A production-style Retrieval-Augmented Generation (RAG) system built around AI security documentation using FastAPI, Qdrant, Redis Queue (RQ), and LangSmith for tracing and evaluation.
The assistant answers questions grounded strictly in trusted AI security documents, supports asynchronous request processing, and includes an automated evaluation pipeline with multiple RAG-specific metrics.
- Retrieval-Augmented Generation (RAG)
- AI Security knowledge base
- PDF ingestion and indexing
- Semantic search using Qdrant
- FastAPI REST API
- Asynchronous processing with Redis Queue (RQ)
- LangSmith tracing
- LangSmith benchmark evaluation
- Grounded responses with page citations
- Modular project architecture
The assistant currently indexes the following documents located in:
app/data/
- NIST AI Risk Management Framework (AI RMF)
- SAFE-AI Full Report
During ingestion, these PDFs are:
- Loaded
- Split into semantic chunks
- Embedded
- Indexed into Qdrant
Every answer generated by the assistant is based solely on the retrieved document context.
| Path | Purpose |
|---|---|
app/data/ |
Stores the PDF knowledge base used by the RAG pipeline. |
app/rag/ |
Core RAG application containing the API server, worker, clients, and pipeline logic. |
app/rag/ingestion/ |
Loads PDFs, performs chunking, generates embeddings, and indexes them into Qdrant. Run this whenever new documents are added. |
app/rag/queues/ |
Contains the RQ worker responsible for retrieval, prompt construction, LLM invocation, and answer generation. |
app/rag/clients/ |
Client configurations such as the Redis Queue connection. |
app/rag/server.py |
Defines the FastAPI application and REST endpoints. |
app/rag/main.py |
Entry point for starting the FastAPI server. |
app/evaluation/ |
Contains the benchmark dataset, evaluation script, and custom LangSmith evaluators. |
app/reports/ |
Stores evaluation reports and other generated artifacts. |
docker-compose.yml |
Starts the required infrastructure services (Qdrant and Redis). |
qdrant_storage/ |
Persistent storage for the local Qdrant database. |
- Python
- FastAPI
- LangChain
- LangSmith
- Qdrant
- Redis
- Redis Queue (RQ)
- Docker
- Pandas
- OpenAI Compatible APIs
git clone <repository-url>
cd rag_observalibilitypython3 -m venv venvActivate it.
Linux/macOS
source venv/bin/activateWindows
venv\Scripts\activatecd app
pip install -r requirements.txtCreate a .env file inside the app/ directory.
Example:
LANGSMITH_API_KEY=
GROQ_API_KEY=From the project root:
docker compose up -dThis starts:
- Qdrant (Vector Database)
- Redis (Message Queue)
Open a terminal.
Navigate to:
rag_observalibility/app
Run:
python -m rag.ingestion.indexThis step:
- Loads every PDF inside
app/data - Chunks the documents
- Generates embeddings
- Stores them inside Qdrant
This only needs to be executed again when the document collection changes.
Open a new terminal.
Navigate to:
rag_observalibility/app
Run:
rq workerThe worker:
- Retrieves relevant document chunks
- Constructs prompts
- Calls the LLM
- Generates the final grounded response
You may start multiple workers depending on workload.
Open another terminal.
Navigate to:
rag_observalibility/app
Run:
python -m rag.mainThe API will start on:
http://localhost:8000
Interactive API Documentation:
http://localhost:8000/docs
Using the Swagger UI available at:
http://localhost:8000/docs
Submit a request to:
POST /chat
The endpoint returns a Job ID.
Use:
GET /job-status
with the Job ID to retrieve the generated answer once processing completes.
The evaluation module benchmarks the RAG system using a custom dataset and multiple LLM-as-a-Judge metrics.
- Correctness
- Answer Relevance
- Retrieval Relevance
- Faithfulness (Groundedness)
Ensure your .env file contains valid API keys, especially:
LANGSMITH_API_KEY=
GROQ_API_KEY=From the project root:
python -m app.evaluation.evaluateThe evaluation script will:
- Load the benchmark dataset
- Execute the RAG pipeline
- Run all evaluation metrics
- Upload the experiment to LangSmith
The latest evaluation results are available here:
User Question
│
▼
FastAPI API
│
▼
Redis Queue (RQ)
│
▼
RQ Worker
│
▼
Semantic Retrieval (Qdrant)
│
▼
Prompt Construction
│
▼
LLM
│
▼
Grounded Response
│
▼
User
- Hybrid Retrieval (Dense + BM25)
- Cross-Encoder Reranking
- Metadata Filtering
- Streaming Responses
- Multi-turn Conversation Support
- Conversation Memory
- Hybrid Search
- Larger Benchmark Dataset
- CI/CD Integration
- Containerized Deployment
This project is intended for educational, research, and demonstration purposes.