KnowledgeBases Class

The KnowledgeBases class manages the collection of knowledge bases, their creation, listing, and retrieval.

Constructor

KnowledgeBases(configuration: Optional[Configuration] = None)
Parameters:
  • configuration (Optional[Configuration]): SDK configuration. Uses environment variables if not provided.

Methods

acreate(name: str, description: Optional[str] = None)

Asynchronously create a new knowledge base.
async def acreate(name: str, description: Optional[str] = None) -> KnowledgeBase
Parameters:
  • name (str): Name of the knowledge base.
  • description (Optional[str]): Optional description.
Returns: Created KnowledgeBase object.

create(name: str, description: Optional[str] = None)

Synchronously create a new knowledge base.
def create(name: str, description: Optional[str] = None) -> KnowledgeBase
Parameters: Same as acreate(). Returns: Created KnowledgeBase object.

alist()

Asynchronously list all available knowledge bases.
async def alist() -> List[KnowledgeBase]
Returns: List of KnowledgeBase objects.

list()

Synchronously list all available knowledge bases.
def list() -> List[KnowledgeBase]
Returns: List of KnowledgeBase objects.

KnowledgeBase

Represents a single knowledge base with document management and search capabilities.

Properties

  • id (str): Unique identifier for the knowledge base.
  • name (str): Name of the knowledge base.
  • type (str): Type of the knowledge base.
  • organization_id (str): ID of the organization owning it.

Methods

Document Management

aadd_documents(document_urls: List[str], sync: Optional[bool] = False)
Asynchronously add new documents to the knowledge base.
async def aadd_documents(document_urls: List[str], sync: Optional[bool] = False) -> List[KnowledgeBaseDocumentItem]
Parameters:
  • document_urls (List[str]): URLs of documents to add.
  • sync (Optional[bool]): Whether to sync the documents.
Returns: List of KnowledgeBaseDocumentItem objects.
add_documents(document_urls: List[str], sync: Optional[bool] = False)
Synchronously add new documents.
def add_documents(document_urls: List[str], sync: Optional[bool] = False) -> List[KnowledgeBaseDocumentItem]
Parameters: Same as aadd_documents(). Returns: List of KnowledgeBaseDocumentItem objects.

Search Operations

asearch(query: str)

Asynchronously perform search operations.
async def asearch(query: str) -> List[KnowledgeBaseSearchResult]
Parameters:
  • query (str): Query string.
Returns: List of KnowledgeBaseSearchResult objects.

search(query: str)

Synchronously perform search operations.
def search(query: str) -> List[KnowledgeBaseSearchResult]
Parameters: Same as asearch(). Returns: List of KnowledgeBaseSearchResult objects.

Knowledge Base Management

adelete()

Asynchronously delete the knowledge base.
async def adelete() -> None

delete()

Synchronously delete the knowledge base.
def delete() -> None
See SDK Types Reference for detailed information on:

Error Handling

Methods may raise ModuleException for SDK-related errors.
from xpander_sdk.exceptions import ModuleException

try:
    search_results = await kb.asearch("nonexistent term")
except ModuleException as e:
    print(f"Error: {e.description}")

Continue to the Knowledge Bases Module Reference for full module documentation.