- Query external APIs or databases directly
- Implement custom ranking or filtering
- Reformulate queries before searching
- Combine multiple data sources
How It Works
When the agent decides to search for information:- The agent calls your
knowledge_retrieverfunction with the query - Your function retrieves documents however you want
- Results are returned to the agent as a list of dictionaries
- The agent uses the retrieved content to generate a response
Retriever Function Signature
Example: Direct Vector Database Query
This example bypasses the Knowledge abstraction and queries Qdrant directly:custom_retriever.py
Example: Query Reformulation
Expand or modify queries before searching:Example: Multi-Source Retrieval
Combine results from multiple knowledge bases:When to Use Custom Retrievers
| Use Case | Why Custom Retriever |
|---|---|
| Direct database access | Skip the Knowledge abstraction for performance |
| Query expansion | Add synonyms or related terms before searching |
| Multi-source search | Combine results from multiple knowledge bases |
| External APIs | Search third-party services (Elasticsearch, Algolia, etc.) |
| Custom ranking | Implement domain-specific relevance scoring |
| Conditional logic | Apply different search strategies based on query type |