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.
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.
How It Works
Quick Start
- 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") - 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
Quality spans retrieval and memory:
| Layer | Mechanism |
|---|---|
| Knowledge | KnowledgeConfig(rerank=True) reranks chunks before injection |
| Memory search | min_quality filters by stored quality metadata |
| Memory store | compute_quality_score() combines completeness, relevance, clarity, accuracy |
| Task output | quality_check=True on tasks stores high-scoring outputs (threshold 0.7) |
score = memory.compute_quality_score(
completeness=0.9,
relevance=0.85,
clarity=0.8,
accuracy=0.9,
)Configuration Options
KnowledgeConfig (retrieval)
| Option | Type | Default | Description |
|---|---|---|---|
rerank | bool | False | Rerank retrieved chunks |
rerank_model | str | None | Model for reranking |
retrieval_k | int | 5 | Chunks to retrieve |
retrieval_threshold | float | 0.0 | Minimum similarity score |
Memory search
| Parameter | Type | Default | Description |
|---|---|---|---|
min_quality | float | 0.0 | Minimum quality metadata |
rerank | bool | False | Rerank search results |
relevance_cutoff | float | 0.0 | Minimum 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.