70 lines
2.7 KiB
Markdown
70 lines
2.7 KiB
Markdown
**What was implemented**
|
||
|
||
- Switched the embedding provider from `OpenAIEmbeddings` to `OllamaEmbeddings` (langchain‑community).
|
||
- 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 local‑host 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 hard‑coding 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` – local‑host 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 hard‑coded 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. |