Question answering over the HotpotQA dataset using BM25, dense retrieval, cross-encoder reranking, and an LLM backend (GPT-4.1-mini or local Qwen3-8B via vLLM).
The easiest way to run the API. No Python setup required.
docker pull sabharwalrishabh/rag-api:latest# For OpenAI backend (default)
OPENAI_API_KEY=your_key_here
# For local vLLM backend (optional)
# OPENAI_BASE_URL=http://host.docker.internal:8002/v1
# MODEL_NAME=Qwen/Qwen3-8B-AWQdocker compose upThe API will be available at http://localhost:8000.
First run note: On first startup the container downloads the retrieval models (~630MB) and encodes the entire corpus into embeddings. This takes 20–40 minutes. Both are cached in Docker volumes so every restart after that is instant.
GET /health
| Endpoint | Method | Description |
|---|---|---|
/retrieve/hybrid |
POST | BM25 + dense retrieval fused with RRF |
/retrieve/rerank |
POST | Dense retrieval re-ranked by a cross-encoder |
Request body:
{ "question": "Who directed Inception?", "k": 5 }| Endpoint | Method | Description |
|---|---|---|
/qa/no_rag |
POST | LLM answers directly from parametric knowledge |
/qa/rag |
POST | Single-shot RAG — retrieves top-k facts then answers |
/qa/agentic |
POST | Agentic RAG — LLM iteratively calls a search tool to gather evidence |
Request body:
{ "question": "Who directed Inception?", "k": 5 }Interactive API docs are available at http://localhost:8000/docs.
Set OPENAI_API_KEY in .env. The API uses gpt-4.1-mini-2025-04-14 by default.
Requires a machine with an NVIDIA GPU. Run the vLLM server separately:
vllm serve Qwen/Qwen3-8B-AWQ --port 8002 --max-model-len 2048 \
--gpu-memory-utilization 0.5 --enable-auto-tool-choice --tool-call-parser hermesThen set these in .env:
OPENAI_BASE_URL=http://host.docker.internal:8002/v1
MODEL_NAME=Qwen/Qwen3-8B-AWQRequires Python 3.11 and a CUDA 12.8 driver.
python3.11 -m venv venv
source venv/bin/activatepip install torch==2.7.0+cu126 \
--index-url https://download.pytorch.org/whl/cu126pip install https://github.com/vllm-project/vllm/releases/download/v0.9.1/vllm-0.9.1%2Bcu126-cp38-abi3-manylinux1_x86_64.whl \
--extra-index-url https://download.pytorch.org/whl/cu126Patch vLLM for transformers 4.x compatibility — open venv/lib/python3.11/site-packages/vllm/transformers_utils/configs/ovis.py and change:
# Before
AutoConfig.register("aimv2", AIMv2Config)
# After
AutoConfig.register("aimv2", AIMv2Config, exist_ok=True)pip install -r requirements.txtOPENAI_API_KEY=your_key_herepython part3.py --agentic_rag_baseline| Flag | Description |
|---|---|
--no_rag_baseline |
LLM answers directly from parametric knowledge |
--rag_baseline |
Retrieves top-5 facts via dense retrieval + reranking, feeds to LLM |
--agentic_rag_baseline |
LLM iteratively calls a find_facts tool to gather evidence before answering |
--model |
gpt-4.1-mini-2025-04-14 (default) or qwen3-8b (requires local vLLM server on port 8002) |
--use_judge |
Uses GPT-4.1 to judge semantic correctness of wrong answers. Requires OPENAI_API_KEY |
Multiple flags can be combined:
python part3.py --rag_baseline --agentic_rag_baseline --model qwen3-8bTo also run the API server locally:
uvicorn api:app --host 0.0.0.0 --port 8000 --reload