This project implements a Retrieval-Augmented Generation (RAG) pipeline for answering technical questions over the RapidFireAI documentation. The pipeline includes data ingestion, vector search, cross-encoder and LLM-based reranking, prompt formatting with deduplication, and LLM-powered generation via Triton AI. It also features a comprehensive suite of evaluation scripts to automatically score retrieval precision/recall and judge generation quality.
For a detailed description of the problem statement and motivation, and a deep dive into the technical details, check out the technical report under report/.
Make sure your virtual environment is active and dependencies are installed:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtThe pipeline primarily uses the Triton AI API for generation. You have two options for providing your configuration (TRITON_API_KEY, TRITON_API_BASE_URL, and optionally OPENAI_API_KEY or GOOGLE_API_KEY if using specific embeddings):
Option A: Using a .env file (Default)
Create a .env file in the root directory:
TRITON_API_KEY="..."
TRITON_API_BASE_URL="..."
# Optional: Only if using OpenAI or Gemini embeddings
# OPENAI_API_KEY="..."
# GOOGLE_API_KEY="..."Option B: Using a custom API key file
If you prefer not to use .env, you can create a plain text file (e.g., keys.txt) with the same format as above. When running the pipeline, pass this file using the --apikey-txt flag:
python main.py --output results.json --apikey-txt keys.txtExperiment variations (chunk size, embeddings, search strategy, models, prompts) are managed via JSON configuration files stored in config/experiments/.
To create a new experiment, duplicate the default config or an existing one and modify it:
cp config/experiments/default_experiment_config.json config/experiments/config-my-experiment.jsonNote: This filename (without the .json extension) will be used as the --config-id parameter in downstream scripts.
If you are using a new embedding model, new chunk sizes, or setting up the database for the first time, you must ingest your raw text files into a vector database (Pinecone or FAISS).
Using ingest.py directly:
# Basic ingestion to Pinecone (default)
python src/rag/ingest.py data/raw/ingestion --index-name my-index
# Ingest using a specific experiment config
python src/rag/ingest.py data/raw/ingestion --config-id config-15
# Ingest into local FAISS index
python src/rag/ingest.py data/raw/ingestion --vector-store faiss --index-name local-indexAutomatic Ingestion:
The main.py pipeline will automatically trigger ingestion if you are using FAISS and the specified index is not found in data/vectorstores/faiss/. You must provide the --corpus-dir flag for this to work.
The primary entry point for the entire pipeline is main.py. This script can handle everything from ingestion (if using FAISS and index is missing) to answer generation and optional evaluation. It handles configuration loading, environment initialization, context retrieval, reranking, and generation.
# Basic usage with default config and FAISS
python main.py --output results.json
# Specific config and vector index
python main.py --config-id config-15 --index-name my_index --output results.json
# Using Pinecone and custom input file
python main.py --input custom_questions.json --output results.json --vector-store pinecone
# Running with API key file and model override
python main.py --output results.json --apikey-txt keys.txt --generation-model gpt-4o
# Enable debug mode and automatic evaluation
python main.py --output results.json --debug --eval
# Custom corpus directory for FAISS index creation
python main.py --output results.json --corpus-dir data/my_docs/ --index-name new_index| Flag | Description | Default |
|---|---|---|
--input |
Path to input JSON file containing questions. | data/raw/qa/validation-set-golden-qa-pairs.json |
--output |
(Required) Path to output JSON file for answers. | N/A |
--config-id |
Config ID (filename in config/experiments/ without .json). |
config-21 |
--index-name |
Name of the vector index. | full-only-text-config-12-no-rst-splitter |
--vector-store |
Vector store type (pinecone or faiss). |
faiss |
--corpus-dir |
Path to dataset for ingestion (used if FAISS index needs creation). | data/raw/ingestion/full-only-text |
--eval |
Invoke the evaluation script under src/retrieval after generation. |
False |
--debug |
Print detailed logs and save traces to data/interim/. |
False |
--apikey-txt |
Path to a file containing API keys (overrides .env). | None |
--generation-model |
Override the LLM model specified in the experiment config. | None |
- End-to-End Execution: Can trigger ingestion, run retrieval, reranking, and generation in one command.
- Model Overrides: Use
--generation-modelto swap the generation LLM without editing the config file. - Triton AI Integration: Generation is powered by the Triton AI API, allowing for flexible model selection (e.g.,
gpt-4o-mini,gpt-4o). - Context Deduplication: Automatically removes overlapping content between retrieved chunks to optimize the prompt window.
- Tracing: In
--debugmode, detailed execution traces are saved todata/interim/for every question.
After generating the answers, you can run additional evaluation scripts to analyze performance.
# Basic usage with default k=5
python src/eval/evaluate_retrieval.py --output results.json --validation VAL.json
# Evaluation with k=10
python src/eval/evaluate_retrieval.py --output results.json --validation VAL.json --k 10Uses a judge model (via Triton) to grade answers based on completeness, faithfulness, and correctness.
# Basic usage with TritonAI key and specific report name
python src/eval/run_judge.py --output results.json --validation val.json --report-name my_eval.json
# Override model and base URL
python src/eval/run_judge.py --output results.json --validation val.json --report-name my_eval.json \
--model gpt-4o-mini --base-url https://api.openai.com/v1
# Increase max retry attempts for API calls
python src/eval/run_judge.py --output results.json --validation val.json --report-name my_eval.json --max-attempts 5# Use default 2000 word threshold
python src/eval/check_token_usage.py --input results.json --output usage_report.json
# Use custom 1500 word threshold
python src/eval/check_token_usage.py --input results.json --output usage_report.json --threshold 1500Compile all metrics into a readable report for debugging and analysis.
# Minimal usage with LLM judge results
python src/scripts/generate_eval_report.py --eval-num 1 --config-id config-1 --qa-set-id val-set --llm-as-judge-json judge.json --output-md report.md
# Complete analysis with retrieval and token usage
python src/scripts/generate_eval_report.py --eval-num 1 --config-id config-1 --qa-set-id val-set \
--llm-as-judge-json judge.json --retrieval-json retrieval.json \
--question-types-json types.json --token-usage-json tokens.json \
--output-md report.mdThe experiment.py script allows you to run a grid search across multiple configurations to find the best parameters.
# Run grid search with default test config
python src/rag/experiment.py --output results_summary.json
# Run grid search with specific config and corpus
python src/rag/experiment.py --config-file config/experiments/grid-search-1.json \
--dataset data/raw/qa/golden-val.json --corpus-dir data/my_docs/ \
--output grid_results.jsonTo measure progress across different experiments, use the comparison script.
python src/scripts/compare_eval_reports.py \
--report1 data/processed/eval/report-v1.md \
--report2 data/processed/eval/report-v2.md \
--output-md data/processed/eval/comparison_v1_v2.md