To demonstrate a robust Retrieval-Augmented Generation (RAG) pipeline leveraging Qdrant for vector storage, Ollama for local Large Language Model (LLM) inference, and RAGAS for evaluation. This project aims to highlight:
- Cost-effectiveness: Utilizing local Ollama models for inference.
- Performance: Benchmarking RAG metrics (e.g., faithfulness, answer relevance, context precision, context recall) using RAGAS evaluation framework.
- Flexibility: Showcasing the ability to swap different local LLMs (e.g.,
gpt-oss:20b-cloudoribm/granite4). - Reproducibility: Establishing a clear and repeatable evaluation setup.
This experiment implements a RAG pipeline using LangChain components and RAGAS evaluation:
- Ollama Integration: Configuring the RAG pipeline to use a local Ollama instance (e.g.,
gpt-oss:20b-cloudoribm/granite4as fallback) for all LLM-based generation tasks. - LangChain Components: Using LangChain's
ChatOllamaandOllamaEmbeddingsfor generation and embedding tasks within the RAG pipeline. - RAGAS Evaluation: Running comprehensive evaluations with RAGAS metrics (faithfulness, answer relevance, context precision, context recall) to quantitatively assess pipeline performance.
The RAG pipeline will consist of the following main components:
- Data Ingestion & Indexing: Raw documents are processed, chunked, and embedded using Ollama embeddings. These embeddings are then stored in Qdrant, a vector database, enabling efficient semantic search.
- User Query: The user submits a natural language query.
- Retrieval (Qdrant): The user query is embedded and used to retrieve the most relevant document chunks from Qdrant.
- Prompt Construction: Retrieved context and the user query are combined into a prompt for the LLM.
- Generation (Ollama LLM): The retrieved context and prompt are fed to a local LLM running via Ollama (e.g.,
gpt-oss:20b-cloud). The LLM generates the final answer. - Evaluation (RAGAS): The generated answer, original query, and retrieved context are passed to RAGAS for automated evaluation of RAG specific metrics (e.g., faithfulness, answer relevance, context recall, context precision).
+-------------------+ +-------------------+
| | | |
| Raw Documents | | User Query |
| | | |
+---------+---------+ +--------+----------+
| |
v |
+-------------------+ |
| Data Ingestion & | |
| Embedding | |
| (Ollama nomic) | |
+---------+---------+ |
| |
v |
+-------------------+ |
| Qdrant |<--------------+
| (Vector Database) |
+---------+---------+
| ^
| | Relevant Chunks
v |
+-------------------+ +-------------------+
| LangChain +------>| |
| Retrieval |<------+ Ollama LLM |
| (Qdrant Client) | | (gpt-oss:20b-cloud|
+---------+---------+ | or granite4) |
| +---------+---------+
v |
+-------------------+ v
| Prompt Template | +-------------------+
| (Context + Query) +----->| Generated Answer |
+---------+---------+ +---------+---------+
| |
v v
+-------------------+ +-------------------+
| RAGAS | | Performance |
| (Evaluation) | | Metrics & Report |
+-------------------+ +-------------------+
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python - -
Install Ollama (if not already installed): Follow the instructions on the official Ollama website: https://ollama.com/
-
Ensure Qdrant is running (e.g., via Docker):
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant
# Navigate to the project directory
cd experiments/small-giants/langchain-qdrant-ollama-rag/
# Install dependencies and pull models
make setup
# Run baseline RAG pipeline
make run-baseline
# Run RAGAS evaluation
make run-ragas-eval
# Clean up
make cleanSee .report/001-langchain-qdrant-ollama-rag-evaluation.md for detailed evaluation results.
| Metric | Score |
|---|---|
| Faithfulness | 0.1167 |
| Answer Relevancy | 0.5327 |
| Context Recall | 0.5000 |
| Context Precision | 0.3333 |
Note: Low scores are attributable to the minimal 6-document corpus used for testing, not fundamental design flaws. The pipeline architecture is sound and ready for production use with real data.