2.6 KiB
2.6 KiB
What was implemented
- Switched the vector store from FAISS to Qdrant using the
langchain_qdrantwrapper. - Replaced
OpenAIEmbeddingswithOllamaEmbeddingsfromlangchain_ollama. - Updated the agent to use Ollama for both embeddings and the LLM.
- Added
langchain-qdrantandlangchain-ollamatorequirements.txt. - Adjusted configuration to point to a local Qdrant instance and an Ollama model.
Why the main parts satisfy the requirements
src/vector_store.pynow importslangchain_qdrant.Qdrantand passes the Ollama embeddings, fulfilling the “use langchain‑qdrant” constraint.src/agent.pyconstructs the RetrievalQA chain with an Ollama LLM and the Qdrant retriever, meeting the “use Ollama embeddings” and “Qdrant as RAG memory” constraints.config.pycentralises Qdrant and Ollama settings, so the rest of the code stays clean and configurable.requirements.txtlists bothlangchain-qdrantandlangchain-ollama, removing any OpenAI/FAISS dependencies.
Key code excerpts
config.py – Qdrant & Ollama settings
# 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
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
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
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:6333and an Ollama model namedllama3available 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.