Skip to main content
Give agents sharper answers from large knowledge bases by combining keyword matching, semantic search, and reranking.
The user asks a question; hybrid retrieval and reranking surface the best knowledge snippets.

How It Works

Quick Start

1

Simple Usage

Enable reranking on the agent’s knowledge config:
2

With Configuration

Use KnowledgeConfig for chunking, vector store, and rerank model:

How It Works

Strategy selection scales with corpus size — see Retrieval Strategies.

Advanced: SmartRetriever

For direct control over retrieval strategy and filters, use SmartRetriever with a Knowledge instance:

Detect Retrieval Failures

An empty result can mean two very different things: the store is healthy but nothing matched, or the store is unreachable and the agent is about to answer from memory alone.
RetrievalResult carries two fields that make the difference visible: chunks stays [] on failure, so nothing downstream breaks — these two fields are the only way to tell “nothing matched” from “the store is down”.
The retriever logs at ERROR on praisonaiagents.rag.retriever the first time a store call fails, so operators see it in application logs even when the caller only reads chunks. A later successful call clears the previous error.

CLI Usage


Best Practices

Reranking adds latency but improves relevance once you have hundreds of chunks. Start with rerank=True when answers feel noisy.
Fetch more candidates (retrieval_k=10–20) so the reranker has enough to choose from, then let the agent inject the top results.
For technical docs with exact terms, rely on automatic strategy selection — hybrid and reranked modes combine keyword and semantic signals.
Pass user_id or agent_id to SmartRetriever.retrieve() when isolating knowledge per tenant or sub-agent.
Check result.retrieval_failed before answering. When it’s True, tell the user the answer is not grounded in the knowledge base — or refuse — because a confidently wrong answer with no signal is exactly the failure this guards against.

Retrieval Strategies

Automatic strategy selection by corpus size

Retrieval Configuration

Configure retrieval behaviour on agents