QA generator
ydata.synthesizers.text.model.qa.DocumentQAGeneration
Generate question-answer pairs from documents using Large Language Models.
Each document is sent to an LLM agent that returns Q&A pairs grounded in its content; the results are collected into one table, with the source document of each pair.
Features
- Input from a single document, a folder of documents (DOCX or TXT), or a pyarrow Table of texts
- Configurable LLM provider and model (Workbench by default)
- Batch processing of multiple documents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
LLMProvider | str
|
LLM provider — |
WORKBENCH
|
subscription_key
|
str | None
|
API / subscription key. Non-Workbench providers fall back to their environment variables; Workbench falls back to the embedded key available in internal builds. |
None
|
model
|
str | OpenAIModel | AnthropicModel | GeminiModel | WorkbenchModel | None
|
Model identifier. Uses the backend default when omitted. |
GPT5
|
region_override
|
str | None
|
Workbench-only. Override the Azure region for the
API call (e.g. |
None
|
charging_code
|
str | None
|
Workbench-only. Charge code sent in the
|
None
|
Example
qa = DocumentQAGeneration(charging_code="
") pairs = qa.generate(input_source="contracts/", docs_extension="docx")
generate(input_source, docs_extension='docx', num_qa_pairs=10)
Generate Q&A scenarios from documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_source
|
str | Table
|
Path to a document or a folder of documents, or a
pyarrow Table with |
required |
docs_extension
|
str
|
Extension of the documents to read from a folder,
|
'docx'
|
num_qa_pairs
|
int
|
Number of Q&A pairs to generate |
10
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: One row per generated Q&A pair, with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input_source is invalid |
