Endpoints

Extractive question answering

POST /extractions/qa

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

Example

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);

Authorizations

Authorization
string header required

An Isaacus-issued API key passed as a bearer token via the Authorization header in the format Authorization: Bearer YOUR_API_KEY.

Request body

model
string required

The ID of the model to use for extractive question answering.

query
string required

The query to extract the answer to.

The query must contain at least one non-whitespace character.

Unlike 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.

texts
string[] required

The texts to search for the answer in and extract the answer from.

There must be at least one text.

Each text must contain at least one non-whitespace character.

ignore_inextractability
boolean

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.

If 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.

top_k
integer

The number of highest scoring answers to return.

If null, which is the default, all answers will be returned.

chunking_options

Settings for how texts should be chunked into smaller segments by semchunk before extraction.

If 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.

Chunking is enabled by default.

size

The maximum number of tokens allowed in a chunk.

If null, the maximum input length of the model will be used less overhead.

overlap_ratio

The proportion of the chunk size by which chunks should overlap.

The ratio must be less than 1.

If null, no overlapping will occur unless overlap_tokens is set.

overlap_ratio and overlap_tokens cannot both be set.

overlap_tokens

The number of tokens by which chunks should overlap.

If null, no overlapping will occur unless overlap_ratio is set.

overlap_tokens and overlap_ratio cannot both be set.

Response

The results of extracting answers from texts.

200
{
  "extractions": [
    {
      "index": 0,
      "answers": [
        {
          "text": "30 years if the person murdered was a police officer and 25 years in any other case",
          "start": 61,
          "end": 144,
          "score": 0.11460486645671249
        }
      ],
      "inextractability_score": 0.0027424068182309302
    }
  ],
  "usage": {
    "input_tokens": 43
  }
}
extractions
object[] required

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).

index
integer required

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).

answers
object[] required

Answers extracted from the text, ordered from highest to lowest score.

text
string required

The text of the answer.

start
integer required

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).

end
integer required

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]).

score
number required

A score between 0 and 1, inclusive, representing the strength of the answer.

inextractability_score
number required

A score between 0 and 1, inclusive, representing the likelihood that an answer can not be extracted from the text.

Where 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.

usage
object required

Statistics about the usage of resources in the process of extracting answers from the texts.

input_tokens
integer required

The number of tokens inputted to the model.

See making requests for authentication, SDK usage, and errors.