RAGOps is an end-to-end Retrieval-Augmented Generation system over the BEIR SciFact corpus.
It is built to be production-like: hybrid retrieval, reranking, citation-grounded generation, safe fallback behavior, offline evaluation, and per-query observability.
- Ingests SciFact corpus, queries, and qrels directly from Hugging Face
- Hybrid retrieval: BM25 + dense embeddings
- Reranking with cross-encoder (with fallback reranker if needed)
- Multi-category routing:
rag,sql,graph,auto - Citation-grounded answering with confidence-aware no-answer behavior
- LLM provider abstraction:
huggingface,openai,ollama,bytez - Evaluation harness for:
- Retrieval quality:
Recall@k,MRR@k,nDCG@k - Generation quality:
Groundedness,FactualAccuracy(citation-precision proxy), answer/no-answer rates - System efficiency: retrieval/rerank/generation/total latency
- Retrieval quality:
- Trace logging for every evaluated or served query (retrieval hits, reranker scores, latency, answer metadata)
- FastAPI service with
/ask,/health, and/metrics
- Data ingestion
- Download SciFact corpus/queries and qrels
- Normalize to local artifacts
- Indexing
- Build BM25 index
- Build dense embedding index
- Retrieval
- Retrieve BM25 and dense candidates
- Fuse with weighted reciprocal rank fusion (RRF)
- Reranking
- Cross-encoder rerank of fused candidates
- Generation
- LLM grounded synthesis with citation checks and overlap guardrails
- Safe fallback to no-answer when evidence is insufficient
- Evaluation + tracing
- Batch query execution over qrels
- Metrics computation and JSON report output
- Per-query trace file for debugging/regression analysis
ragops/
cli.py # Typer CLI
pipeline.py # Retrieval + rerank + generation orchestration
generation.py # Extractive + LLM grounded generators
llm_providers.py # Provider adapters (HF, OpenAI, Ollama, Bytez)
model_eval.py # Model-level eval (retrieval/generation/latency)
server.py # FastAPI app
sql_engine.py # SQL category
graph_engine.py # Graph category
experiments/
scifact_experiments.yaml
tests/
- Python
>= 3.11 - Internet connection for first-time dataset/model downloads
- Optional provider credentials for hosted LLMs
python -m pip install -e .- Prepare data:
python -m ragops.cli prepare-data- Build indexes:
python -m ragops.cli build-index- Build SQL + graph artifacts:
python -m ragops.cli build-sql-db
python -m ragops.cli build-graph- Ask a question:
python -m ragops.cli ask "Does aspirin reduce heart attack risk?"- Auto route:
python -m ragops.cli ask "How many documents are in the corpus?"- Force category:
python -m ragops.cli ask "How many documents are in the corpus?" --category sql
python -m ragops.cli ask "Show most connected docs in the graph" --category graph
python -m ragops.cli ask "Does aspirin reduce heart attack risk?" --category ragExamples:
python -m ragops.cli ask "Does aspirin reduce heart attack risk?" --enable-llm --llm-provider huggingface
python -m ragops.cli ask "Does aspirin reduce heart attack risk?" --enable-llm --llm-provider openai --llm-model gpt-4.1-mini
python -m ragops.cli ask "Does aspirin reduce heart attack risk?" --enable-llm --llm-provider ollama --llm-model llama3.1
python -m ragops.cli ask "Does aspirin reduce heart attack risk?" --enable-llm --llm-provider bytez --llm-model openai/gpt-4.1-miniEnvironment variables:
OPENAI_API_KEYfor OpenAI providerBYTEZ_API_KEYfor Bytez provider
Notes:
- If your hosted model quota is exhausted, generation can fail or fallback behavior may be triggered.
- The CLI prints runtime generator metadata in
evaluate-modelso fallback usage is visible.
python -m ragops.cli evaluate --mode hybrid_rerankSupported retrieval modes:
bm25densehybridhybrid_rerank
python -m ragops.cli evaluate-model --sample-size 50 --llm-provider bytez --llm-model openai/gpt-4.1-miniCurrent tuned defaults in this repository:
fused_top_k=30no_answer_threshold=0.35llm_min_grounding_overlap=0.15
You can override directly:
python -m ragops.cli evaluate-model \
--sample-size 50 \
--fused-top-k 30 \
--answer-top-k 5 \
--no-answer-threshold 0.35 \
--llm-min-grounding-overlap 0.15Output:
outputs/eval/*.json: aggregated evaluation reportsoutputs/traces/*.jsonl: per-query traces
Run multi-config experiments from YAML:
python -m ragops.cli run-experiments --config-file experiments/scifact_experiments.yamlUseful fields in experiment configs:
retrieval: retrieval hyperparametersmodel: model/reranker settingsllm: provider/model settingsanswer_eval: enable/disable generation scoringanswer_eval_sample_size: subsample for faster iteration
Start server:
python -m ragops.cli serve --host 0.0.0.0 --port 8000Endpoints:
GET /healthGET /metricsGET /metrics/jsonPOST /ask
Example:
curl -X POST "http://localhost:8000/ask" \
-H "Content-Type: application/json" \
-d "{\"query\":\"Does aspirin reduce heart attack risk?\",\"category\":\"rag\"}"python -m pytest -q- Do not hardcode API keys in source files.
- Use environment variables for credentials.
- Large artifacts and outputs are excluded via
.gitignore.
python -m ragops.cli prepare-data
python -m ragops.cli build-index
python -m ragops.cli build-sql-db
python -m ragops.cli build-graph
python -m ragops.cli evaluate --mode hybrid_rerank
python -m ragops.cli evaluate-model --sample-size 50 --llm-provider bytez --llm-model openai/gpt-4.1-mini
python -m ragops.cli ask "Can vitamin D reduce respiratory infections?"
python -m ragops.cli serve