Skip to main content

Question Answering

The qa resource submits and manages AI question answering jobs. It is available via client.qa.

import asyncio
from biolevate import BiolevateClient, QuestionInput

async def main():
async with BiolevateClient(
base_url="https://<api-domain>",
token="<your-pat>",
) as client:
job = await client.qa.create_job(
questions=[
QuestionInput(
id="q1",
question="What is the main conclusion?",
answer_type={"dataType": "STRING", "multiValued": False},
)
],
file_ids=["a1b2c3d4-e5f6-7890-abcd-ef1234567890"],
)
print(f"Job created: {job.job_id} (status: {job.status})")

asyncio.run(main())

Methods

create_job()

Submit a new QA job. Target documents by file_ids, collection_ids, or both.

from biolevate import QuestionInput

job = await client.qa.create_job(
questions=[
QuestionInput(
id="q1",
question="What is the main conclusion of this document?",
answer_type={"dataType": "STRING", "multiValued": False},
),
QuestionInput(
id="q2",
question="What is the publication date?",
answer_type={"dataType": "DATE", "multiValued": False},
),
],
file_ids=["a1b2c3d4-e5f6-7890-abcd-ef1234567890"],
collection_ids=None,
)
print(f"Job: {job.job_id}")
ParameterTypeDefaultDescription
questionslist[QuestionInput]Questions to ask
file_idslist[str] | NoneNoneUUIDs of individual EliseFiles to process
collection_idslist[str] | NoneNoneUUIDs of Collections to process

Returns Job

Raises AuthenticationError, APIError


get_job()

Get the current status of a QA job. Poll this until status is SUCCESS or FAILED.

job = await client.qa.get_job(job_id)
print(f"Status: {job.status}")
ParameterTypeDescription
job_idstrUUID of the QA job

Returns Job

Raises NotFoundError, AuthenticationError, APIError


list_jobs()

List all QA jobs for the current user.

page = await client.qa.list_jobs(page=0, page_size=20)
for job in page.data:
print(f"{job.job_id}: {job.status}")
ParameterTypeDefaultDescription
pageint0Page number (0-based)
page_sizeint20Number of jobs per page
sort_propertystr | NoneNoneField to sort by
sort_orderstr | NoneNone"ASC" or "DESC"

Returns JobPage

Raises AuthenticationError, APIError


get_job_outputs()

Retrieve the results of a completed QA job.

outputs = await client.qa.get_job_outputs(job_id)
for result in outputs.results:
print(f"Q: {result.question}")
print(f"A: {result.raw_value}")
if result.explanation:
print(f" {result.explanation}")
ParameterTypeDescription
job_idstrUUID of the QA job

Returns QAJobOutputs

Raises NotFoundError, AuthenticationError, APIError


get_job_inputs()

Retrieve the original inputs submitted to the job.

inputs = await client.qa.get_job_inputs(job_id)
print(f"Questions: {[q.question for q in inputs.questions]}")
ParameterTypeDescription
job_idstrUUID of the QA job

Returns QAJobInputs

Raises NotFoundError, AuthenticationError, APIError


get_job_annotations()

Retrieve the source annotations for all results — document passages the AI used as evidence.

annotations = await client.qa.get_job_annotations(job_id)
for ann in annotations:
if ann.data:
print(f"[{ann.data.document_name}] {ann.data.content[:80]}")
ParameterTypeDescription
job_idstrUUID of the QA job

Returns list[Annotation]

Raises NotFoundError, AuthenticationError, APIError

Full Example — Create, Poll, and Retrieve Results

import asyncio
from biolevate import BiolevateClient, QuestionInput

TERMINAL_STATUSES = {"SUCCESS", "FAILED", "ABORTED"}

async def main():
async with BiolevateClient(
base_url="https://<api-domain>",
token="<your-pat>",
) as client:
job = await client.qa.create_job(
questions=[
QuestionInput(
id="q1",
question="What is the main conclusion of this document?",
answer_type={"dataType": "STRING", "multiValued": False},
),
QuestionInput(
id="q2",
question="What is the risk level?",
answer_type={
"dataType": "ENUM",
"multiValued": False,
"enumValues": ["LOW", "MEDIUM", "HIGH"],
},
),
],
file_ids=["a1b2c3d4-e5f6-7890-abcd-ef1234567890"],
)
print(f"Job created: {job.job_id}")

while True:
job = await client.qa.get_job(job.job_id)
print(f"Status: {job.status}")
if job.status in TERMINAL_STATUSES:
break
await asyncio.sleep(3)

if job.status == "SUCCESS":
outputs = await client.qa.get_job_outputs(job.job_id)
for result in outputs.results:
print(f"Q: {result.question}")
print(f"A: {result.raw_value}")

annotations = await client.qa.get_job_annotations(job.job_id)
annotation_map = {a.id.id: a for a in annotations}
for result in outputs.results:
for ref in result.reference_ids:
ann = annotation_map.get(ref.id)
if ann and ann.data:
print(f" Source: [{ann.data.document_name}] {ann.data.content[:80]}")

asyncio.run(main())

Next Steps