CRAG MultiHop Reasoning Engine: Architecture & Performance Benchmark Deep Dive

Live web application screenshot and interface of CRAG MultiHop Reasoning Engine

Key Takeaways

  • Corrective RAG MultiHop reasoning solves complex queries by decomposing them into up to 3 sequential retrieval hops.
  • Self-grading evaluator classifies context as correct, ambiguous, or incorrect, triggering automated web search fallbacks.
  • Hybrid retrieval merges dense vectors (intfloat/multilingual-e5-small) with sparse BM25, reranked locally via jina-reranker-v3 cross-encoder.
  • Real-time WebSocket streaming visualizes every pipeline stage: retrieval, grading, reranking, and generation.
  • Deployed as a containerized stack: React/Vite frontend, Django/Daphne ASGI backend, Celery/Redis async workers, ChromaDB vector store, and PostgreSQL.
Live Project Access: https://crag.nevatal.id

Live web application screenshot and interface of CRAG MultiHop Reasoning Engine
Live web application interface of CRAG MultiHop Reasoning Engine (https://crag.nevatal.id)

The Engineering Challenge: Why CRAG MultiHop Reasoning Engine Was Architected

Standard Retrieval-Augmented Generation (RAG) pipelines fail catastrophically when faced with multi-hop questions—queries requiring logical deductions across disconnected documents—and weak retrieval contexts that induce hallucinations. The CRAG MultiHop Reasoning Engine was architected specifically to address these dual failure modes by combining query decomposition, self-grading retrieval correction, and hybrid reranking into a single, observable pipeline.

Unlike monolithic RAG chains, this engine treats retrieval as a verifiable, correctable step rather than a trusted black box. The architecture enforces a “grade-then-generate” contract: if the self-grader flags retrieved chunks as ambiguous or incorrect, the system autonomously expands queries or falls back to live web search before the LLM ever sees the context.

Core Architecture & Technical Stack Deep-Dive

High-Level Deployment Topology

The system runs as a Docker Compose stack with clear separation of concerns:

Browser (React/Vite) → Nginx (Port 5151) → Daphne (Django ASGI, Port 8051)
                                   → Static Assets
Daphne → Redis (6351) → Celery Workers (Ingestion)
         → ChromaDB (8002) Vector Store
         → PostgreSQL (5432) Metadata/State

Backend: Django ASGI & Daphne

The Django application runs on Daphne (ASGI server) to natively support long-lived WebSocket connections alongside standard HTTP request/response cycles. This eliminates the need for a separate WebSocket server (e.g., Node.js/Socket.io), reducing operational complexity. Django Channels uses Redis as the channel layer for inter-process message broadcasting.

Vector Database: ChromaDB

ChromaDB serves as the primary vector index, storing embeddings generated by intfloat/multilingual-e5-small. It handles dense vector similarity search for the initial retrieval candidate set. Chroma runs as a separate container (port 8002), decoupled from the application logic for independent scaling.

Async Ingestion Pipeline: Celery + Redis

Document ingestion (PDF, TXT, URLs) is offloaded to Celery workers backed by Redis queues. This ensures the API remains responsive during heavy parsing, chunking, and embedding workloads. The worker pipeline: Parse → Chunk → Embed (e5-small) → Upsert ChromaDB.

Frontend: React + Vite + WebSocket Client

The React SPA (built via Vite) establishes a WebSocket connection to /ws/query/ immediately upon query submission. The UI renders a live pipeline timeline—Retrieving → Grading → Reranking → Generating—consuming server-sent events (SSE-style over WS) for granular progress updates.

Key Features Breakdown & Practical Benefits

1. Sequential Multi-Hop Query Decomposition (Up to 3 Hops)

The orchestrator uses the LLM (via OpenRouter Qwen 30B) to decompose a complex question into a dependency graph of sub-queries. Each hop executes sequentially: the answer/context from Hop N is injected into the prompt for Hop N+1. This mimics human research behavior—finding an entity in Doc A, then searching for that entity’s relations in Doc B.

2. Corrective RAG (CRAG) Self-Grading Evaluator

Before generation, every retrieved chunk set passes through a self-grading prompt that classifies context utility:

  • CORRECT: Sufficient evidence; proceed to generation.
  • AMBIGUOUS: Partial relevance; trigger query expansion + re-retrieval.
  • INCORRECT: Irrelevant/noisy; trigger external web search fallback.

This prevents the “garbage in, garbage out” problem inherent in naive RAG.

3. Automated Live Web Search Fallback

When the grader returns AMBIGUOUS or INCORRECT, the pipeline automatically constructs expanded queries and hits a live search API. Results are merged into the candidate pool, re-graded, and only then passed forward. This “self-healing” loop is the defining characteristic of Corrective RAG.

4. Hybrid Retrieval: Dense + Sparse (BM25) + Local Cross-Encoder Reranking

Retrieval is a two-stage funnel:

  1. Candidate Generation (Hybrid): Parallel dense vector search (ChromaDB, cosine similarity) + sparse lexical search (BM25 via rank_bm25 on stored chunks). Results merged via Reciprocal Rank Fusion (RRF).
  2. Precision Reranking: Top-k merged candidates scored by Jina Reranker v3 (cross-encoder) running locally. This captures semantic nuance missed by bi-encoders or keyword overlap.

5. Real-Time WebSocket Pipeline Observability

Every stage emits a typed event over the WebSocket: hop_started, retrieval_complete, grading_result, rerank_complete, generation_streaming. The frontend renders these as an animated timeline, giving users (and developers) full transparency into latency bottlenecks and decision points.

6. Per-Query Pipeline Configuration Toggles

The UI exposes toggles for: Multi-Hop (on/off, max hops), CRAG Grading (on/off), Reranking (on/off), Dense Retrieval (on/off), Sparse/BM25 (on/off). This enables A/B testing and ablation studies directly from the browser without code changes.

Real-World Deployment & Production Topology

The production deployment at https://crag.nevatal.id follows the architecture diagram above. Nginx terminates TLS and routes /api and /ws to Daphne, while serving static React assets directly. Redis runs with persistence enabled (AOF) to survive restarts without losing channel state or Celery task queues. ChromaDB data is mounted on a persistent volume. PostgreSQL stores document metadata, ingestion job status, and query logs for analytics.

Graceful Degradation Strategy: If Jina Reranker OOMs or ChromaDB is slow, the pipeline catches exceptions, logs structured errors, and falls back to the pre-rerank candidate set (or dense-only if BM25 fails). The WebSocket emits a stage_degraded event so the UI reflects the reduced capability rather than hard-failing.

Data Flow & How It Works: Step-by-Step Workflow

  1. User submits query via React UI → WebSocket connection opened.
  2. Multi-Hop Planner (LLM) decomposes query into sub-queries (Hop 1, 2, 3).
  3. For each Hop:
    • Hybrid Retrieval: Dense (ChromaDB) + Sparse (BM25) → RRF merge.
    • Local Rerank: Jina Reranker v3 scores top-k.
    • CRAG Gr

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *