Files
agent-s-rag-pamyatyu/SOLUTION.md
T
2026-07-01 13:53:42 +03:00

2.6 KiB
Raw Blame History

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 langchainqdrant” 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

# 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:6333 and an Ollama model named llama3 available locally.
  • No error handling for connection failures is added; in production youd 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.