Knowledge Base
Upload documents to build knowledge bases for RAG evaluation and context injection. Create, update, and manage files.
📝
TL;DR
from fi.kb import KnowledgeBase(part offutureagi)- Upload PDFs, DOCX, TXT, or RTF files to build a knowledge base
- Use with dataset evaluations for RAG context
Knowledge bases are document collections you upload to Future AGI. Use them as context sources for RAG evaluations or to power retrieval in your AI applications. For a full guide on concepts and platform usage, see the Knowledge Base docs.
Note
Requires pip install futureagi (or comes with ai-evaluation) and FI_API_KEY + FI_SECRET_KEY in your environment. Supported file types: PDF, DOCX, TXT, RTF.
Quick Example
from fi.kb import KnowledgeBase
kb = KnowledgeBase()
# Create a knowledge base with files
kb.create_kb(
name="product-docs",
file_paths=["docs/guide.pdf", "docs/faq.txt"],
)
# Add more files later
kb.update_kb(
kb_name="product-docs",
file_paths=["docs/changelog.txt"],
)
Creating a Knowledge Base
from fi.kb import KnowledgeBase
kb = KnowledgeBase()
# From individual files
kb.create_kb(name="my-kb", file_paths=["file1.pdf", "file2.txt"])
# From a directory
kb.create_kb(name="my-kb", file_paths="/path/to/docs/")
# Empty (add files later)
kb.create_kb(name="my-kb")
Loading an Existing KB
kb = KnowledgeBase(kb_name="product-docs")
# The SDK fetches the KB config from the server
Updating
Add files or rename a knowledge base.
# Add files
kb.update_kb(kb_name="product-docs", file_paths=["new-doc.pdf"])
# Rename
kb.update_kb(kb_name="product-docs", new_name="product-docs-v2")
# Both at once
kb.update_kb(kb_name="product-docs", new_name="v2", file_paths=["extra.txt"])
Deleting Files
Remove specific files from a knowledge base.
kb.delete_files_from_kb(
file_names=["old-doc.pdf", "deprecated.txt"],
kb_name="product-docs",
)
Deleting a Knowledge Base
# By name
kb.delete_kb(kb_names="product-docs")
# By ID
kb.delete_kb(kb_ids="abc-123-def")
# Multiple
kb.delete_kb(kb_names=["kb-1", "kb-2"])
Method Reference
| Method | What it does | Returns |
|---|---|---|
create_kb(name, file_paths) | Create a new KB, optionally upload files. file_paths accepts a single path (str), a list of paths, or a directory path. | self |
update_kb(kb_name, new_name, file_paths) | Rename and/or add files | self |
delete_files_from_kb(file_names, kb_name) | Remove specific files | self |
delete_kb(kb_ids, kb_names) | Delete one or more KBs | self |
All methods return self for chaining.
Related
Was this page helpful?