Knowledge Base: Upload Documents and Query with the SDK

Upload documents to a Knowledge Base, manage files programmatically with the SDK, and use Knowledge Bases for grounded evaluations and synthetic data generation.

📝
TL;DR

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

TimeDifficultyPackage
15 minBeginnerfutureagi
Prerequisites

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

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. Follow those steps to generate a KB-grounded dataset.

Create a Knowledge Base via SDK

You can also create and manage a KB programmatically:

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}")

Expected output:

KB created: product-docs

Note

Supported file types: pdf, docx, txt, rtf.

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 can also rename the KB at the same time:

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

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.")

Delete the entire KB:

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

print("KB deleted.")

Use the Knowledge Base in evaluations

When running evaluations on a dataset, you can attach your Knowledge Base so the evaluator uses your domain documents as grounding context.

  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) — this allows the evaluator to leverage your domain-specific documents when scoring
  5. Map the remaining keys and click Add & Run

Tip

The Knowledge Base dropdown appears for FutureAGI built-in evaluation metrics. It provides domain-specific context to the evaluator so it can score outputs against your actual documentation rather than general knowledge.

Note: Knowledge Base is only supported with the turing_large evaluator model. The turing_small and turing_flash models do not support attaching a KB.

Generate synthetic data from your KB

You can generate a synthetic dataset grounded in your KB documents — either from the KB detail view or from the synthetic data wizard.

From the KB detail view:

  1. Go to Knowledge base → click on your KB → click Create Synthetic data (top action bar)
  2. The synthetic data wizard opens with your KB pre-selected

From the synthetic data wizard:

  1. Go to DatasetAdd DatasetCreate Synthetic Data
  2. In the Add details step, select your KB from the Select knowledge base dropdown

Both paths lead to the same synthetic data generation pipeline. Follow the full walkthrough in Generate a Synthetic Dataset.

What you built

You can now create and manage Knowledge Bases, attach them to evaluations for domain-grounded scoring, and generate synthetic data from your documents.

  • Created a Knowledge Base from the dashboard and via the SDK
  • Viewed uploaded files and processing status in the KB detail view
  • Added, removed, and renamed documents with update_kb() and delete_files_from_kb()
  • Attached the KB to evaluations for domain-grounded scoring
  • Generated synthetic data grounded in your KB documents

Next steps

Was this page helpful?

Questions & Discussion