63 lines
2.6 KiB
Markdown
63 lines
2.6 KiB
Markdown
**What was implemented**
|
||
- Switched the vector store from FAISS to Qdrant using the `langchain_qdrant` wrapper.
|
||
- Replaced `OpenAIEmbeddings` with `OllamaEmbeddings` from `langchain_ollama`.
|
||
- Updated the agent to use Ollama for both embeddings and the LLM.
|
||
- Added `langchain-qdrant` and `langchain-ollama` to `requirements.txt`.
|
||
- Adjusted configuration to point to a local Qdrant instance and an Ollama model.
|
||
|
||
**Why the main parts satisfy the requirements**
|
||
- `src/vector_store.py` now imports `langchain_qdrant.Qdrant` and passes the Ollama embeddings, fulfilling the “use langchain‑qdrant” constraint.
|
||
- `src/agent.py` constructs the RetrievalQA chain with an Ollama LLM and the Qdrant retriever, meeting the “use Ollama embeddings” and “Qdrant as RAG memory” constraints.
|
||
- `config.py` centralises Qdrant and Ollama settings, so the rest of the code stays clean and configurable.
|
||
- `requirements.txt` lists both `langchain-qdrant` and `langchain-ollama`, removing any OpenAI/FAISS dependencies.
|
||
|
||
**Key code excerpts**
|
||
|
||
`config.py` – Qdrant & Ollama settings
|
||
```python
|
||
# Qdrant settings
|
||
QDRANT_HOST = "localhost"
|
||
QDRANT_PORT = 6333
|
||
QDRANT_API_KEY = None
|
||
QDRANT_COLLECTION = "rag_collection"
|
||
|
||
# Ollama settings
|
||
OLLAMA_MODEL = "llama3"
|
||
```
|
||
|
||
`src/vector_store.py` – Qdrant wrapper
|
||
```python
|
||
class QdrantVectorStore:
|
||
def __init__(self, embeddings, collection_name: str = None):
|
||
self.qdrant = Qdrant(
|
||
url=f"http://{config.QDRANT_HOST}:{config.QDRANT_PORT}",
|
||
api_key=config.QDRANT_API_KEY,
|
||
collection_name=self.collection_name,
|
||
embeddings=embeddings,
|
||
)
|
||
```
|
||
|
||
`src/agent.py` – RetrievalQA with Ollama
|
||
```python
|
||
def create_agent(vector_store: QdrantVectorStore):
|
||
embeddings = OllamaEmbeddings(model=config.OLLAMA_MODEL)
|
||
llm = Ollama(model=config.OLLAMA_MODEL)
|
||
qa_chain = RetrievalQA.from_chain_type(
|
||
llm=llm,
|
||
chain_type="stuff",
|
||
retriever=vector_store.get_retriever(),
|
||
)
|
||
return qa_chain
|
||
```
|
||
|
||
`src/main.py` – initialization and sample run
|
||
```python
|
||
vector_store = QdrantVectorStore(embeddings)
|
||
agent = create_agent(vector_store)
|
||
result = agent.run("What is LangChain?")
|
||
```
|
||
|
||
**Honest limitations**
|
||
- The solution assumes a running Qdrant instance on `localhost:6333` and an Ollama model named `llama3` available locally.
|
||
- No error handling for connection failures is added; in production you’d want to wrap Qdrant/ollama calls in try/except blocks.
|
||
- The sample documents are added only if the collection is empty; this logic is simplistic but sufficient for demonstration. |