Create a Knowledge Base using SDK

Create and manage Knowledge Bases programmatically with the Future AGI Python SDK: create, update, add or remove files, and delete KBs from code or automation.

What it is

The Knowledge Base (SDK) flow lets you create and manage Knowledge Bases from code using the Future AGI Python SDK. You install the futureagi package, authenticate with API credentials, then call methods to create a KB with a name and file paths (or a directory), add more files to an existing KB, remove files by name, or delete entire KBs. Supported file types are PDF, DOCX, TXT, and RTF. The SDK provides extended support for large volumes of files and complex automation workflows, including CI/CD pipelines.

Use cases

  • Automation — Create or update KBs from scripts, pipelines, or scheduled jobs.
  • Bulk ingestion — Upload many files or point at a directory path instead of selecting files one by one in the UI.
  • Larger files — Use the SDK when file size or volume exceeds UI limits.
  • Reproducibility — Version and replay KB setup in code (e.g. in a repo or notebook).
  • Integrations — Embed KB creation/updates in your own tools or workflows.

How to

Install the SDK

Install the Future AGI Python package:

pip install futureagi

Authenticate

Create a KnowledgeBase client with your API key and secret (from the Future AGI platform). Optionally pass fi_base_url for a custom API base.

from fi.kb import KnowledgeBase

client = KnowledgeBase(
    fi_api_key="YOUR_API_KEY",
    fi_secret_key="YOUR_SECRET_KEY"
)

Create a Knowledge Base

Call create_kb with a name and either a list of file paths or a single directory path. The SDK uploads the files and returns the same client with the new KB cached in client.kb (id, name, files). Supported extensions: pdf, docx, txt, rtf.

client = client.create_kb(
    name="my-knowledge-base",
    file_paths=["path/to/file1.pdf", "path/to/file2.txt"]
)
print(f"Created KB: {client.kb.id}{client.kb.name}")

To use all files in a directory:

client = client.create_kb(
    name="my-knowledge-base",
    file_paths="path/to/docs_folder"
)

Update a Knowledge Base (optional)

To add files or rename an existing KB, use update_kb. The first argument is the KB name (the SDK resolves it to the existing KB). You can pass new_name to rename and/or file_paths to add more files.

client.update_kb(
    kb_name="my-knowledge-base",
    file_paths=["path/to/extra_file.pdf"]
)
# Or rename and add files:
client.update_kb(
    kb_name="my-knowledge-base",
    new_name="my-renamed-kb",
    file_paths=["path/to/extra_file.pdf"]
)

Delete files from a Knowledge Base (optional)

To remove specific documents, call delete_files_from_kb with the file names (as stored in the KB), not file IDs. You can pass kb_name if the client is not already targeting that KB.

client.delete_files_from_kb(
    file_names=["file1.pdf", "file2.txt"],
    kb_name="my-knowledge-base"  # optional if client already has this KB
)

Delete a Knowledge Base (optional)

To delete one or more KBs, use delete_kb with either kb_ids or kb_names. The client can target the current cached KB if you don’t pass either.

client.delete_kb(kb_ids=[str(client.kb.id)])
# Or by name:
client.delete_kb(kb_names=["my-knowledge-base"])

Note

Wrap SDK calls in try/except and handle fi.utils.errors.SDKException (and optionally InvalidAuthError, rate limits) in production. Keep API credentials out of version control (e.g. use environment variables).

What you can do next

Was this page helpful?

Questions & Discussion