Knowledge Base Tools¶
Tools for managing the knowledge base.
Search¶
kb_search¶
Search the knowledge base.
kb_search(
ctx: RunContext[None],
query: str,
collection_name: Optional[str] = None,
num_docs: int = 5
) -> str
Example:
Returns relevant document excerpts with:
- Document name
- Page number (if applicable)
- Relevance score
- Content excerpt
Add Sources¶
kb_add_source¶
Add web page or text to knowledge base.
kb_add_source(
ctx: RunContext[None],
source_type: str, # "url" or "text"
source: str, # URL or text content
collection_name: str = "datasus",
description: Optional[str] = None
) -> str
For URLs:
For text:
kb_add_document¶
Upload PDF document.
Example:
List Sources¶
kb_list_sources¶
List available sources.
Example:
kb_list_collections¶
List collections.
Example:
Status¶
kb_status¶
Check knowledge base status.
Example:
Collections¶
| Collection | Purpose |
|---|---|
datasus |
Official DATASUS documentation |
epidemiology |
Epidemiological methods |
methodology |
Research methodology |
Duplicate Detection¶
The system automatically checks for duplicates before adding:
- URLs are checked by domain + path
- Text documents by name
- Chunked documents are recognized
Example response:
Source already exists in knowledge base: 'portalsinan.saude.gov.br_o-sinan'
(collection: datasus). Skipping duplicate.
Chunking¶
Large documents are automatically split:
- Maximum chunk size: 1024 characters
- Overlap: 100 characters
- Paragraph boundaries preserved
Example response:
Best Practices¶
- Use appropriate collections: Organize by topic
- Verify before adding: Check if source exists
- Add quality sources: Official documentation works best
- Search first: Query before adding to avoid duplicates