Files
agent-s-rag-pamyatyu/SOLUTION.md
T
2026-07-01 14:05:59 +03:00

70 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**What was implemented**
- Switched the embedding provider from `OpenAIEmbeddings` to `OllamaEmbeddings` (langchaincommunity).
- Replaced the FAISS vector store with a Qdrant store.
- Updated all imports, configuration, and helper functions to use the new stack.
- Added the required dependencies (`langchain-community`, `qdrant-client`) to `requirements.txt`.
- Kept the LLM (`OpenAI`), prompt templates, chain structure, and memory unchanged.
- Provided localhost configuration for both Ollama and Qdrant in `config.py`.
**Why the main parts satisfy the requirements**
- **Embeddings** `embeddings.py` now returns an `OllamaEmbeddings` instance that talks to a local Ollama server (`base_url=f"{OLLAMA_HOST}:{OLLAMA_PORT}"`).
- **Vector store** `vector_store.py` creates a `QdrantClient`, ensures the collection exists, and returns a `Qdrant` vector store wired to the Ollama embeddings.
- **Agent** `agent.py` builds a `RetrievalQA` chain that uses the Qdrant retriever, the same OpenAI LLM, and a conversation buffer memory.
- **Configuration** `config.py` exposes host/port for both services, so the agent can connect to local instances without hardcoding URLs.
- **Dependencies** `requirements.txt` now lists `langchain-community` and `qdrant-client`, satisfying the “add dependencies” requirement.
**Key code excerpts**
`embeddings.py` Ollama embeddings
```python
from langchain_community.embeddings import OllamaEmbeddings
...
return OllamaEmbeddings(
model=OLLAMA_EMBEDDING_MODEL,
base_url=f"{OLLAMA_HOST}:{OLLAMA_PORT}"
)
```
`vector_store.py` Qdrant store
```python
from qdrant_client import QdrantClient
...
return Qdrant(
client=client,
collection_name=QDRANT_COLLECTION_NAME,
embeddings=embeddings
)
```
`agent.py` RetrievalQA chain unchanged except for the retriever
```python
vector_store: Qdrant = get_vector_store()
retriever = vector_store.as_retriever(search_kwargs={"k": 5})
...
chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
memory=memory
)
```
`config.py` localhost settings
```python
OLLAMA_HOST: str = "http://localhost"
OLLAMA_PORT: int = 11434
QDRANT_HOST: str = "http://localhost"
QDRANT_PORT: int = 6333
```
**Honest limitations**
- The solution assumes a running local Ollama server exposing the chosen embedding model (`llama2`) and a Qdrant instance listening on the default ports.
- The vector size is hardcoded to 768; if the chosen Ollama model uses a different dimensionality, the collection creation will need adjustment.
- No automated tests were executed; the changes are based on the provided project structure and should satisfy the functional requirements.