Skip to content

Repository files navigation

Production-Ready RAG Application in Python

This project demonstrates a modular, enterprise-style Retrieval-Augmented Generation (RAG) application built with modern LangChain components.

Project Structure

  • DocumentLoader/: load source documents from disk
  • TextSplitter/: split documents into retrievable chunks
  • Embeddings/: generate vector embeddings
  • VectorStores/: persist and query vector indexes
  • Retriever/: retrieve relevant context for a query
  • Prompts/: prompt templates for generation
  • Models/: chat model wrappers
  • Chains/: orchestrate the full RAG pipeline

Features

  • Environment-based configuration
  • Structured logging
  • PEP8-friendly modular code
  • Exception handling and validation
  • LangChain v0.3+ style architecture
  • FAISS-backed vector search
  • Gemini-based embeddings and chat model

Setup

  1. Create and activate a virtual environment
  2. Install dependencies
  3. Copy .env.example to .env and fill in your values
  4. Run the application
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
python main.py

Environment Variables

  • GOOGLE_API_KEY
  • RAG_SOURCE_PATH
  • RAG_QUERY
  • EMBEDDING_MODEL
  • CHAT_MODEL
  • MODEL_TEMPERATURE
  • VECTOR_STORE_PATH
  • LOG_LEVEL

Expected Output

Running the app prints a concise answer generated from the retrieved context.

Architecture Diagram

User Query
|
v
RAG Chain
|-> DocumentLoader
|-> TextSplitter
|-> Embeddings
|-> VectorStores
|-> Retriever
|-> Prompts + Models
v
Final Answer

Execution Flow

1. Load document from disk
2. Split into chunks
3. Create embeddings
4. Build FAISS index
5. Retrieve relevant chunks
6. Generate answer with Gemini

Best Practices

  • Keep modules small and focused
  • Use environment variables for secrets and configuration
  • Add logging everywhere
  • Handle exceptions explicitly
  • Prefer dependency injection over hard-coded values
  • Version-pin dependencies for reproducibility

Interview Questions

  1. What is the difference between retrieval and generation in a RAG system?
  2. How does chunk size affect retrieval performance?
  3. Why are embeddings important in vector search?
  4. What is the role of the retriever in a RAG pipeline?
  5. How would you scale this architecture for production?

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages