Knowledge Bases Client

The KnowledgeBasesClient manages knowledge bases — collections of documents, sources, and configurations that agents query for context-aware responses.
zaby.knowledge_bases  # → KnowledgeBasesClient

Create

name
string
required
Display name
slug
string
required
Unique URL-friendly identifier
description
string
Human-readable description
kb = await zaby.knowledge_bases.create({
    "name": "Product Docs",
    "slug": "product-docs",
    "description": "Company product documentation",
})

Documents

Upload text document

doc = await zaby.knowledge_bases.upload_text_document(kb_id, {
    "text": "Refunds are processed within 5-7 business days.",
    "metadata": {"category": "billing"},
})

Library documents

# Create a library text document
lib_doc = await zaby.knowledge_bases.create_library_text_document({
    "name": "Company FAQ",
    "text": "Full FAQ content here...",
})

# List library documents
docs = await zaby.knowledge_bases.list_library_documents({
    "limit": 50,
})

# List findings for a library document
findings = await zaby.knowledge_bases.list_library_document_findings(
    doc_id, {"category": "billing"}
)

# Link a library document to a knowledge base
await zaby.knowledge_bases.link_library_document(kb_id, {
    "libraryDocumentId": lib_doc["id"],
})

# Project library document sections into a KB
await zaby.knowledge_bases.project_library_document(kb_id, selection_id, {
    "projection": {...},
})

Retrieval

Query the knowledge base for relevant context:
results = await zaby.knowledge_bases.retrieve(kb_id, {
    "query": "What is the refund policy?",
    "limit": 5,
})

Provisional answer

Generate an answer using the KB as context:
answer = await zaby.knowledge_bases.provisional_answer(kb_id, {
    "query": "What is the refund policy?",
})

Source groups

Organize sources into logical groups.
groups = await zaby.knowledge_bases.list_source_groups(kb_id, {
    "limit": 50,
})
group = await zaby.knowledge_bases.create_source_group(kb_id, {
    "name": "Billing Docs",
})
await zaby.knowledge_bases.update_source_group(kb_id, sg_id, {
    "name": "Updated Name",
})

Sources

Sources are the raw data feeds ingested into a knowledge base.
sources = await zaby.knowledge_bases.list_sources(kb_id, {
    "status": "ACTIVE",
})
source = await zaby.knowledge_bases.create_source(kb_id, {
    "name": "Website Crawl",
    "type": "web_crawl",
    "config": {"url": "https://example.com/docs"},
})
await zaby.knowledge_bases.update_source(kb_id, source_id, {
    "config": {"url": "https://new-url.com/docs"},
})
await zaby.knowledge_bases.reprocess_source(kb_id, source_id)

Ingestion policies

Control how sources are ingested and processed.
policies = await zaby.knowledge_bases.list_ingestion_policies(kb_id)
policy = await zaby.knowledge_bases.create_ingestion_policy(kb_id, {
    "name": "Daily Crawl",
    "schedule": "0 6 * * *",
    "sourceId": source_id,
})
await zaby.knowledge_bases.update_ingestion_policy(kb_id, policy_id, {
    "schedule": "0 12 * * *",
})

Governance policy

await zaby.knowledge_bases.upsert_governance_policy(kb_id, {
    "rules": [...],
})

Profiles

profiles = await zaby.knowledge_bases.list_profiles(kb_id)
profile = await zaby.knowledge_bases.create_profile(kb_id, {
    "name": "Default",
    "config": {"maxChunks": 10},
})
await zaby.knowledge_bases.update_profile(kb_id, profile_id, {
    "config": {"maxChunks": 20},
})

Jobs

Monitor and manage ingestion jobs.
jobs = await zaby.knowledge_bases.list_jobs(kb_id, {
    "status": "RUNNING",
})
job = await zaby.knowledge_bases.get_job(kb_id, job_id)
await zaby.knowledge_bases.cancel_job(kb_id, job_id)

Agent attachment

await zaby.agents.attach_knowledge_base(agent_id, {
    "knowledgeBaseId": kb_id,
})

Example

import asyncio
from zaby import Zaby

async def main():
    zaby = Zaby(api_key="zaby_pk_...")

    kb = await zaby.knowledge_bases.create({
        "name": "Customer FAQ",
        "slug": "customer-faq",
    })

    await zaby.knowledge_bases.upload_text_document(kb["id"], {
        "text": "Refunds are processed within 5-7 business days.",
        "metadata": {"category": "billing"},
    })

    results = await zaby.knowledge_bases.retrieve(kb["id"], {
        "query": "How long do refunds take?",
    })

    print(f"Found {len(results)} relevant results")
    await zaby.agents.attach_knowledge_base(agent_id, {
        "knowledgeBaseId": kb["id"],
    })

asyncio.run(main())