CYBEN / AI← All systemsStart a project ↗
CASE STUDY / 26PRODUCT SYSTEM

Corrective RAG

A self-correcting Retrieval-Augmented Generation (CRAG) system that evaluates document relevance with an LLM and automatically triggers web search fallback to eliminate hallucinations.

  • AI
  • RAG
  • Full-Stack
Corrective RAG case study cover
PROJECT VISUAL2026

Context

Standard Retrieval-Augmented Generation (RAG) pipelines blindly synthesize answers from whatever document chunks vector search returns. When uploaded documents lack relevant information, classic RAG models frequently generate convincing hallucinations.

Corrective RAG (CRAG) addresses this vulnerability by introducing an automated quality-control loop. Built with FastAPI, LangGraph, Pinecone, and Groq, the platform evaluates retrieved passage relevance before generation and dynamically initiates Tavily web search when local context falls short.

The problem

Enterprise RAG deployments suffer when users ask questions outside the domain of uploaded knowledge bases. Because traditional systems lack relevance self-assessment, they force LLMs to compose answers from weak or off-topic context.

Furthermore, synchronous vector indexing during large PDF uploads can block user interfaces, while naive vector similarity search often retrieves redundant or noisy document chunks.

Product strategy

The strategy was to implement a self-correcting decision graph in LangGraph that grades vector retrieval results before answer generation, creating a resilient dual-path system grounded in verified local documents or real-time web evidence.

  • Evaluated retrieval

    Grade retrieved document chunks with a dedicated LLM prompt prior to feeding evidence into generation.

  • Autonomous web fallback

    Trigger Tavily search automatically when document relevance falls below confidence thresholds.

  • Transparent source attribution

    Provide explicit source file, page number, and web URL citations alongside a visual web fallback indicator.

AuraNode turns that strategy into one native workspace with a provider-neutral backend.

PDF chunking & local embedding

Extract text with pypdf, chunking at 500 characters with 100 overlap, and generating 384-dim dense vectors locally via BGE-small.

Pinecone MMR vector search

Execute Maximal Marginal Relevance search (k=5, fetch_k=20) in Pinecone Serverless to maximize result diversity.

LLM document grading

Assess retrieved chunk relevance via Groq LLM inference, classifying context quality before committing to synthesis.

Dynamic web search fallback

Query Tavily Web Search when local document chunks fail grading, incorporating real-time web context into the final answer.

System architecture

A React single-page frontend communicates with a FastAPI service running a LangGraph CRAG pipeline that pairs Pinecone vector search with LLM relevance grading and automatic Tavily web search fallback.

Live request topologyPrompt travels right · tokens stream leftPrompt travels down · tokens stream up
State 01
Client / presentation

React + Vite UI

Single-page interface providing document upload, query input, real-time vector status checks, and clear source attribution with web fallback indicators.

  • React 18
  • Vite
  • Axios
State 02
Application API

FastAPI REST Server

Asynchronous Python API handling PDF parsing (pypdf), text chunking (500 chars/100 overlap), BGE embedding generation, and Pinecone vector store updates.

  • FastAPI
  • Python
  • pypdf
State 03
Correction Pipeline

LangGraph CRAG Graph

Orchestrates Pinecone MMR retrieval (k=5), evaluates document relevance with Groq LLM, and dynamically branches to Tavily web search if retrieved context is weak.

  • LangGraph
  • LangChain
  • Groq
State 04
Vector & Fallback

Pinecone & Tavily Search

Pinecone Serverless index ('rag-docs') performs dense vector retrieval while Tavily Web Search executes live fallback web queries when local context fails relevance grading.

  • Pinecone
  • BGE Embeddings
  • Tavily
Worker dependenciesState · data · commerce
Vector Queries

Pinecone Serverless

Stores 384-dimensional dense vectors generated by HuggingFace BGE-small, performing Maximal Marginal Relevance (MMR) search over uploaded documents.

External Retrieval

Tavily Search API

Retrieves external web results to supply fresh evidence whenever local document relevance falls below confidence thresholds.

LLM Completion

Groq LLM Engine

High-speed Groq inference for document relevance binary grading and final grounded answer generation with explicit source list formatting.

Request lifecycle

When a user submits a query, FastAPI triggers the LangGraph Corrective RAG workflow. The graph first invokes Pinecone using Maximal Marginal Relevance (MMR) search to extract candidate document passages embedded via local HuggingFace bge-small models. A Groq-powered LLM evaluator grades each chunk’s relevance. If the retrieved context passes relevance evaluation, the system synthesizes a grounded answer from local documents. If context is deemed irrelevant or insufficient, the graph automatically triggers Tavily Web Search, incorporates web evidence, and generates the final answer with a used_web_search: true flag and explicit source citations.

Separation of concerns

The React frontend handles document upload, search UI, and source rendering. The FastAPI layer decouples file processing and vector store operations from client requests. The LangGraph engine encapsulates the corrective decision logic, keeping vector retrieval (Pinecone), document grading (Groq), web fallback (Tavily), and answer generation cleanly separated.

Key experiences

The application gives users complete transparency into document ingestion, retrieval quality, and fallback triggers.

01

Multi-PDF upload workspace

Upload multiple document files with real-time vector status monitoring and clear session index controls.

02

Interactive QA interface

Ask natural language questions and receive grounded responses with highlighted source files and page numbers.

03

Web fallback indicator

Display explicit visual badges whenever Tavily web search was triggered to supplement local document gaps.

04

Session vector clearing

One-click index clearing endpoint prevents free-tier vector accumulation during iterative demo testing.

Engineering decisions

FastAPI & Uvicorn for asynchronous REST endpoints

FastAPI handles multipart PDF uploads, vector status polling, and streaming query responses.

LangGraph for stateful correction workflow

Explicit graph nodes and conditional branches govern Pinecone retrieval, relevance grading, and web search routing.

Groq for ultra-low latency relevance grading

High-speed LLM inference via Groq performs chunk evaluation and final answer synthesis without UI lag.

Local HuggingFace BGE embeddings

Runs BGE-small (BAAI/bge-small-en-v1.5) locally on CPU, ensuring vector embeddings require zero external API costs.

Pinecone Serverless vector storage

Scalable vector index ('rag-docs') supporting cosine similarity and Maximal Marginal Relevance filtering.

Dockerized backend & Vercel frontend

Containerized FastAPI backend compatible with Docker hosting paired with a Vercel-deployed React 18 SPA.

Current status / Dockerized release

A self-correcting RAG platform with web fallback.

Corrective RAG solves the fundamental vulnerability of classic RAG by introducing automated retrieval evaluation and live web search fallback.

The project is containerized via Docker and open-sourced with full setup scripts, FastAPI endpoints, and a Vite React frontend.

  • LangGraph state machine with automated LLM relevance grading and Tavily web fallback
  • Pinecone Serverless vector retrieval using MMR for diverse context matching
  • Local HuggingFace BGE-small embedding generation requiring zero external API cost
  • Groq LLM integration for sub-second chunk grading and grounded synthesis
  • Dockerized container release with Vercel React 18 single-page app
Continue exploring