A Production-Grade Retrieval-Augmented Generation (RAG) Framework for Scalable, Trustworthy, and Context-Aware LLM Systems
RAG-Engine is a modular, extensible, and research-grade Retrieval-Augmented Generation (RAG) framework designed to support the development of robust, scalable, and trustworthy large language model (LLM) applications.
It provides a complete engineering and research pipeline covering data ingestion, indexing, retrieval, reasoning, generation, evaluation, and deployment, enabling developers and researchers to build production-level AI systems such as:
- Knowledge-grounded AI assistants
- Enterprise search copilots
- Research agents and autonomous analysts
- LLM-powered data intelligence platforms
- Trustworthy and explainable AI systems
This framework emphasizes engineering rigor, modularity, evaluation, and reliability, making it suitable for both academic research and real-world deployment.
RAG-Engine is designed with the following principles:
- Reliability — grounded generation with traceable sources
- Modularity — pluggable LLMs, retrievers, and pipelines
- Scalability — supports large-scale document and embedding pipelines
- Trustworthiness — safety guardrails and evaluation metrics
- Production-readiness — API serving, logging, Docker deployment
- Research extensibility — experimentation with advanced RAG methods
RAG-Engine follows a layered and extensible architecture:
User Query
↓
API Layer (FastAPI / CLI)
↓
RAG Orchestration Pipeline
├── Query Understanding
├── Retrieval Layer
│ ├─ Embedding generation
│ ├─ Vector search
│ ├─ Hybrid retrieval (optional)
│ └─ Reranking
│
├── Context Builder
│ ├─ Chunk selection
│ ├─ Prompt construction
│ └─ Citation formatting
│
└── LLM Generation Layer
├─ Response generation
├─ Safety filtering
└─ Structured output
- Document ingestion and preprocessing
- Intelligent chunking and metadata management
- Embedding generation and indexing
- Retrieval and reranking
- Context-aware response generation
- Source attribution and traceability
Supports integration with:
- OpenAI models (GPT series)
- Vertex AI / Gemini
- Local models (Llama, Mistral, etc.)
- Custom enterprise LLM endpoints
- Vector search (FAISS, Chroma, pgvector)
- Hybrid retrieval (vector + BM25)
- Metadata filtering
- Semantic reranking
- Multi-query expansion
- Prompt injection mitigation
- Output validation
- PII detection (optional)
- Policy-based filtering
- Safe prompt templates
Built-in evaluation framework:
- Retrieval precision & recall
- Faithfulness metrics
- Context relevance
- Hallucination detection
- Automated benchmarking pipeline
- FastAPI REST service
- Streaming responses
- Docker deployment
- Configurable environments
- Logging and monitoring support
rag-engine/
├─ README.md
├─ pyproject.toml
├─ .env.example
├─ .gitignore
├─ Makefile
├─ docker/
│ ├─ Dockerfile
│ └─ docker-compose.yml
├─ scripts/
│ ├─ ingest.py
│ ├─ build_index.py
│ ├─ eval.py
│ └─ export_artifacts.py
├─ configs/
│ ├─ app.yaml
│ ├─ rag.yaml
│ └─ logging.yaml
├─ data/
│ ├─ raw/ # input docs (optional local)
│ ├─ processed/ # cleaned/chunked docs
│ └─ samples/
├─ artifacts/
│ ├─ indexes/ # vector index persistence (FAISS/Chroma/etc.)
│ ├─ docstore/ # metadata store snapshots
│ └─ eval/ # evaluation outputs
├─ src/
│ └─ rag_engine/
│ ├─ __init__.py
│ ├─ main.py # entrypoint (optional CLI)
│ ├─ settings.py # pydantic settings (env + yaml)
│ ├─ logging.py
│ ├─ api/
│ │ ├─ app.py # FastAPI app
│ │ ├─ routes/
│ │ │ ├─ health.py
│ │ │ └─ chat.py # /chat, /query, /stream
│ │ └─ schemas.py # request/response models
│ ├─ rag/
│ │ ├─ pipeline.py # RAG orchestration
│ │ ├─ prompts.py # prompt templates
│ │ ├─ rerank.py # optional reranker integration
│ │ └─ citations.py # source attribution formatting
│ ├─ ingestion/
│ │ ├─ loader.py # pdf/html/txt loaders
│ │ ├─ cleaner.py # normalize/clean text
│ │ ├─ chunker.py # chunk strategy (recursive, semantic)
│ │ └─ metadata.py # doc_id, source, timestamps
│ ├─ retrieval/
│ │ ├─ embeddings.py # embedding model wrapper
│ │ ├─ vectorstore.py # FAISS/Chroma adapters
│ │ ├─ hybrid.py # optional BM25 + vector hybrid
│ │ └─ filters.py # metadata filtering
│ ├─ llm/
│ │ ├─ client.py # OpenAI/Vertex/local LLM adapter
│ │ ├─ streaming.py
│ │ └─ guardrails.py # safety, policy, PII filtering
│ ├─ memory/
│ │ ├─ conversation.py
│ │ └─ store.py # redis/sqlite (optional)
│ ├─ evaluation/
│ │ ├─ datasets.py
│ │ ├─ metrics.py # faithfulness, answer relevance, etc.
│ │ └─ runner.py
│ ├─ utils/
│ │ ├─ ids.py
│ │ ├─ time.py
│ │ └─ io.py
│ └─ tests/
│ ├─ unit/
│ ├─ integration/
│ └─ conftest.py
├─ notebooks/
│ ├─ 01_ingestion.ipynb
│ ├─ 02_retrieval_debug.ipynb
│ └─ 03_eval.ipynb
└─ docs/
├─ architecture.md
├─ api.md
└─ prompts.md
Add your documents to:
data/raw/
Run ingestion pipeline:
python scripts/ingest.py
Build vector index:
python scripts/build_index.py
##Run API Server
Start FastAPI server:
uvicorn src.rag_engine.api.app:app --reload --port 8000
API endpoint:
POST /chat
Example request:
{
"query": "Explain retrieval augmented generation",
"top_k": 5
}
from rag_engine.rag.pipeline import RAGPipeline
rag = RAGPipeline()
response = rag.query("What is RAG in LLM?")
print(response.answer)
print(response.sources)
docker build -t rag-engine .Run container
docker run -p 8000:8000 rag-engine
RAG-Engine integrates safety-first design:
- Prompt injection defense
- Output filtering
- Source-grounded generation
- Structured output validation
- Optional trust scoring
- Agentic RAG framework
- Graph-based RAG
- Multimodal RAG (image + text)
- Streaming and real-time memory
- Self-reflective RAG evaluation
- Risk-aware trustworthy RAG
- Autonomous research agents
We welcome contributions from researchers and engineers. Steps:
- Fork repository
- Create feature branch
- Commit changes
- Submit pull request
MIT License
Miraj Rahman AI Researcher | LLM Systems | Trustworthy AI | RAG Architect