<DocsApiEndpoint method="POST" path="/extractions/qa" slug="api-reference/extractions/extractive-question-answering" />

Extract information from documents with an Isaacus extractive question answering model.

## Example

<DocsCodeGroup>

```javascript
import Isaacus from 'isaacus';

const client = new Isaacus({
  apiKey: process.env['ISAACUS_API_KEY'],
});

const answerExtractionResponse = await client.extractions.qa.create({
  model: 'kanon-answer-extractor',
  query: 'What is the punishment for murder in Victoria?',
  texts: [
    'The standard sentence for murder in the State of Victoria is 30 years if the person murdered was a police officer and 25 years in any other case.',
  ],
});

console.log(answerExtractionResponse.extractions);
```

```python
import os
from isaacus import Isaacus

client = Isaacus(
    api_key=os.environ.get("ISAACUS_API_KEY"),
)
answer_extraction_response = client.extractions.qa.create(
    model="kanon-answer-extractor",
    query="What is the punishment for murder in Victoria?",
    texts=["The standard sentence for murder in the State of Victoria is 30 years if the person murdered was a police officer and 25 years in any other case."],
)
print(answer_extraction_response.extractions)
```

</DocsCodeGroup>

## Authorizations

<DocsApiFieldGroup>
	<DocsApiField name="Authorization" type="string" id="parameter-authorization" location="header" required description={"An Isaacus-issued API key passed as a bearer token via the `Authorization` header in the format `Authorization: Bearer YOUR_API_KEY`."} />
</DocsApiFieldGroup>

## Request body

<DocsApiFieldGroup>
	<DocsApiField name="model" type="string" id="body-model" required description={"The ID of the [model](https://docs.isaacus.com/models#extractive-question-answering) to use for extractive question answering."} />

	<DocsApiField name="query" type="string" id="body-query" required description={"The query to extract the answer to.\n\nThe query must contain at least one non-whitespace character.\n\nUnlike the texts from which the answer will be extracted, the query cannot be so long that it exceeds the maximum input length of the model."} />

	<DocsApiField name="texts" type="array[string]" id="body-texts" required description={"The texts to search for the answer in and extract the answer from.\n\nThere must be at least one text.\n\nEach text must contain at least one non-whitespace character."} />

	<DocsApiField name="ignore_inextractability" type="boolean" id="body-ignore-inextractability" description={"Whether to, if the model's score of the likelihood that an answer can not be extracted from a text is greater than the highest score of all possible answers, still return the highest scoring answers for that text.\n\nIf you have already determined that the texts answer the query, for example, by using one of our classification or reranker models, then you should set this to `true`."} />

	<DocsApiField name="top_k" type="integer" id="body-top-k" description={"The number of highest scoring answers to return.\n\nIf `null`, which is the default, all answers will be returned."} />

	<DocsApiField name="chunking_options" types={[{"type":"object","id":"body-chunking-options-one-of-0"},{"type":"null","id":"body-chunking-options-one-of-1"}]} description={"Settings for how texts should be chunked into smaller segments by [semchunk](https://github.com/isaacus-dev/semchunk) before extraction.\n\nIf `null`, the texts will not be chunked and will instead be truncated to the maximum input length of the model less overhead if found to exceed that limit.\n\nChunking is enabled by default."}>
	<DocsApiFieldNested>
		<DocsApiField name="size" types={[{"type":"integer","id":"body-chunking-options-one-of-0-size-one-of-0"},{"type":"null","id":"body-chunking-options-one-of-0-size-one-of-1"}]} nested description={"The maximum number of tokens allowed in a chunk.\n\nIf `null`, the maximum input length of the model will be used less overhead."} />

	<DocsApiField name="overlap_ratio" types={[{"type":"number","id":"body-chunking-options-one-of-0-overlap-ratio-one-of-0"},{"type":"null","id":"body-chunking-options-one-of-0-overlap-ratio-one-of-1"}]} nested description={"The proportion of the chunk size by which chunks should overlap.\n\nThe ratio must be less than 1.\n\nIf `null`, no overlapping will occur unless `overlap_tokens` is set.\n\n`overlap_ratio` and `overlap_tokens` cannot both be set."} />

	<DocsApiField name="overlap_tokens" types={[{"type":"integer","id":"body-chunking-options-one-of-0-overlap-tokens-one-of-0"},{"type":"null","id":"body-chunking-options-one-of-0-overlap-tokens-one-of-1"}]} nested description={"The number of tokens by which chunks should overlap.\n\nIf `null`, no overlapping will occur unless `overlap_ratio` is set.\n\n`overlap_tokens` and `overlap_ratio` cannot both be set."} />
	</DocsApiFieldNested>
</DocsApiField>
</DocsApiFieldGroup>

## Response

The results of extracting answers from texts.

<DocsCodeBlock code={"{\n  \"extractions\": [\n    {\n      \"index\": 0,\n      \"answers\": [\n        {\n          \"text\": \"30 years if the person murdered was a police officer and 25 years in any other case\",\n          \"start\": 61,\n          \"end\": 144,\n          \"score\": 0.11460486645671249\n        }\n      ],\n      \"inextractability_score\": 0.0027424068182309302\n    }\n  ],\n  \"usage\": {\n    \"input_tokens\": 43\n  }\n}"} lang="json" label="200" />

<DocsApiFieldGroup>
	<DocsApiField name="extractions" type="array[object]" id="response-extractions" required description={"The results of extracting answers from the texts, ordered from highest to lowest answer confidence score (or else lowest to highest inextractability score if there are no answers for a text)."}>
	<DocsApiFieldNested>
		<DocsApiField name="index" type="integer" id="response-extractions-items-index" required nested description={"The index of the text in the input array of texts that this result represents, starting from `0` (and, therefore, ending at the number of texts minus `1`)."} />

	<DocsApiField name="answers" type="array[object]" id="response-extractions-items-answers" required nested description={"Answers extracted from the text, ordered from highest to lowest score."}>
	<DocsApiFieldNested>
		<DocsApiField name="text" type="string" id="response-extractions-items-answers-items-text" required nested description={"The text of the answer."} />

	<DocsApiField name="start" type="integer" id="response-extractions-items-answers-items-start" required nested description={"The index of the first character of the answer in the text, starting from `0` (and, therefore, ending at the number of characters in the text minus `1`)."} />

	<DocsApiField name="end" type="integer" id="response-extractions-items-answers-items-end" required nested description={"The index of the character immediately after the last character of the answer in the text, starting from `0` (such that, in Python, the answer is equivalent to `text[start:end]`)."} />

	<DocsApiField name="score" type="number" id="response-extractions-items-answers-items-score" required nested description={"A score between `0` and `1`, inclusive, representing the strength of the answer."} />
	</DocsApiFieldNested>
</DocsApiField>

	<DocsApiField name="inextractability_score" type="number" id="response-extractions-items-inextractability-score" required nested description={"A score between `0` and `1`, inclusive, representing the likelihood that an answer can not be extracted from the text.\n\nWhere this score is greater than the highest score of all possible answers, the text should be regarded as not having an extractable answer to the query. If that is the case and `ignore_inextractability` is `false`, no answers will be returned."} />
	</DocsApiFieldNested>
</DocsApiField>

	<DocsApiField name="usage" type="object" id="response-usage" required description={"Statistics about the usage of resources in the process of extracting answers from the texts."}>
	<DocsApiFieldNested>
		<DocsApiField name="input_tokens" type="integer" id="response-usage-input-tokens" required nested description={"The number of tokens inputted to the model."} />
	</DocsApiFieldNested>
</DocsApiField>
</DocsApiFieldGroup>

See [making requests](/docs/api-reference/making-requests) for authentication, SDK usage, and [errors](/docs/api-reference/errors).