Implementation:Confident ai Deepeval Synthesizer Generate Goldens From Contexts
| Sources | Domains | Last Updated |
|---|---|---|
| DeepEval | Synthetic_Data, LLM_Evaluation, Data_Management | 2026-02-14 09:00 GMT |
Overview
The generate_goldens_from_contexts method on the Synthesizer class generates evaluation goldens from pre-prepared text contexts, bypassing the document loading and chunking stages.
Description
This method accepts a list of context groups (each group being a list of text strings) and produces evaluation goldens by using the configured LLM to generate queries and expected answers conditioned on each context group. It is the preferred generation method when contexts have already been extracted, curated, or prepared through a custom pipeline. An optional source_files parameter allows associating each context group with its origin file for traceability.
Usage
Call this method on an instantiated Synthesizer when contexts are already available and document loading is not needed.
Code Reference
Source Location: Repository: confident-ai/deepeval, File: deepeval/synthesizer/synthesizer.py (L358-540)
Signature:
def generate_goldens_from_contexts(
self,
contexts: List[List[str]],
include_expected_output: bool = True,
max_goldens_per_context: int = 2,
source_files: Optional[List[str]] = None,
) -> List[Golden]:
...
Import:
from deepeval.synthesizer import Synthesizer
I/O Contract
Inputs:
| Parameter | Type | Required | Description |
|---|---|---|---|
| contexts | List[List[str]] | Yes | Pre-chunked text contexts; each inner list is a group of related text passages |
| include_expected_output | bool | No | Whether to generate expected answers for each golden (default: True) |
| max_goldens_per_context | int | No | Maximum number of goldens to generate per context group (default: 2) |
| source_files | Optional[List[str]] | No | Optional list of source file names corresponding to each context group for traceability |
Outputs:
- List[Golden] -- list of generated evaluation goldens, each containing input (query), expected_output (answer if requested), and context (source passages)
Usage Examples
from deepeval.synthesizer import Synthesizer
synthesizer = Synthesizer()
goldens = synthesizer.generate_goldens_from_contexts(
contexts=[["Python is a language.", "It supports OOP."]],
max_goldens_per_context=2,
)