> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    Q[Query] --> R[Retrieve]
    R --> S[Quality score]
    S --> F[Filter]
    F --> K[Rerank]
    K --> A[Answer]

    classDef query fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class Q query
    class R,S,F,K process
    class A output
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant QualityBasedRag

    User->>Agent: Request
    Agent->>QualityBasedRag: Process
    QualityBasedRag-->>Agent: Result
    Agent-->>User: Response
```

## Quick Start

**1. Simple Usage**

Enable reranking on the agent's knowledge base:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Feature as Quality-Based RAG

    User->>Agent: Request
    Agent->>Feature: Process request
    Feature-->>Agent: Result
    Agent-->>User: Response
```

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) |

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

> [accordion] Enable rerank for accuracy-critical tasks
>
> Reranking adds an LLM call — disable for high-throughput pipelines.

> [accordion] Set retrieval\_threshold for noisy corpora
>
> Raise `retrieval_threshold` to 0.6–0.7 when documents overlap heavily.

> [accordion] Combine with task quality\_check
>
> Use `Task(quality_check=True)` so only high-quality outputs enter long-term memory.

> [accordion] Weight metrics for your domain
>
> Pass custom `weights` to `compute_quality_score()` — weight accuracy higher for factual Q\&A.

***

## Related

> [card] [Quality Checking](https://praison.ai/docs/features/quality-checking.md)
>
> Automatic task output assessment

> [card] [Knowledge](https://praison.ai/docs/features/knowledge.md)
>
> Knowledge base setup and retrieval


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.