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, useSmartRetriever with a Knowledge instance:
include_glob, exclude_glob, path_filter, or metadata_filters is set, SmartRetriever pulls max(fetch_k, top_k * 10) chunks from the store before filtering. A document that matches the filter is not dropped just because its unfiltered score sat below top_k.
Invalid filter regex raises ValueError
An invalid path_filter regex fails closed instead of quietly returning unfiltered data.
Multi-hop queries with SubQuestionEngine
SubQuestionEngine splits a question into sub-questions and retrieves context for each one with your SmartRetriever.
SubQuestionEngine accepts any retriever that returns either a list of chunks or a RetrievalResult with a .chunks attribute, so SmartRetriever and Knowledge-style retrievers are interchangeable.
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. Store errors are per-call: concurrent retrieve() calls on the same SmartRetriever cannot see each other’s error state.CLI Usage
Best Practices
Enable rerank for large corpora
Enable rerank for large corpora
Reranking adds latency but improves relevance once you have hundreds of chunks. Start with
rerank=True when answers feel noisy.Tune retrieval_k before reranking
Tune retrieval_k before reranking
Fetch more candidates (
retrieval_k=10–20) so the reranker has enough to choose from, then let the agent inject the top results.Use hybrid strategies at scale
Use hybrid strategies at scale
For technical docs with exact terms, rely on automatic strategy selection — hybrid and reranked modes combine keyword and semantic signals.
Scope by user or agent
Scope by user or agent
Pass
user_id or agent_id to SmartRetriever.retrieve() when isolating knowledge per tenant or sub-agent.Handle retrieval failure explicitly
Handle retrieval failure explicitly
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.Related
Retrieval Strategies
Automatic strategy selection by corpus size
Retrieval Configuration
Configure retrieval behaviour on agents

