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.
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.
| Time | Difficulty | Package |
|---|---|---|
| 15 minutes | Beginner | futureagi |
- Future AGI account → app.futureagi.com
- API keys:
FI_API_KEYandFI_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.com → Knowledge base (left sidebar) → Create Knowledge Base.
- Enter a name:
product-docs - In the Upload tab, upload your documents (PDF, TXT, DOCX, or RTF)
- 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-docsNote
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, rtfConvert 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.
- Go to app.futureagi.com → Dataset → open your dataset
- Click Evaluate → Add Evaluations → select an eval metric (e.g.
completeness) - In the evaluation configuration, find the Knowledge base dropdown
- Select your KB (e.g.
product-docs) - 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
| Symptom | Cause | Fix |
|---|---|---|
create_kb() raises an unsupported file type error | File extension isn’t pdf, docx, txt, or rtf | Convert the document to a supported format before uploading |
| Knowledge base dropdown is empty | No Knowledge Base has finished processing in this organization | Create one and wait for processing to complete |
update_kb() or delete_files_from_kb() resolves the wrong KB | No Knowledge Base name contains that string, or the lookup matched a different one | kb_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 disabled | Uploaded documents are still processing | Wait until every file shows a processed status in the KB detail view, then retry |
| SDK calls fail with an authentication error | FI_API_KEY or FI_SECRET_KEY isn’t exported in the shell running the script | Re-export both env vars in the same terminal session before running |
delete_files_from_kb() raises an invalid-files error | A 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 upload | The file is over the 5 MB per-file limit, or the KB has hit the 1 GB total storage limit | Split or compress the document, or delete unused files first |
Manage datasets and attach evaluations end to end in Running Your First Eval.
Questions & Discussion