← Back to Chat
🔬 Architecture & Systems Design

System Architecture

A comprehensive technical overview of the ContextAware Retrieval-Augmented Generation (RAG) framework, detailing ingestion pipelines, retrieval heuristics, and generative orchestration.

3
Retrieval Stages
512
Tokens / Chunk
768
Embedding Dims
5
LLM Providers
10+
Modules Built

Asynchronous Data Processing Pipeline

The end-to-end operational flow encompassing document ingestion, semantic embedding, vector indexing, and optimal context retrieval for generative inference.

📥 Phase I: Corpus Ingestion & Indexing
📄1. Document Acquisition
Asynchronous file handling via FastAPI multipart/form-data.
↓
🔍2. PDF Parsing & Extraction
PyMuPDF-driven optical text extraction, preserving spatial metadata and pagination.
↓
✂️3. Recursive Text Chunking
Semantic boundary splitting algorithm yielding 512-token chunks with 64-token overlap for contextual continuity.
↓
🔢4. High-Dimensional Embedding
Transformation of textual data into 768-dimensional dense vectors utilizing Gemini-Embedding-001.
↓
🗄️5. Persistent Vector Storage
Indexing within an isolated ChromaDB HNSW (Hierarchical Navigable Small World) collection optimized for cosine similarity.
💬 Phase II: Grounded Retrieval & Generation
❓1. User Query Modeling
Semantic mapping of the user's natural language input into the shared vector space.
↓
🎯2. Candidate Set Retrieval
Efficient Approximate Nearest Neighbor (ANN) search isolating the top 30 potential candidate chunks.
↓
🧬3. Multi-Objective Subset Optimization
Algorithmic selection maximizing: f(S) = α·Relevance + β·Coverage + γ·Support — fundamentally mitigating semantic redundancy.
↓
⚡4. Cross-Encoder Reranking
Secondary validation via ms-marco-MiniLM-L-6-v2 to evaluate strict query-document entailment prior to generation.
↓
🤖5. Constrained Generative Inference
LLaMA 3 70B synthesizes a precise response, strictly constrained by the validated context to eliminate parametic hallucination.

Technology Stack

Key technologies powering each layer of the application.

LLM
Groq LLaMA 3
Google Gemini & OpenAI
Embedding
gemini-001
768 dim dense vectors
Storage
ChromaDB
HNSW persistent index
Backend
FastAPI
Async Python REST API
Ranking
ms-marco-L-6
CrossEncoder ranking
Frontend
HTML & Tailwind JS
Black Transparent UI
Parsing
PyMuPDF
Text/Meta extraction
Optimizer
Multi-Obj Greedy
Submodular selection

Original Research Contributions

Contrasting the implemented methodology against standard baseline constraints observed in contemporary RAG systems.

❌ Standard Baseline: Naïve Top-K Dense Retrieval
  • • Ranks documents independently by marginal cosine similarity.
  • • Fails to account for inter-document semantic overlap across the retrieved set.
  • • Frequently populates the context window with clustered, highly redundant text chunks.
  • • Induces severe hallucination risk when generative reasoning requires a diverse, multi-perspective synthesis of information.
✅ Proposed Method: Submodular Context Optimization
  • • Transitions selection logic from a sorting heuristic to a constrained knapsack optimization sequence.
  • • Jointly penalizes semantic redundancy while enforcing query relevance and inter-chunk factual support.
  • • Evaluates each candidate dynamically conditioned on the distribution of already-selected chunks.
  • • Demonstrably enhances grounding robustness and eliminates systemic generative contradictions.