Skip to content

Latest commit

Β 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Scalable Enterprise RAG System

Production-grade Retrieval-Augmented Generation (RAG) system designed for enterprise-scale document ingestion, semantic search, and LLM-powered question answering.

This project focuses on scalability, modularity, system design, observability, and evaluation β€” not demo-level RAG pipelines.


πŸš€ Key Features

  • Modular end-to-end RAG architecture
  • Multi-format document ingestion (TXT, PDF, DOCX)
  • Incremental knowledge base updates (no re-embedding unchanged data)
  • Persistent FAISS vector store
  • Hash-based embedding cache
  • Observability-first UI (latency, retrieved chunks, confidence)
  • Explicit evaluation layer (Recall@K, latency)
  • Dockerized & Cloud Run–ready
  • GCP Secret Manager integration
  • Designed with enterprise document systems in mind

🌐 Live Deployment

The application is deployed on Google Cloud Run and is publicly accessible.

πŸ”— Live URL:
https://scalable-enterprise-rag-761523979642.asia-south1.run.app

Deployment Details

  • Hosted on Google Cloud Run
  • Container image stored in Artifact Registry
  • HTTPS enabled by default
  • Autoscaling based on traffic
  • Secrets securely injected via GCP Secret Manager

This deployment closely mirrors how production-grade GenAI / RAG services are deployed in real enterprise environments.


πŸ“„ Supported Document Formats

The system supports multi-format enterprise document ingestion:

  • βœ… TXT β€” Plain text files
  • βœ… PDF β€” Extracted using pypdf
  • βœ… DOCX β€” Extracted using python-docx

Documents are routed to loaders using a factory-based ingestion layer, making it trivial to add support for formats like HTML, Markdown, or PPTX.


🧠 Knowledge Base Lifecycle

This system implements a production-grade knowledge base lifecycle.

βœ… Incremental Ingestion

  • Each document receives a stable, deterministic document ID
  • Content hashes tracked via kb_state.json
  • Only new or modified documents are chunked and embedded

βœ… Persistent Vector Store

  • FAISS index and metadata are persisted
  • Restarting the service does not rebuild embeddings
  • The knowledge base grows incrementally over time

βœ… Safe Reuse Without Recompute

  • If documents are already ingested, the system reuses the existing FAISS index
  • The RAG pipeline auto-initializes from persisted state
  • This avoids unnecessary compute cost and LLM calls

πŸ‘€ Observability & Transparency

The Streamlit UI exposes internal system behavior:

  • ⏱ Retrieval latency (ms)
  • πŸ“¦ Number of retrieved chunks
  • 🟒 Confidence indicator (heuristic)
  • πŸ“š Exact retrieved contexts used by the LLM

This mirrors internal enterprise RAG tools used at large tech companies β€” not black-box demos.


πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Raw Documentsβ”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Ingestion     β”‚ ← loaders.py, cleaner.py
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Chunking      β”‚ ← strategies.py
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Embeddings    β”‚ ← GeminiEmbedder + cache
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Vector Store  β”‚ ← FAISS (persistent)
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Retrieval     β”‚ ← Top-K semantic search
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LLM Response  β”‚ ← Gemini (grounded)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure


scalable-enterprise-rag/
β”‚
β”œβ”€β”€ app/
β”‚   └── ui.py                 # Streamlit UI (ingestion, QA, observability)
β”‚
β”œβ”€β”€ ingestion/
β”‚   β”œβ”€β”€ base.py               # BaseLoader abstraction
β”‚   β”œβ”€β”€ loaders.py            # Loader factory (TXT / PDF / DOCX)
β”‚   β”œβ”€β”€ pdf_loader.py
β”‚   β”œβ”€β”€ docx_loader.py
β”‚   └── cleaner.py
β”‚
β”œβ”€β”€ chunking/
β”‚   └── strategies.py         # Fixed-size chunking with overlap
β”‚
β”œβ”€β”€ embeddings/
β”‚   β”œβ”€β”€ embedder.py           # GeminiEmbedder
β”‚   └── cache.py              # Hash-based embedding cache
β”‚
β”œβ”€β”€ vectorstore/
β”‚   β”œβ”€β”€ faiss_store.py        # Persistent FAISS index wrapper
β”‚   └── kb_manager.py         # Incremental KB lifecycle manager
β”‚
β”œβ”€β”€ retrieval/
β”‚   └── retriever.py
β”‚
β”œβ”€β”€ llm/
β”‚   └── gemini_llm.py
β”‚
β”œβ”€β”€ rag/
β”‚   └── pipeline.py           # RAG orchestration + observability
β”‚
β”œβ”€β”€ evaluation/
β”‚   β”œβ”€β”€ latency.py
β”‚   β”œβ”€β”€ retrieval_metrics.py
β”‚   └── run_evaluation.py
β”‚
β”œβ”€β”€ data/                     # ❌ Ignored (runtime artifacts)
β”‚
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ .gitignore
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── LICENSE


βš™οΈ Configuration & Secrets

Local Development

  • Secrets are loaded via a .env file
  • The .env file is gitignored

Production (Cloud Run)

  • Secrets are managed using GCP Secret Manager
  • Secrets are injected as environment variables at runtime
  • No secrets are baked into Docker images or source code

πŸ“Š Evaluation & Metrics

Unlike most RAG demos, this project includes an explicit evaluation layer.

Planned/supported metrics:

  • Retrieval latency
  • Recall@K
  • Mean Reciprocal Rank (MRR)
  • End-to-end pipeline latency

πŸ§ͺ How to Run Locally

# Clone repository
git clone https://github.com/Indrasish7/scalable-enterprise-rag.git
cd scalable-enterprise-rag

# Create virtual environment
python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run the pipeline
streamlit run app/ui.py

🐳 Docker (Production-Equivalent)

docker build -t scalable-enterprise-rag .
docker run -p 8501:8501 scalable-enterprise-rag

☁️ Cloud Deployment (GCP)

  • Docker image pushed to Artifact Registry
  • Deployed on Cloud Run
  • Autoscaling enabled by default
  • Secure HTTPS endpoint exposed
  • Secrets injected securely via GCP Secret Manager

This setup mirrors real-world GenAI service deployments used in production environments.


🧩 Design Philosophy

  • Production-first mindset
  • Clear separation of concerns
  • Compute-efficient incremental updates
  • Scales from small document sets to enterprise corpora
  • Easily extensible for hybrid search, reranking, and evaluation

πŸ›£οΈ Roadmap

Planned improvements to evolve this into a fully production-ready RAG system:

  • Hybrid retrieval (BM25 + Dense vectors)
  • Cross-encoder reranking for improved answer relevance
  • Streaming LLM responses
  • Multi-tenant vector index support
  • Monitoring & latency tracing
  • Kubernetes-native deployment

πŸ‘€ Author

Indrasish Bhattacharjee
AI Engineer | GenAI β€’ RAG β€’ LLMs β€’ FAISS
πŸ“ India
πŸ”— LinkedIn: https://www.linkedin.com/in/indrasishbhattacharjee


πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.


⭐ If this repository helped you understand production-grade RAG systems, consider starring it.

About

Production-grade Retrieval-Augmented Generation (RAG) system with scalable ingestion, FAISS-based vector search, and LLM-powered retrieval.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages