Manage with the SDK

Create, update, and delete a knowledge base from Python

The platform’s upload dropzone caps a single file at 5 MB, which is small next to a real policy manual or a scanned contract. Reach for the SDK when:

  • A file is bigger than 5 MB
  • You want to point at a whole directory instead of picking files one by one
  • A knowledge base is something your own pipeline builds and refreshes on a schedule

If you’re creating a knowledge base from the UI and want a starting point, its create drawer has an Import from SDK tab that hands you a ready-made Python snippet for creating one; see Create a knowledge base for that flow.

Install the SDK

pip install futureagi

Set your credentials

The client reads your API key and secret from the environment. Get FI_API_KEY and FI_SECRET_KEY from Settings > API Keys (see API Keys), then set them before you run your script:

export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"

Initialize the client

from fi.kb import KnowledgeBase

kb = KnowledgeBase()

Create a knowledge base

Call create_kb with a name and file_paths. Pass a list of paths to upload specific files:

kb.create_kb(
    name="FAQ knowledge base",
    file_paths=["docs/refund-policy.pdf", "docs/shipping-policy.txt"],
)
print("Created FAQ knowledge base")

Or pass a directory path to upload everything in it:

kb.create_kb(
    name="FAQ knowledge base",
    file_paths="docs/support_policies/",
)

create_kb returns the client itself (self), so calls can be chained. If the call returns without raising an exception, the knowledge base was created.

These rules apply whichever path you use above, since they’re enforced on the server, not by the dropzone:

  • Only PDF, DOCX, TXT, and RTF files are indexed
  • A knowledge base holds up to 1 GB total
  • The name has to be unique in your organization
  • A single call can’t upload two files with the same name

create_kb fails on any of the above. Fix the file, rename, or split the upload, then re-run.

Add a file

update_kb adds files to an existing knowledge base. Pass the knowledge base’s name and the new file_paths:

kb.update_kb(
    kb_name="FAQ knowledge base",
    file_paths=["docs/warranty-policy.pdf"],
)

Remove a file by name

delete_files_from_kb removes specific files. It takes the file names as they’re stored in the knowledge base, not file IDs: that’s the file’s base name, not its local path. The create_kb call above uploads docs/shipping-policy.txt, and it’s removed here by its base name, shipping-policy.txt:

kb.delete_files_from_kb(
    file_names=["shipping-policy.txt"],
    kb_name="FAQ knowledge base",
)

Delete the knowledge base

delete_kb removes one or more knowledge bases at once, by name or by ID:

kb.delete_kb(kb_names="FAQ knowledge base")

For the by-ID form and its full parameters, see the Knowledge Base SDK reference.

Dive deeper

Was this page helpful?

Questions & Discussion