AI

AI API

Document Summarization

AIDocumentsAPI.summarize(id: Optional[int] = None, external_id: Optional[str] = None, instance_id: Optional[NodeId] = None) Summary

Summarize a document using a Large Language Model.

Note

Currently only supports summarizing a single document at a time, but this may be extended in the future.

Parameters
  • id (int | None) – The ID of the document

  • external_id (str | None) – The external ID of the document

  • instance_id (NodeId | None) – The instance ID of the document

Returns

A summary of the document.

Return type

Summary

Examples

Summarize a single document using ID:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> client.ai.tools.documents.summarize(id=123)

You can also use external ID or instance ID:

>>> from cognite.client.data_classes.data_modeling import NodeId
>>> client.ai.tools.documents.summarize(
...     instance_id=NodeId("my-space", "my-xid")
... )

Document Question Answering

AIDocumentsAPI.ask_question(question: str, *, id: Optional[int] = None, external_id: Optional[Union[str, Sequence[str]]] = None, instance_id: Optional[Union[NodeId, Sequence[NodeId]]] = None, language: Union[AnswerLanguage, Literal['Chinese', 'Dutch', 'English', 'French', 'German', 'Italian', 'Japanese', 'Korean', 'Latvian', 'Norwegian', 'Portuguese', 'Spanish', 'Swedish']] = AnswerLanguage.English, additional_context: Optional[str] = None, ignore_unknown_ids: bool = False) Answer

Ask a question about one or more documents using a Large Language Model.

Supports up to 100 documents at a time.

Parameters
  • question (str) – The question.

  • id (int | None) – The ID(s) of the document(s)

  • external_id (str | Sequence[str] | None) – The external ID(s) of the document(s)

  • instance_id (NodeId | Sequence[NodeId] | None) – The instance ID(s) of the document(s)

  • language (AnswerLanguage | Literal['Chinese', 'Dutch', 'English', 'French', 'German', 'Italian', 'Japanese', 'Korean', 'Latvian', 'Norwegian', 'Portuguese', 'Spanish', 'Swedish']) – The desired language of the answer, defaults to English.

  • additional_context (str | None) – Additional context that you want the LLM to take into account.

  • ignore_unknown_ids (bool) – Whether to skip documents that do not exist or that are not fully processed, instead of throwing an error. If no valid documents are found, an error will always be raised.

Returns

The answer to the question in the form of a list of multiple content objects, each consisting of a chunk of text along with a set of references.

Return type

Answer

Examples

Ask a question about a single document with id=123 and get the answer in English (default):

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> client.ai.tools.documents.ask_question(
...     question="What model pump was used?",
...     id=123,
... )

Ask a question about multiple documents referenced using external IDs, and instance ID and get the answer in German:

>>> from cognite.client.data_classes.data_modeling import NodeId
>>> from cognite.client.data_classes.ai import AnswerLanguage
>>> client.ai.tools.documents.ask_question(
...     question="What other pumps are available?",
...     external_id=["foo", "bar"],
...     instance_id=NodeId("my-space", "my-xid"),
...     language=AnswerLanguage.German,
... )