fastrag.ingestion#
fastrag.ingestion — lazy, event-emitting ingestion pipeline.
A lazy pipeline API: constructing a step never executes anything, and
evaluating one emits lifecycle and domain events instead of writing to
stdout directly. This module re-exports the inert value types owned by
ingestion (Source, policy, events), the step contract and its evaluator
(PipelineStep, ExecutionContext), and Pipeline, the context
manager that installs the execution context and event sink for a whole
graph. Document — shared by retrieval, querying, serving and
benchmarking, not an ingestion-only concern — lives at fastrag.models
instead and is deliberately not re-exported here. The cache contract lives at
fastrag.ingestion.cache and is deliberately not re-exported here (see its
own module docstring); Logger/ConsoleLogger live at
fastrag.ingestion.logger, likewise not re-exported here. This package
must never import from outside its own tree, except the foundation modules
every package sits on top of (fastrag.models, fastrag.exceptions)
and the underscore-prefixed private modules directly under fastrag
(fastrag._sql today) that hold plumbing shared across packages.
- class fastrag.ingestion.Pipeline(root, *, cache=None, policy=None, source_headers_only=False, headers_only=False)[source]#
Bases:
AbstractAsyncContextManager[Pipeline]Evaluates a lazy
PipelineStepgraph.Pipelineowns theExecutionContextfor a whole run: it is responsible for creating it (with this pipeline’s own defaultcache/policy) and for installing the event sink every step in the graph — however deeply nested — ultimately emits into.async with Pipeline(vector_store.save(embedded_documents)) as pipeline: await ConsoleLogger(pipeline).run()
- Parameters:
root (PipelineStep[Any])
cache (CacheStore | None)
policy (Policy | None)
source_headers_only (bool)
headers_only (bool)
- property root: PipelineStep[Any]#
The step this pipeline evaluates — and the top of its upstream chain.
- class fastrag.ingestion.Policy(retries=UNSET, backoff=UNSET, max_backoff=UNSET, timeout=UNSET, on_error=UNSET, concurrency=UNSET, batch_size=UNSET, cache_batch_size=UNSET, recreate_cache=UNSET)[source]#
Bases:
objectExecution policy controlling operational constraints for pipeline steps.
- Parameters:
- on_error#
Failure handling strategy (
"skip","raise","retry").- Type:
Literal[‘skip’, ‘raise’, ‘retry’]
A step’s policy is layered over its parent’s (the pipeline’s, or an enclosing router/aggregator’s) with
merge(): only the fields the caller explicitly passed override the parent; the rest are inherited.
- class fastrag.ingestion.Source(id, uri, content, content_type, content_hash, etag=None, last_modified=None, metadata=<factory>, last_validated=None, cached=False)[source]#
Bases:
objectRaw content fetched from somewhere, plus enough metadata to place it.
A
Sourceis produced by a fetcher and carries the original bytes together with enough information to identify, validate, cache, and later transform it into one or moreDocumentinstances. Sources are independently cacheable, and their freshness may be validated against the originating system using ETags, modification timestamps, content hashes, or equivalent mechanisms.- Parameters:
- last_modified#
Origin-reported modification time, when available.
- Type:
datetime.datetime | None
- last_validated#
When this source was last confirmed fresh against its origin (or, for one that has never been revalidated, first fetched). Persisted: round-tripped through the cache so that
SourceStep.cache_validation_intervalmeans the same thing across process restarts, not just within one.Noneon aSourcethat has never been through a cache write, e.g. one just produced byevaluate()and not yet cached.- Type:
datetime.datetime | None
Modules
The pluggable step cache. |
|
Events emitted during pipeline execution. |
|
|
|
Pipeline event consumers for progress, documents and raw sources. |
|
Value types produced by the ingestion pipeline's source-fetching stage. |
|
|
|
Execution policy controlling operational constraints for pipeline steps. |
|
Step base classes and the policy-aware evaluator. |