A Retrieval-Augmented Generation (RAG) system implementing query expansion, retrieval enhancement, context compression, and comprehensive LLM-as-a-judge evaluations.
The pipeline utilizes Query Decomposition, Hypothetical Document Embeddings (HyDE), Context Compression (Sentence Filtering), and Multi-Metric Evaluation.
graph TD
UserQuery([User Question]) --> Decompose[Query Decomposition <br/><i>qwen2.5-coder:3b</i>]
Decompose -->|Sub-queries| HyDE[HyDE Generator <br/><i>llama3.2</i>]
HyDE -->|Hypothetical Answers| Embedder[Embedder <br/><i>all-MiniLM-L6-v2</i>]
Embedder -->|Dense Vectors| VectorDB[(ChromaDB)]
VectorDB -->|Retrieved Chunks| Compress[Context Compression <br/><i>qwen2.5-coder:3b</i>]
Compress -->|Filtered Context| LLM[Response Synthesis <br/><i>llama3.2</i>]
LLM --> FinalAnswer([Synthesized Answer])
%% Evaluation path
FinalAnswer --> Eval[Evaluation Engine <br/><i>scorers.py</i>]
Eval -->|Metrics| Faithfulness[Faithfulness Score]
Eval -->|Metrics| Relevance[Answer Relevance]
Eval -->|Metrics| Precision[Context Precision]
Eval -->|Metrics| GroundTruth[Ground Truth Sim.]
- Query Decomposition: Deconstructs complex queries into 2-4 granular sub-queries to ensure complete coverage.
- Hypothetical Document Embeddings (HyDE): Generates hypothetical, factual documents for each sub-query to bridge the vocabulary gap during semantic search.
- Context Compression: Compresses retrieved passages sentence-by-sentence to extract only directly relevant info, keeping context windows clean.
- Robust Evaluation Suite: LLM-as-a-judge scorers for:
- Faithfulness: Factuality of the generated answer against the context.
- Answer Relevance: Embedding-based similarity between user query and answer.
- Context Precision: The proportion of retrieved chunks that survive compression.
- Ground Truth Similarity: Cosine similarity between the answer and gold-standard references.
- CLI Interface: Rich visual output, tables, and progress bars.
This repository uses uv for fast Python package management.
Ensure you have uv installed, then run:
uv syncThe toolkit relies on local LLMs run via Ollama. Download and run the following models:
# Pull synthesis and judge model
ollama pull llama3.2
# Pull decomposition and compression model
ollama pull qwen2.5-coder:3bThe application is controlled via a simple command-line interface in main.py.
Fetch Wikipedia articles on Machine Learning and database topics:
uv run python fetch_wiki.pyThis stores Wikipedia documents in the docs/ directory.
Index the Markdown documents into ChromaDB:
uv run python main.py ingest docsAsk questions to trigger the advanced decomposition + HyDE + compression pipeline:
uv run python main.py ask "How do vector databases store and retrieve data?"Add the --debug (or -d) flag to inspect the sub-queries and compressed context chunks in real-time.
View database stats and configuration:
uv run python main.py statusTo wipe your indexed ChromaDB collection:
uv run python main.py clearThe evaluation suite tests the toolkit against a set of predefined benchmark QA pairs located in benchmark/questions.json.
To run the evaluations and print a styled results table:
uv run python main.py eval --show-answersResults are saved automatically to benchmark/results/ as a timestamped JSON file (e.g., eval_20260612_154707.json).