Quick Start
kb.query()
Search the knowledge base for relevant content.Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | Required | Search query string |
top_k | int | 5 | Number of results to return |
retrieval_type | str | "basic" | Retrieval method |
score_threshold | float | 0.0 | Minimum relevance score (0.0-1.0) |
lambda_param | float | None | Hybrid search parameter (0=keyword, 1=semantic) |
time_decay_factor | float | None | Time decay for time_aware retrieval |
Example
Retrieval Types
basic
Standard vector similarity search. Default and fastest option.mmr (Maximal Marginal Relevance)
Returns diverse results by reducing redundancy. Useful when you want varied perspectives.hyde (Hypothetical Document Embeddings)
Generates a hypothetical answer first, then searches for similar content. Better for question-style queries.time_aware
Weights results by recency. Useful for content where freshness matters.QueryResult Object
Each result is aQueryResult with these properties:
| Property | Type | Description |
|---|---|---|
text | str | Retrieved text chunk |
score | float | Relevance score (0.0-1.0) |
source | str | Source document name |
metadata | dict | Additional metadata |
id | str | Document/chunk ID |
page | int | Page number (for PDFs) |
chunk_index | int | Chunk index in document |
Working with Results
Using with Agents
Pass knowledge bases toagent.run() for RAG-powered responses.
Basic Usage
Multiple Knowledge Bases
Custom Runtime Configuration
Usewith_config() to customize retrieval settings per-call:
kb.with_config()
Create a runtime configuration for custom retrieval settings.Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
top_k | int | 10 | Number of results to retrieve |
retrieval_type | str | "basic" | Retrieval method |
score_threshold | float | 0.0 | Minimum relevance score |
time_decay_factor | float | 0.4 | Time decay factor |