Skip to Content

RAG Patterns

7 intelligent retrieval-augmented generation patterns for knowledge management.

Overview

isA Data supports multiple RAG patterns optimized for different use cases:

PatternDescriptionLatencyBest For
SimpleBasic vector search + LLMFastGeneral Q&A
CRAGCorrective with validationMediumFact-checking
HyDEHypothetical document embeddingsMediumSparse data
Graph RAGKnowledge graph enhancedMediumEntity relationships
RAG FusionMulti-query fusionMediumComplex questions
Self-RAGSelf-reflective generationSlowHigh accuracy
RAPTORRecursive summarizationSlowLong documents

Simple RAG

Basic vector similarity search with LLM generation.

How It Works

Query → Embed → Vector Search → Top-K Chunks → LLM → Response

Usage

# Store response = await client.post( "/api/v1/digital/store", json={ "user_id": "user123", "content": "Your content here", "content_type": "text" } ) # Search response = await client.post( "/api/v1/digital/search", json={ "user_id": "user123", "query": "Your question", "search_options": { "rag_mode": "simple", "top_k": 5 } } ) # Response response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "Your question", "response_options": { "rag_mode": "simple" } } )

CRAG (Corrective RAG)

Adds self-correction through relevance validation.

How It Works

Query → Retrieve → Relevance Check ─┬─▶ Relevant → Generate └─▶ Not Relevant → Web Search → Generate

Features

  • Relevance scoring for retrieved chunks
  • Automatic fallback to web search
  • Self-correction loop

Usage

response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "What is the capital of France?", "response_options": { "rag_mode": "crag", "relevance_threshold": 0.7, "use_web_search": True } } )

HyDE (Hypothetical Document Embeddings)

Generates hypothetical documents to improve retrieval.

How It Works

Query → LLM → Hypothetical Doc → Embed → Search → Real Docs → Generate

When to Use

  • Vague or abstract queries
  • Sparse knowledge bases
  • Concept-based search

Usage

response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "How do neural networks learn?", "response_options": { "rag_mode": "hyde", "num_hypothetical_docs": 1 } } )

Graph RAG

Knowledge graph-enhanced retrieval for entity relationships.

How It Works

Query → Extract Entities → Graph Traversal → Context Enrichment → Generate │ │ ▼ ▼ Neo4j Store Related Entities

Features

  • Entity extraction from documents
  • Relationship mapping
  • Multi-hop traversal
  • Context enrichment

Usage

# Store with graph indexing response = await client.post( "/api/v1/digital/store", json={ "user_id": "user123", "content": "Apple Inc. was founded by Steve Jobs in Cupertino.", "content_type": "text" } ) # Query with graph context response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "Who founded Apple?", "response_options": { "rag_mode": "graph_rag", "use_neo4j": True, "max_hops": 2 } } )

Graph Components

ComponentPurpose
Entity ExtractorExtract entities from text
Relation ExtractorIdentify relationships
Graph ConstructorBuild Neo4j graph
Knowledge RetrieverTraverse and retrieve

RAG Fusion

Multi-query fusion with Reciprocal Rank Fusion (RRF).

How It Works

Original Query → Query Variants (3-5) → Parallel Search → RRF Fusion → Generate │ │ ▼ ▼ Rephrase/Expand Dedupe + Rank

Features

  • Multiple query variations
  • Parallel retrieval
  • RRF score combination
  • Improved recall

Usage

response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "Best practices for microservices", "response_options": { "rag_mode": "rag_fusion", "num_queries": 3, "fusion_weight": "equal" } } )

Self-RAG

Self-reflective generation with quality checks.

How It Works

Query → Retrieve → Generate Draft → Self-Critique ─┬─▶ Good → Return └─▶ Bad → Regenerate

Features

  • Response quality assessment
  • Automatic regeneration
  • Hallucination detection
  • Confidence scoring

Usage

response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "Explain quantum computing", "response_options": { "rag_mode": "self_rag", "reflection_enabled": True, "max_iterations": 3 } } )

RAPTOR

Recursive Abstractive Processing for Tree-Organized Retrieval.

How It Works

Documents → Chunk → Cluster → Summarize → Build Tree → Search Tree → Generate Hierarchical Index /\ / \ Summaries / \ Chunks Chunks

Features

  • Hierarchical summarization
  • Multi-level retrieval
  • Long document support
  • Context compression

Usage

# Store with RAPTOR indexing response = await client.post( "/api/v1/digital/store", json={ "user_id": "user123", "content": "https://example.com/long-document.pdf", "content_type": "pdf" } ) # Query with tree traversal response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "Summarize the main findings", "response_options": { "rag_mode": "raptor", "tree_depth": 2 } } )

Pattern Selection Guide

ScenarioRecommended Pattern
Quick Q&ASimple RAG
Fact verificationCRAG
Abstract conceptsHyDE
Entity relationshipsGraph RAG
Improve recallRAG Fusion
High accuracy requiredSelf-RAG
Long documentsRAPTOR

Evaluation

All patterns support DeepEval quality metrics:

MetricDescriptionTarget
FaithfulnessGrounded in context> 0.8
RelevancyAnswers the question> 0.75
Context PrecisionRight chunks retrieved> 0.7
Context RecallAll info retrieved> 0.7
# Get evaluation metrics response = await client.post( "/api/v1/digital/response", json={ "user_id": "user123", "query": "Your question", "response_options": { "rag_mode": "simple", "include_evaluation": True } } ) # Response includes: # { # "response": "...", # "evaluation": { # "faithfulness": 0.85, # "relevancy": 0.82 # } # }

Hybrid GraphRAG with RRF Fusion

Combines graph-based retrieval (Neo4j) with vector similarity search (Qdrant) and merges results using Reciprocal Rank Fusion for higher recall than either source alone.

How It Works

Query ├──▶ Graph retrieval (Neo4j) → ranked results A ├──▶ Vector retrieval (Qdrant) → ranked results B Reciprocal Rank Fusion (k=60) Merged & re-ranked results → LLM → Response

RRF score formula: score = Σ 1/(k + rank_i) where k=60 is a smoothing constant. Results that appear highly ranked in both sources receive the highest fused score.

Usage

response = await client.post( "/api/v1/digital/search", json={ "user_id": "user123", "query": "How do agent checkpoints relate to session state?", "search_options": { "rag_mode": "hybrid_graph", "top_k": 10 } } )

When to Use

ScenarioRecommended pattern
Entity-relationship questionsHybrid GraphRAG
Semantic similarity onlySimple RAG or RAG Fusion
Graph traversal onlyGraph RAG
Best recall on complex questionsHybrid GraphRAG

Vector DB Backends

isA Data supports multiple vector database backends implementing the BaseVectorDB interface:

BackendVectorDBTypeBest for
Qdrant (default)QDRANTProduction, full-featured, hosted
MilvusMILVUSHigh-scale, distributed deployments

Milvus Backend

Configure Milvus via environment variables:

VECTOR_DB_TYPE=MILVUS MILVUS_HOST=localhost MILVUS_PORT=19530 MILVUS_COLLECTION=isa_docs # Collection name (default: isa_data)

The Milvus backend implements the same BaseVectorDB API — no code changes needed to switch from Qdrant:

# Works identically regardless of backend response = await client.post( "/api/v1/digital/store", json={"user_id": "user123", "content": "...", "content_type": "text"} )

Next Steps