Triamorph Systems

Applied AI · 15 min read · Sep 08, 2024

Eliminating RAG Hallucinations: Building Production Retrieval Systems with Self-RAG, Corrective RAG, and Cohere Reranking

Comprehensive guide to eliminating hallucinations in enterprise RAG: implementing Self-RAG reflection tokens, Corrective RAG (CRAG) web-fallbacks, and Cohere semantic rerankers.

By Aman Aslam

Core Engineering Takeaways

  • Vector search alone yields poor recall on domain-specific queries; implementing hybrid dense-sparse search (Qdrant + BM25) combined with Cohere Rerank v3 increases retrieval accuracy by over 45%.
  • Self-RAG introduces internal critique nodes that evaluate retrieval necessity (`[Retrieve]`), relevance (`[IsRel]`), and grounded support (`[IsSup]`) before synthesizing output.
  • Corrective RAG (CRAG) evaluates retrieval confidence scores; if confidence falls below threshold, the system automatically reformulates queries or triggers fallback web search.

Naive Retrieval-Augmented Generation (RAG)—chunking documents, storing embeddings, and pulling Top-K vector matches—fails miserably in real-world enterprise deployments. Vector embeddings struggle with specific keyword queries, retrieve out-of-context noise, and provide confident hallucinations when the knowledge base lacks an answer. Production-grade RAG systems in 2026 deploy Self-RAG reflection nodes, Corrective RAG (CRAG) evaluation fallbacks, and two-stage cross-encoder reranking.

1. Why Naive Vector Search Fails in Enterprise Applications

Understanding cosine similarity blind spots and context pollution

Cosine similarity measures semantic relatedness, not factual accuracy. If a user asks "What was the revenue in Q3 2024?", dense embeddings will retrieve chunks containing "Q3 2023 revenue" or "Q4 2024 projections" because the vocabulary is nearly identical.

Injecting low-relevance chunks into the LLM context window dilutes attention (the "lost in the middle" phenomenon) and forces the model to synthesize contradictory answers.

Hallucination Reduction
88%
Self-RAG reflection + Cohere Reranking
Retrieval Precision
94.6%
Hybrid BM25 + Qdrant Dense Vectors
P95 Pipeline Latency
< 650ms
Parallelized asynchronous evaluation

2. Two-Stage Retrieval: Hybrid Search + Cohere Rerank v3

Combining sparse keyword matching with deep transformer cross-encoders

We implement a two-stage retrieval pipeline: Stage 1 retrieves the top 50 candidates using Reciprocal Rank Fusion (RRF) between dense vector embeddings and BM25 full-text search. Stage 2 passes the top 50 candidates through a Cohere Rerank v3 cross-encoder model to select the top 5 most relevant chunks.

ai/retrieval/self_corrective_rag.py (python)
import cohere
from qdrant_client import QdrantClient
from langchain_openai import ChatOpenAI

co = cohere.Client(os.getenv("COHERE_API_KEY"))
llm = ChatOpenAI(model="gpt-4o", temperature=0.0)

def retrieve_and_rerank(query: str, collection_name: str) -> list[str]:
    # 1. Stage 1: Hybrid Sparse + Dense Retrieval (Top 40 candidates)
    initial_docs = qdrant.query_points(
        collection_name=collection_name,
        query=query,
        limit=40
    )
    
    doc_texts = [doc.payload["content"] for doc in initial_docs.points]
    
    # 2. Stage 2: Cohere Semantic Cross-Encoder Reranking
    rerank_results = co.rerank(
        model="rerank-english-v3.0",
        query=query,
        documents=doc_texts,
        top_n=5,
        return_documents=True
    )
    
    # 3. Filter by relevance threshold
    high_confidence_docs = [
        result.document.text for result in rerank_results.results
        if result.relevance_score >= 0.72
    ]
    
    return high_confidence_docs

def evaluate_groundedness(query: str, context_docs: list[str], candidate_answer: str) -> bool:
    """Self-RAG Critique: Verify that answer is strictly grounded in retrieved text"""
    critique_prompt = f"""Given the context: {' '.join(context_docs)}
Verify if the answer: '{candidate_answer}' is 100% supported by the context without hallucination.
Output ONLY 'GROUNDED' or 'HALLUCINATED'."""
    result = llm.invoke(critique_prompt)
    return "GROUNDED" in result.content

3. Implementing Self-RAG Reflection Loops

Injecting validation reflection nodes before returning answers to users

Self-RAG utilizes dedicated reflection prompts to grade retrieved passages on relevance before feeding them to the generation model. If retrieved chunks fail relevance grading, the model triggers an alternative query decomposition step.

4. Corrective RAG (CRAG) & Knowledge Refinement

Automated query reformulation and external verification fallbacks

Corrective RAG categorizes retrieval confidence into three states: Correct (proceed to synthesis), Incorrect (strip retrieved context and trigger web search or fallback API), and Ambiguous (combine retrieved context with external verification).

Tags: eliminating rag hallucinationsself corrective rag architecturecrag corrective retrieval augmented generationcohere semantic reranking langchainproduction rag accuracy benchmarks

Related Engineering Practice & Case Studies

Engineering Practice Blueprint

AI Automation & Applied Intelligent Systems →

Production LLM agent integration, computer vision, and Model Context Protocol pipelines.

View Practice Blueprint & Capabilities →
Production Client System

VisageGuard Biometric Security Platform →

Edge facial recognition and biometric identity verification platform with sub-300ms verification latency.

Read Deployed Case Study (99.4% verification accuracy at sub-300ms edge latency) →

Related Engineering Articles & Guides

Explore all technical guides in our Articles & Guides Index → or discuss your architecture with our engineers via Technical Discovery →