Quality-Based RAG

Score, filter, and rerank retrieved content for higher-quality answers

Retrieve with quality scoring — filter low-quality chunks and rerank before the agent answers.

python
from praisonaiagents import Agent, KnowledgeConfig

agent = Agent(
    name="Quality RAG",
    instructions="Answer from documents. Prefer high-quality sources.",
    knowledge=KnowledgeConfig(
        sources=["docs/"],
        rerank=True,
        retrieval_k=5,
        retrieval_threshold=0.7,
    ),
)

agent.start("What are the key product features?")

The user asks a question; retrieval scores and filters chunks before the agent answers from high-quality sources.

Diagram

Query

Retrieve

Quality score

Filter

Rerank

Answer

How It Works

Diagram
QualityBasedRagAgentUserQualityBasedRagAgentUserRequestProcessResultResponse

Quick Start

  1. Simple Usage

    Enable reranking on the agent’s knowledge base:

    python
    from praisonaiagents import Agent, KnowledgeConfig
    
    agent = Agent(
        name="RAG Agent",
        instructions="Answer from the knowledge base.",
        knowledge=KnowledgeConfig(sources=["docs/"], rerank=True),
    )
    
    agent.start("Summarise the onboarding guide")
  2. With Configuration

    Filter memory search by quality score:

    python
    from praisonaiagents import Agent, Memory
    
    agent = Agent(
        name="Memory RAG",
        instructions="Use only high-quality past outputs.",
        memory=Memory(),
    )
    
    results = agent.memory.search_short_term(
        "previous research on AI",
        min_quality=0.7,
        rerank=True,
        limit=5,
    )

How It Works

Diagram
Quality-Based RAGAgentUserQuality-Based RAGAgentUserRequestProcess requestResultResponse

Quality spans retrieval and memory:

LayerMechanism
KnowledgeKnowledgeConfig(rerank=True) reranks chunks before injection
Memory searchmin_quality filters by stored quality metadata
Memory storecompute_quality_score() combines completeness, relevance, clarity, accuracy
Task outputquality_check=True on tasks stores high-scoring outputs (threshold 0.7)
python
score = memory.compute_quality_score(
    completeness=0.9,
    relevance=0.85,
    clarity=0.8,
    accuracy=0.9,
)

Configuration Options

KnowledgeConfig (retrieval)

OptionTypeDefaultDescription
rerankboolFalseRerank retrieved chunks
rerank_modelstrNoneModel for reranking
retrieval_kint5Chunks to retrieve
retrieval_thresholdfloat0.0Minimum similarity score

Memory search

ParameterTypeDefaultDescription
min_qualityfloat0.0Minimum quality metadata
rerankboolFalseRerank search results
relevance_cutofffloat0.0Minimum relevance score

Best Practices

Enable rerank for accuracy-critical tasks

Reranking adds an LLM call — disable for high-throughput pipelines.

Set retrieval_threshold for noisy corpora

Raise retrieval_threshold to 0.6–0.7 when documents overlap heavily.

Combine with task quality_check

Use Task(quality_check=True) so only high-quality outputs enter long-term memory.

Weight metrics for your domain

Pass custom weights to compute_quality_score() — weight accuracy higher for factual Q&A.


Related