test RAG with local Ollama models
initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
# Local RAG Setup
|
||||
|
||||
Minimal RAG implementation with LangChain, Ollama, and FAISS.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Only 5 packages:
|
||||
- `langchain` - Core framework
|
||||
- `langchain-ollama` - Ollama integration
|
||||
- `faiss-cpu` - Vector search
|
||||
- `sentence-transformers` - Embeddings
|
||||
- `pypdf` - PDF loading
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Create conda environment
|
||||
conda create -n local_rag python=3.10 -y
|
||||
conda activate local_rag
|
||||
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Setup Ollama
|
||||
|
||||
```bash
|
||||
# Make sure Ollama is running
|
||||
ollama serve
|
||||
|
||||
# Pull a model (in another terminal)
|
||||
ollama pull llama2
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Edit `local_rag.py` and uncomment the example code:
|
||||
|
||||
```python
|
||||
# Add documents
|
||||
rag.add_documents([
|
||||
"path/to/document1.pdf",
|
||||
"path/to/document2.txt"
|
||||
])
|
||||
|
||||
# Query
|
||||
question = "What is this document about?"
|
||||
answer = rag.query(question)
|
||||
print(f"Answer: {answer}")
|
||||
```
|
||||
|
||||
Run:
|
||||
```bash
|
||||
python local_rag.py
|
||||
```
|
||||
|
||||
## How it works
|
||||
|
||||
1. **Load documents** - PDFs or text files
|
||||
2. **Split into chunks** - 1000 chars with 200 overlap
|
||||
3. **Create embeddings** - Using sentence-transformers
|
||||
4. **Store in FAISS** - Fast similarity search
|
||||
5. **Query** - Retrieve relevant chunks and generate answer with Ollama
|
||||
|
||||
That's it! Simple and minimal.
|
||||
Reference in New Issue
Block a user