Knowledge Base: Upload and Manage Documents with the SDK

Upload documents to a Knowledge Base via dashboard or SDK, and use them for domain-grounded evaluations and synthetic data generation.

📝
TL;DR

Upload documents to a Knowledge Base via the dashboard or SDK, manage files programmatically, and use the Knowledge Base for domain-grounded evaluations and synthetic data generation.

TimeDifficultyPackage
15 minutesBeginnerfutureagi
Prerequisites
  • Future AGI account → app.futureagi.com
  • API keys: FI_API_KEY and FI_SECRET_KEY (see Get your API keys)
  • Python 3.11+
  • Documents to index (PDF, TXT, DOCX, or RTF), up to 5 MB each

Install

pip install futureagi
export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"

Tutorial

Create a Knowledge Base from the dashboard

Go to app.futureagi.comKnowledge base (left sidebar) → Create Knowledge Base.

  1. Enter a name: product-docs
  2. In the Upload tab, upload your documents (PDF, TXT, DOCX, or RTF)
  3. Click Create

product-docs appears in the Knowledge base list with your files processing.

View your Knowledge Base

Click on product-docs in the Knowledge Base list. Inside, you can see:

  • All uploaded files with their file size and processing status
  • Add docs: upload additional documents
  • Create Synthetic data: generate a synthetic dataset grounded in this KB (available once processing completes)

Note

The Create Synthetic data button opens the same synthetic data wizard covered in the Synthetic Data Generation cookbook, with your KB pre-selected.

Create a Knowledge Base via SDK

Create and manage a KB programmatically instead of through the dashboard:

import os
from fi.kb import KnowledgeBase

kb_client = KnowledgeBase(
    fi_api_key=os.environ["FI_API_KEY"],
    fi_secret_key=os.environ["FI_SECRET_KEY"],
)

kb_client.create_kb(
    name="product-docs",
    file_paths=[
        "./docs/return-policy.txt",
        "./docs/shipping-info.txt",
        "./docs/product-catalog.pdf",
    ],
)

print(f"KB created: {kb_client.kb.name}")

You should see:

KB created: product-docs

Note

Supported file types: pdf, docx, txt, rtf

An unsupported file type fails the call instead of silently skipping it:

kb_client.create_kb(
    name="product-docs",
    file_paths=["./docs/changelog.md"],
)

You should see:

UnsupportedFileType: File type '.md' is not supported. Supported types: pdf, docx, txt, rtf

Convert the file and retry:

kb_client.create_kb(
    name="product-docs",
    file_paths=["./docs/changelog.txt"],
)

print(f"KB created: {kb_client.kb.name}")

You should see:

KB created: product-docs

Add documents to an existing KB

When your content changes, add files without recreating the KB:

kb_client.update_kb(
    kb_name="product-docs",
    file_paths=["./docs/warranty-policy.txt"],
)

print("New document added to product-docs.")

You should see:

New document added to product-docs.

Rename the KB in the same call:

kb_client.update_kb(
    kb_name="product-docs",
    new_name="product-docs-v2",
    file_paths=["./docs/new-policy.txt"],
)

You should see: the KB now listed as product-docs-v2.

Delete files or an entire KB

Remove specific files from a KB:

kb_client.delete_files_from_kb(
    file_names=["return-policy.txt"],
    kb_name="product-docs",
)

print("File removed from KB.")

You should see:

File removed from KB.

Delete the entire KB:

kb_client.delete_kb(kb_names="product-docs")

print("KB deleted.")

You should see:

KB deleted.

Use the Knowledge Base in evaluations

Attach the Knowledge Base to a dataset evaluation so the evaluator grounds its scoring in your domain documents.

  1. Go to app.futureagi.comDataset → open your dataset
  2. Click EvaluateAdd Evaluations → select an eval metric (e.g. completeness)
  3. In the evaluation configuration, find the Knowledge base dropdown
  4. Select your KB (e.g. product-docs)
  5. Map the remaining keys and click Add & Run

The eval column fills in with scores and reasons grounded in your KB documents.

Tip

The Knowledge base dropdown appears for Future AGI built-in evaluation metrics and provides domain-specific context so the evaluator scores outputs against your documents rather than general knowledge.

Troubleshooting

SymptomCauseFix
create_kb() raises an unsupported file type errorFile extension isn’t pdf, docx, txt, or rtfConvert the document to a supported format before uploading
Knowledge base dropdown is emptyNo Knowledge Base has finished processing in this organizationCreate one and wait for processing to complete
update_kb() or delete_files_from_kb() resolves the wrong KBNo Knowledge Base name contains that string, or the lookup matched a different onekb_name is a case-insensitive substring search that returns the first match; pass the full name as shown in the dashboard
Create Synthetic data button stays disabledUploaded documents are still processingWait until every file shows a processed status in the KB detail view, then retry
SDK calls fail with an authentication errorFI_API_KEY or FI_SECRET_KEY isn’t exported in the shell running the scriptRe-export both env vars in the same terminal session before running
delete_files_from_kb() raises an invalid-files errorA name in file_names doesn’t exactly match a file in the KB (match is exact, including extension and case)Copy the file name from the KB detail view
A file shows an error status after uploadThe file is over the 5 MB per-file limit, or the KB has hit the 1 GB total storage limitSplit or compress the document, or delete unused files first

Manage datasets and attach evaluations end to end in Running Your First Eval.

Was this page helpful?

Questions & Discussion