Skip to main content

Knowledge Bases

Knowledge bases: documents agents answer from.

Access it as client.knowledge on a Strongly client, or the same path on AsyncStrongly with await. All methods exist on both with identical signatures.

Quick start​

from strongly import Strongly

client = Strongly()

# List (auto-paginates as you iterate)
for knowledge in client.knowledge.list():
print(knowledge.id)

Methods​

Core​

list​

list(*, limit: int | None = None) -> SyncPaginator[KnowledgeBase]

List the knowledge bases you can use, by name.

Parameters

  • limit (int | None, optional): The most knowledge bases to return; None returns every one.

Returns

  • SyncPaginator[KnowledgeBase]: The knowledge bases (without their documents), fetched a page at a time.

create​

create(*, name: str, index_model_id: str, description: str | None = None) -> KnowledgeBase

Create a knowledge base.

Parameters

  • name (str): The knowledge base's name.
  • index_model_id (str): The AI Gateway chat model that writes each document's section summaries while it is indexed. Its usage is billed to whoever adds the document.
  • description (str | None, optional): What the documents cover; agents see it in their catalog.

Returns

  • KnowledgeBase: The new knowledge base.

retrieve​

retrieve(knowledge_base_id: str) -> KnowledgeBase

Retrieve a knowledge base with its documents.

Parameters

  • knowledge_base_id (str): The knowledge base's id.

Returns

  • KnowledgeBase: The knowledge base; each document carries its status, the reason it failed, and what indexing found.

Raises

  • NotFoundError: There is no such knowledge base, or you cannot use it.

update​

update(knowledge_base_id: str, *, name: str | None = None, description: str | None = None, index_model_id: str | None = None) -> KnowledgeBase

Rename a knowledge base, describe it, or change its indexing model.

A new indexing model applies to documents added from now on; re-index a document (reindex_document) to apply it to that document.

Parameters

  • knowledge_base_id (str): The knowledge base's id.
  • name (str | None, optional): The new name.
  • description (str | None, optional): The new description.
  • index_model_id (str | None, optional): The AI Gateway chat model that indexes documents.

Returns

  • KnowledgeBase: The knowledge base as it now is.

delete​

delete(knowledge_base_id: str) -> None

Delete a knowledge base, its documents and their stored data.

It is removed from every agent that reads it. Artifacts added to it are kept.

Parameters

  • knowledge_base_id (str): The knowledge base's id.

Other​

add_document​

add_document(knowledge_base_id: str, *, filename: str | None = None, content: str | None = None, file: str | Path | BinaryIO | None = None, content_type: str | None = None) -> KnowledgeDocument

Add a document to a knowledge base; it is indexed in the background.

Give either content (text, with a filename ending .md or .txt; Markdown headings become its sections) or file (a path or a binary file object). Takes .pdf .md .markdown .txt .html .htm .docx .csv .json.

Parameters

  • knowledge_base_id (str): The knowledge base's id.
  • filename (str | None, optional): The file name with its extension. Required with content; defaults to the file's own name with file.
  • content (str | None, optional): The document text.
  • file (str | Path | BinaryIO | None, optional): The file to upload, sent base64-encoded.
  • content_type (str | None, optional): The MIME type of file.

Returns

  • KnowledgeDocument: The document, status "pending"; retrieve shows when it is ready.

add_member​

add_member(resource_id: str, *, user_id: str, role: str) -> Permissions

Share the resource with a user.

Parameters

  • resource_id (str): The resource's id.
  • user_id (str): The user to share it with.
  • role (str): "editor" (use and change it) or "user" (use it only; types without a use-only tier, such as knowledge bases, take "editor" only).

agent_catalog​

agent_catalog(agent_id: str) -> dict[str, Any]

Return what an agent knows, as the agent sees it.

Parameters

  • agent_id (str): The agent's id.

Returns

  • dict[str, Any]: knowledge_bases: each knowledge base the agent reads (its _id, name and description), with every readable document's _id, title and summary (documents, keeping the API's keys) and those still being indexed or that failed (not_ready).

agent_outline​

agent_outline(agent_id: str, document_id: str) -> dict[str, Any]

Return a document's section tree, as the agent sees it.

Parameters

  • agent_id (str): The agent's id.
  • document_id (str): The document's id.

Returns

  • dict[str, Any]: document (with its _id) and outline: every section's id, title, summary and pages.
agent_search(agent_id: str, q: str) -> dict[str, Any]

Find the sections of an agent's documents that mention the query's words.

Keyword search across every knowledge base the agent reads, best match first.

Parameters

  • agent_id (str): The agent's id.
  • q (str): The words to look for.

Returns

  • dict[str, Any]: query and results, best first. Each result keeps the API's keys: its document (documentId), section (sectionId), the sections above it, its pages, score and knowledge base (knowledgeBaseId, knowledgeBaseName).

agent_section​

agent_section(agent_id: str, document_id: str, section_id: str) -> dict[str, Any]

Read one section of a document, as the agent reads it.

Parameters

  • agent_id (str): The agent's id.
  • document_id (str): The document's id.
  • section_id (str): The section's id, from the outline or a search result.

Returns

  • dict[str, Any]: The section's title, summary, pages, text and children (its sub-sections; a section with sub-sections holds little text of its own).

import_artifacts​

import_artifacts(knowledge_base_id: str, *, artifact_ids: Sequence[str]) -> list[KnowledgeDocument]

Add Library artifacts to a knowledge base as documents.

Each artifact is read where it is stored (not copied), re-indexed whenever it changes, and dropped from answers if the person who added it can no longer open it. Text, Markdown, HTML, PDF, Word, CSV and JSON artifacts can be indexed; images cannot.

Parameters

  • knowledge_base_id (str): The knowledge base's id.
  • artifact_ids (Sequence[str]): The artifacts to add.

Returns

  • list[KnowledgeDocument]: The documents added, one per artifact.

permissions​

permissions(resource_id: str) -> Permissions

Return who can reach the resource: its owner, members and their roles, and visibility.

Parameters

  • resource_id (str): The resource's id.

reindex_document​

reindex_document(knowledge_base_id: str, document_id: str) -> KnowledgeDocument

Index a document again (after a failure, or with the current indexing model).

Parameters

  • knowledge_base_id (str): The knowledge base's id.
  • document_id (str): The document's id.

Returns

  • KnowledgeDocument: The document, status "pending".

remove_document​

remove_document(knowledge_base_id: str, document_id: str) -> None

Remove a document and its stored index. An artifact removed this way is kept.

Parameters

  • knowledge_base_id (str): The knowledge base's id.
  • document_id (str): The document's id.

remove_member​

remove_member(resource_id: str, user_id: str) -> None

Stop sharing the resource with a user.

Parameters

  • resource_id (str): The resource's id.
  • user_id (str): The user to stop sharing it with.

set_visibility​

set_visibility(resource_id: str, visibility: str) -> Permissions

Make the resource public (every user can find and use it) or private.

Parameters

  • resource_id (str): The resource's id.
  • visibility (str): "public" or "private".

update_agent_knowledge_bases​

update_agent_knowledge_bases(agent_id: str, *, knowledge_base_ids: Sequence[str]) -> dict[str, Any]

Set the knowledge bases an agent answers from.

The list is complete: it replaces the agent's current one. Each knowledge base added must be one you can use. A running agent gets its knowledge tools when it restarts (redeploy it).

Parameters

  • agent_id (str): The agent's id.
  • knowledge_base_ids (Sequence[str]): Every knowledge base the agent should read; empty removes them all.

Returns

  • dict[str, Any]: The agent's whole config, as client.agents.config returns it.