How labdmitriy/llm-rag works
Project type and purpose
• This is a Python library and tutorial suite for “RAG From Scratch,” a Retrieval‐Augmented Generation (RAG) framework built on top of LangGraph.
• It provides:
• An indexing subsystem (converts documents into vector embeddings)
• A collection of RAG “graph” pipelines (various query‐translation and generation strategies)
• Demo notebooks to show each RAG variant in action
File structure
• Top‐level:
• .env.example, README.md, pyproject.toml, requirements.txt (configuration & packaging)
• notebooks/ (Jupyter tutorials)
• src/llm_rag/ (core library)
• Inside src/llm_rag/:
• indexing/ (article ingestion, multi‐vector, RAPTOR, self‐query, ColBERT model adapters)
• graphs/ (one folder per RAG strategy: multi_query, rag_fusion, decomposition, step_back, hyde, routing, etc.)
• utils.py (shared utilities)
• No web frontend or database schemas—this is a modular Python package, not a web app.
README for additional insights
• Specifies how to configure .env for API keys, how to install via pip or uv.
• Links each graph submodule to its Jupyter demo.
• Mentions external dependencies: LLM APIs (OpenAI, Hugging Face), vector stores (FAISS, Pinecone), ColBERT.
1. Configuration & CLI
• .env loader
• uv command‐line interface or direct Python import
2. Data Stores
• Vector database (FAISS / Pinecone / Weaviate)
• (Optionally) local file store for raw documents
3. Indexing Subsystem
• llm_rag.indexing modules
• Embedding model(s)
• Multi‐vector / CRAG / RAPTOR adapters
• Writes to Vector DB
4. Graph Execution Engine
• llm_rag.graphs subpackages
• Each graph implements a retrieval‐generation pipeline:
• Query → Query‐translation (multi‐query, decomposition, routing, step_back, hyde, etc.)
• Retrieval from Vector DB
• LLM generation step(s)
• Orchestrated by LangGraph core
5. LLM Service(s)
• OpenAI / Hugging Face APIs
6. Developer Interface
• Jupyter Notebooks
• Python SDK (import llm_rag in scripts)
1. Config → CLI/SDK (loads API keys, settings)
2. Raw Documents → Indexing Subsystem → Vector DB
3. User Query → Graph Execution Engine
→ (1) Query‐translation modules → (2) Vector DB retrieval → (3) LLM Service
→ Graph aggregates and fuses responses → returns final answer → User
4. Notebooks ↔ CLI/SDK (invoke indexing and graph functions interactively)
c. Architectural Patterns & Design Principles
• Modular design: separate “indexing” vs. “graph” concerns
• Strategy pattern: each RAG variant is a pluggable graph subpackage
• Dependency inversion: graph modules depend on abstract embedding & retrieval interfaces
• Single responsibility: each submodule does one variant of query translation or indexing
d. Relevant Technologies
• Python 3.x, pip, uv (packaging & CLI)
• LangGraph (core orchestration)
• Vector DBs: FAISS, Pinecone, Weaviate (configurable)
• LLM APIs: OpenAI, Hugging Face
• ColBERT (optional late‐interaction retrieval)