Skip to content

About

RAG Engine, a component of the Vertex AI Platform, facilitates Retrieval-Augmented Generation (RAG). Vertex AI RAG Engine is also a data framework for developing context-augmented large language model (LLM) applications. Context augmentation occurs when you apply an LLM to data.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

RAG-Engine

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.

Core Objectives

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

System Architecture

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

Key Features

1. End-to-End RAG Pipeline

  • Document ingestion and preprocessing
  • Intelligent chunking and metadata management
  • Embedding generation and indexing
  • Retrieval and reranking
  • Context-aware response generation
  • Source attribution and traceability

2. Multi-LLM Support

Supports integration with:

  • OpenAI models (GPT series)
  • Vertex AI / Gemini
  • Local models (Llama, Mistral, etc.)
  • Custom enterprise LLM endpoints

3. Advanced Retrieval Engine

  • Vector search (FAISS, Chroma, pgvector)
  • Hybrid retrieval (vector + BM25)
  • Metadata filtering
  • Semantic reranking
  • Multi-query expansion

4. Safety and Guardrails

  • Prompt injection mitigation
  • Output validation
  • PII detection (optional)
  • Policy-based filtering
  • Safe prompt templates

5. Evaluation and Benchmarking

Built-in evaluation framework:

  • Retrieval precision & recall
  • Faithfulness metrics
  • Context relevance
  • Hallucination detection
  • Automated benchmarking pipeline

6. Production Deployment Ready

  • FastAPI REST service
  • Streaming responses
  • Docker deployment
  • Configurable environments
  • Logging and monitoring support

Project Structure

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

Data Ingestion

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
}

Example Usage (Python)

from rag_engine.rag.pipeline import RAGPipeline

rag = RAGPipeline()
response = rag.query("What is RAG in LLM?")

print(response.answer)
print(response.sources)

🐳 Docker Deployment

Build container

docker build -t rag-engine .

Run container

docker run -p 8000:8000 rag-engine

Safety and Responsible AI

RAG-Engine integrates safety-first design:

  • Prompt injection defense
  • Output filtering
  • Source-grounded generation
  • Structured output validation
  • Optional trust scoring

Research & Development Roadmap

  • 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

Contributing

We welcome contributions from researchers and engineers. Steps:

  • Fork repository
  • Create feature branch
  • Commit changes
  • Submit pull request

License

MIT License

Author

Miraj Rahman AI Researcher | LLM Systems | Trustworthy AI | RAG Architect

About

RAG Engine, a component of the Vertex AI Platform, facilitates Retrieval-Augmented Generation (RAG). Vertex AI RAG Engine is also a data framework for developing context-augmented large language model (LLM) applications. Context augmentation occurs when you apply an LLM to data.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors