Skip to main content
Search a knowledge base directly or give an agent a tool that searches it.

How Search Works

Knowledge.search() passes the query, result limit, and filters to the configured vector database. The database returns Document objects in its ranked order. Install the PgVector example dependencies and run PostgreSQL with pgvector enabled:

Search Types

Search algorithms differ by vector database. Evaluate each supported search type with representative queries and expected documents.

Direct and Agentic Retrieval

Pass knowledge to an agent to register the search_knowledge_base tool. search_knowledge=True is the default.
The model controls when and how often it calls search_knowledge_base. Set add_knowledge_to_context=True to retrieve knowledge for each string input and add the results to the model context.

Filtering Results

Filter searches by metadata:
For OR, NOT, and comparison operators, see Filtering.

Custom Retrieval Logic

Set knowledge_retriever to replace the default Knowledge.retrieve() path:
See Custom Retriever for accepted parameters and examples.

Retrieval Decisions

Test Retrieval

Compare results with a set of queries and expected documents:

Next Steps

Hybrid Search

Configure vector and lexical retrieval signals

Filtering

Apply metadata filters to knowledge searches

Vector DB

Compare storage and search integrations

Performance Tips

Tune ingestion and retrieval settings