﻿# Prodigy custom streams: a lazy iterator still needs a reproducible source boundary

Build Prodigy annotation streams from generators without confusing bounded memory, stable source ordering and reliable restart after partial annotation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-prodigy-lazy-stream-restart-source/
Language: en

## Separate streaming from reproducibility

A generator can keep an annotation process from loading a large source into memory all at once. It does not automatically make that source stable. The [Prodigy loader guide](https://prodi.gy/docs/api-loaders) describes iterable task streams and line-oriented input. For a repeatable annotation run, also identify the source revision, selection rule and order that produced the tasks. Otherwise a restart can read a different population while still using the same recipe and destination dataset.

## Keep the task producer inspectable

The [custom recipe documentation](https://prodi.gy/docs/custom-recipes) permits a recipe to return an iterable stream together with interface and storage components. Separate fetching source records from constructing annotation questions. A text record can be valid at the source but become an invalid task if required interface fields are missing. Test the producer on examples with absent optional fields, unusual characters and empty content before connecting it to a long-running annotation session.

## Account for ordering and remote pagination

When a generator reads a changing API, new records or modified sort keys can shift page boundaries. A fixed query string is not necessarily a fixed source snapshot. Prefer a documented stable revision or record a selected set of source identities. If the source cannot supply snapshot semantics, state that limitation and preserve the retrieved task stream as a separate artifact when reproducibility is required. This is a property of the source, not something the Python iterator can repair.

## Plan a restart around persisted work

The [database API](https://prodi.gy/docs/api-database) distinguishes stored datasets and session records and provides retrieval methods for examples. Decide which persisted annotation history the restarted recipe will exclude. An iterator position in process memory disappears when that process exits; it is different from a source checkpoint and from submitted feedback in storage. Rehearse interruption after a partial session, then inspect which source records and questions reappear.

## Preserve what explains the collected data

Keep the recipe configuration, source boundary and selection history with the exported annotations. The guides on [WebDataset sample identity](/journal/data-guide-webdataset-sample-key-shards/) and [active-learning selection history](/journal/data-guide-active-learning-selection-bias/) illustrate related pitfalls. A memory-efficient loader is valuable, but the research result depends on knowing which questions reached reviewers and which answers were actually retained. Treat those observations as distinct from how many records the source offered to the generator.
