Document Question Answering
- async AsyncCogniteClient.ai.tools.documents.ask_question(
- question: str,
- *,
- id: int | Sequence[int] | None = None,
- external_id: str | Sequence[str] | None = None,
- instance_id: NodeId | Sequence[NodeId] | None = None,
- language: AnswerLanguage | Literal['Chinese', 'Dutch', 'English', 'French', 'German', 'Italian', 'Japanese', 'Korean', 'Latvian', 'Norwegian', 'Portuguese', 'Spanish', 'Swedish'] = AnswerLanguage.English,
- additional_context: str | None = None,
- ignore_unknown_ids: bool = False,
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 | Sequence[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, AsyncCogniteClient >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> 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, ... )