Skip to main content
Custom retrievers let you implement your own search logic instead of using the default knowledge search. This is useful when you need to:
  • 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:
  1. The agent calls your knowledge_retriever function with the query
  2. Your function retrieves documents however you want
  3. Results are returned to the agent as a list of dictionaries
  4. 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

For most use cases, the built-in Knowledge search is sufficient. Use custom retrievers when you need full control over the retrieval process.

Next Steps

Search & Retrieval

Learn about built-in search options

Filtering

Filter results by metadata