gen_ai_hub.document_grounding.clients.vector_api_client module

Vector API client for Document Grounding.

This module provides the VectorAPIClient class for managing vector-based document collections and performing semantic searches. The Vector API enables creating, retrieving, updating, and deleting collections, as well as managing documents within those collections.

Key capabilities:
  • Collection management (create, read, update, delete)

  • Document management within collections

  • Semantic vector search across collections

  • Collection status tracking (creation/deletion)

API Reference: https://api.sap.com/api/DOCUMENT_GROUNDING_API/resource/Vector

class gen_ai_hub.document_grounding.clients.vector_api_client.VectorAPIClient(proxy_client: GenAIHubProxyClient | None = None)

Bases: object

The Vector API provides management and search capabilities for vector-based document collections.

It enables creating, retrieving, updating, and deleting collections, as well as managing documents and performing semantic vector searches within those collections.

Reference: https://api.sap.com/api/DOCUMENT_GROUNDING_API/resource/Vector

__init__(proxy_client: GenAIHubProxyClient | None = None)

Initializes the VectorAPIClient

Parameters:

proxy_client (Optional[GenAIHubProxyClient], optional) – Optional proxy client to use for requests

get_collections(top: int | None = None, skip: int | None = None, count: bool | None = None) CollectionsListResponse

Get all collections.

Parameters:
  • top (Optional[int], optional) – the number of collections to retrieve, defaults to None

  • skip (Optional[int], optional) – the number of collections to skip, defaults to None

  • count (Optional[bool], optional) – whether to include the total count of collections, defaults to None

Returns:

A CollectionsListResponse object containing the list of collections

Return type:

CollectionsListResponse

create_collection(collection_request: CollectionCreateRequest) Response

Create a new collection.

Parameters:

collection_request (CollectionCreateRequest) – The object containing the collection configuration.

Returns:

requests.Response empty object with 202 status code

Return type:

requests.Response

get_collection_by_id(collection_id: str) Collection

Get collection details by ID.

Parameters:

collection_id (str) – The ID of the collection to retrieve.

Returns:

A Collection object containing the collection details

Return type:

Collection

delete_collection(collection_id: str) Response

Delete collection by ID.

Parameters:

collection_id (str) – The ID of the collection to delete.

Returns:

requests.Response empty object with 204 status code

Return type:

requests.Response

get_documents(collection_id: str, top: int | None = None, skip: int | None = None, count: bool | None = None) DocumentsResponse

Get documents from a collection.

Parameters:
  • collection_id (str) – The ID of the collection to retrieve documents from.

  • top (Optional[int], optional) – the number of documents to retrieve, defaults to None

  • skip (Optional[int], optional) – the number of documents to skip, defaults to None

  • count (Optional[bool], optional) – whether to include the total count of documents, defaults to None

Returns:

A DocumentsResponse object containing the list of documents

Return type:

DocumentsResponse

create_documents(collection_id: str, request: DocumentsCreateRequest) DocumentsListResponse

Create documents in a collection.

Parameters:
  • collection_id (str) – The ID of the collection to add documents to.

  • request (DocumentsCreateRequest) – The object containing the documents to create.

Returns:

A DocumentsListResponse object containing the created documents

Return type:

DocumentsListResponse

update_documents(collection_id: str, request: DocumentsUpdateRequest) DocumentsListResponse

Update documents in a collection.

Parameters:
  • collection_id (str) – The ID of the collection to update documents in.

  • request (DocumentsUpdateRequest) – The object containing the documents to update.

Returns:

A DocumentsListResponse object containing the updated documents

Return type:

DocumentsListResponse

get_document_by_id(collection_id: str, document_id: str) Document

Get a document by ID from a collection.

Parameters:
  • collection_id (str) – The ID of the collection to retrieve the document from.

  • document_id (str) – The ID of the document to retrieve.

Returns:

A Document object containing the document details

Return type:

Document

delete_document(collection_id: str, document_id: str) Response

Delete a document from a collection.

Parameters:
  • collection_id (str) – The ID of the collection to delete the document from.

  • document_id (str) – The ID of the document to delete.

Returns:

requests.Response empty object with 204 status code

Return type:

requests.Response

get_collection_creation_status(collection_id: str) Annotated[CollectionCreatedResponse | CollectionPendingResponse, FieldInfo(annotation=NoneType, required=True, discriminator='status')]

Get creation status for a collection.

Parameters:

collection_id (str) – The ID of the collection to retrieve the creation status for.

Returns:

A CollectionCreationStatusResponse object containing the creation status

Return type:

CollectionCreationStatusResponse

get_collection_deletion_status(collection_id: str) Annotated[CollectionDeletedResponse | CollectionPendingResponse, FieldInfo(annotation=NoneType, required=True, discriminator='status')]

Get deletion status for a collection.

Parameters:

collection_id (str) – The ID of the collection to retrieve the deletion status for.

Returns:

A CollectionDeletionStatusResponse object containing the deletion status

Return type:

CollectionDeletionStatusResponse

search(request: TextSearchRequest) VectorSearchResults

Perform semantic search in vector collections.

Parameters:

request (TextSearchRequest) – The object containing the search parameters.

Returns:

A VectorSearchResults object containing the search results

Return type:

VectorSearchResults