fastrag.ingestion.cache.base#
The pluggable cache contract every step-side cache backend implements.
Following docs/specification/caching.md: a step is handed a
CacheStore or nothing at all, so caching stays explicit and per-step
rather than a hidden global.
Classes
Pluggable abstract cache backend with distinct lifecycle support. |
|
|
Protocol for checking if an upstream resource has changed. |
- class fastrag.ingestion.cache.base.SourceFreshnessValidator(*args, **kwargs)[source]#
Bases:
ProtocolProtocol for checking if an upstream resource has changed.
- class fastrag.ingestion.cache.base.CacheStore[source]#
Bases:
AbstractAsyncContextManager[CacheStore],ABCPluggable abstract cache backend with distinct lifecycle support.
- abstractmethod async get_source_entries(source_cache_id)[source]#
Fetches cached sources associated with a step run.
- Parameters:
source_cache_id (str) – Unique hash of the source step configuration and target.
- Returns:
The cached sources,
[]if the id is known but holds no entries, orNoneon a cache miss. Each returnedSourcecarries its persistedlast_validated, so a caller can judge freshness without any per-process state.- Return type:
- abstractmethod async put_source_entries(source_cache_id, sources)[source]#
Persists fetched sources and updates source reference tables.
Idempotent: writing the same
source_cache_idagain replaces its entry set rather than appending to it.- Parameters:
source_cache_id (str) – Unique hash of the source step configuration.
sources (Sequence[Source]) – Sequence of Source objects to persist. Each source’s
last_validatedis written verbatim when set; a source withlast_validated=Noneis stamped with the current time, since being written at all means it was just validated.
- Return type:
None
- abstractmethod async get_document_entries(document_cache_id)[source]#
Fetches cached documents associated with a transformation step.
- async get_source_entries_many(source_cache_ids)[source]#
Read multiple buckets, including misses and known-empty results.
Backends may override this with a bulk query. The default preserves compatibility with backends implementing only single-bucket reads. Duplicate ids are read once; an empty input performs no I/O.
- async get_document_entries_many(document_cache_ids)[source]#
Read document buckets with the same semantics as single reads.
The default uses single-bucket reads for existing custom backends. Duplicate ids are read once; an empty input performs no I/O.
- abstractmethod async put_document_entries(document_cache_id, documents)[source]#
Persists transformed documents and updates document cache references.
Idempotent: writing the same
document_cache_idagain replaces its entry set rather than appending to it.
- async get_source_headers_many(cache_ids)[source]#
Read source identities and validators, with lazy content when supported.
The fallback returns complete sources for existing custom backends.
- async get_bucket_sources(source_cache_id, source_ids)[source]#
Read only
source_ids(with content) from one cached bucket.The fallback loads the whole bucket; backends should override it with a targeted query so hydrating one page of a large crawl bucket does not transfer every sibling page.
- async get_document_headers_many(cache_ids)[source]#
Read cached identities and routing metadata without text or vectors.
Optimized backends return lazy headers; the fallback returns complete documents. Ordinary cache getters always return complete outputs.
- abstractmethod async clear_sources()[source]#
Removes every cached source and every source cache id.
Cache administration only: emits nothing, retries nothing, and never touches a vector store.
- Returns:
The number of source rows removed.
- Return type:
- abstractmethod async clear_documents()[source]#
Removes every cached document and every document cache id.
Cache administration only: emits nothing, retries nothing, and never touches a vector store.
- Returns:
The number of document rows removed.
- Return type:
- abstractmethod async clear()[source]#
Removes everything this store holds: sources, documents, and both cache id tables.
Cache administration only: emits nothing, retries nothing, and never touches a vector store.
- Returns:
The total number of source and document rows removed.
- Return type:
- abstractmethod async delete_sources(source_ids)[source]#
Removes the named cached sources.
Any source cache id left referencing none of its entries after this deletion is removed too, so a later
get_source_entrieson that id returnsNone(a miss) rather than[](a known-empty result).Idempotent and tolerant: a
source_idsid that is not cached is silently skipped rather than raising. An emptysource_idsis a no-op — no statement is sent.
- abstractmethod async delete_documents(source_ids)[source]#
Removes every cached document whose
source_idis one of source_ids.Any document cache id left referencing none of its entries after this deletion is removed too, so a later
get_document_entrieson that id returnsNonerather than[].Idempotent and tolerant: a
source_idsid with no cached documents is silently skipped rather than raising. An emptysource_idsis a no-op — no statement is sent.
- abstractmethod async collect_garbage(max_age)[source]#
Removes every source and document whose
last_accessedpredatesnow - max_age.An age-based sweep keyed on the column every read already touches. Any source or document cache id left referencing none of its entries after the sweep is removed too, with the same empty-bucket guarantee as
delete_sources/delete_documents.- Parameters:
max_age (timedelta) – How old an entry may be, by
last_accessed, before it is collected. Must be positive.- Returns:
The total number of source and document rows removed.
- Raises:
ValueError – If
max_ageis zero or negative.- Return type: