RAG Pipeline ArchitectureInteractive Flow Diagram

How the System Works

An end-to-end Retrieval-Augmented Generation pipeline engineered with two-stage neural reranking, verified character citations, and strict anti-hallucination guardrails.

Complete RAG Pipeline Flow Diagram

Click any node below to inspect real-time data payloads and Python code implementation.

Node: Document Ingestion
STAGE 1Document Ingestion, Chunking & Embedding Index
Query Execution & Inference Pipeline
STAGE 2Two-Stage Retrieval, Cross-Encoder Rerank & Grounded Answer Stream
1

Document Ingestion

INGESTION
Input Data Payload

URL or Raw Document (HTML/PDF/Text)

Output / Stored Transformation

Clean sanitized text + metadata (Title, URL)

Key Engineering Specs

Extracts text via BeautifulSoup4 with HTML tag sanitization and paragraph preservation.
Strips navigation bars, scripts, advertisements, and extraneous markup.
Extracts metadata: Canonical URL, title, document length, and creation timestamp.

Python / Backend Implementation

def scrap_return_text(url: str) -> str:
    res = requests.get(url, headers={'User-Agent': 'Mozilla/5.0...'})
    soup = BeautifulSoup(res.text, 'html.parser')
    paragraphs = [p.get_text().strip() for p in soup.find_all('p')]
    return "\n\n".join([p for p in paragraphs if len(p) > 20])

🛡️ Core Design Decisions & Anti-Hallucination Guardrails

Hallucination Prevention

The model receives direct document context chunks and strict grounding instructions. If the retrieved context does not contain sufficient facts to answer the question, the system clearly states the lack of documentation rather than confabulating plausible claims.

Verified Citation Graph

Cohere's fine-grained citation engine produces exact start-and-end character spans matching specific retrieved documents. Our frontend replaces these tokens with interactive React popover badges linked to corresponding source cards below.

Two-Stage Rerank Precision

Single-stage vector search alone often surfaces false positives due to cosine distance limitations. Adding Cohere's cross-encoder reranker ensures only the highest-scoring paragraphs enter the LLM's prompt window.

📋 Deliverables & Feature Checklist

Feature / CapabilityStatusImplementation Details
Document Upload & IngestionImplementedSupports web URLs, raw text, and document store
Text Extraction & CleaningImplementedBeautifulSoup parser, HTML sanitization, whitespace normalization
Sentence-Level ChunkingImplementedSentence boundary segmentation with 100-char overlap (~700 chars)
Dense Embedding GenerationImplementedCohere embed-multilingual-v3.0 (1024 dimensions) with 429 retry
Vector Indexing & SearchImplementedCosine distance similarity search over vector store
Cross-Encoder RerankingImplementedCohere rerank-v3.5 top-K precision filter (relevance > 0.3)
Grounded Answer GenerationImplementedCohere command-r-08-2024 with document grounding
Inline Citations & Source LinksImplementedInteractive [1], [2] hover popovers + connected source cards
Conversation History & BranchingImplementedTree-based conversation branching, history sidebar, title editing
Docs Management UIImplementedTable view, document addition, preview modal, deletion
Responsive Next.js FrontendImplementedReact + Redux Toolkit + Tailwind CSS + Syntax Highlighter