Skip to content
simran-malikPublic

About

A RAG-powered pipeline for technical Q&A on the RapidFireAI Platform

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

91 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG-Powered Pipeline for Technical Q&A on the RapidFire AI Platform

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/.


1. Setup & Configuration

Prerequisites

Make sure your virtual environment is active and dependencies are installed:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

API Key Configuration

The 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.txt

Creating a New Configuration

Experiment 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.json

Note: This filename (without the .json extension) will be used as the --config-id parameter in downstream scripts.


2. Data Ingestion Pipeline

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-index

Automatic 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.


3. Running the RAG Pipeline (End-to-End)

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.

Usage Examples

# 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

Full Options

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

Key Features

  • End-to-End Execution: Can trigger ingestion, run retrieval, reranking, and generation in one command.
  • Model Overrides: Use --generation-model to 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 --debug mode, detailed execution traces are saved to data/interim/ for every question.

4. Running Evaluations

After generating the answers, you can run additional evaluation scripts to analyze performance.

4a. Retrieval Evaluation (Precision, Recall, F1)

# 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 10

4b. LLM-as-Judge Evaluation

Uses 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

4c. Token Usage Evaluation

# 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 1500

5. Generating the Evaluation Markdown Report

Compile all metrics into a readable report for debugging and analysis.

Usage Examples

# 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.md

6. Grid Search (Hyperparameter Optimization)

The experiment.py script allows you to run a grid search across multiple configurations to find the best parameters.

Usage Examples

# 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.json

7. Comparing Evaluation Reports

To measure progress across different experiments, use the comparison script.

Usage Example

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

About

A RAG-powered pipeline for technical Q&A on the RapidFireAI Platform

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages