fastrag.ingestion.cache#
The pluggable step cache.
The CacheStore contract, its PostgreSQL and SQLite implementations, and the
identity helpers every caching step builds cache ids with.
Caching is explicit and per-step (docs/specification/API.md: “Cache is
explicit in each step … it is better to be explicit about it”): a step is
handed a CacheStore or cache=False, never a hidden global.
- class fastrag.ingestion.cache.PostgresCache(*, url, schema='fastrag_cache', pool_size=5, read_batch_size=128, read_batch_delay=0.001)[source]#
Bases:
CacheStoreCache pipeline sources and documents on a PostgreSQL server.
async with PostgresCache(url=DATABASE_URL) as cache: sources = SitemapCrawler(url=SITEMAP_URL, cache=cache)
- Parameters:
url (str) –
postgresql://user:password@host:port/database. Accepted as a plainpostgresql://URL; the asyncpg driver is selected internally.schema (str) – The Postgres schema this cache’s tables live in. Created if absent. Defaults to a dedicated schema so the cache never collides with application tables.
pool_size (int) – Connections held by this cache’s engine.
read_batch_size (int) – Maximum buckets per bulk read (default 128). Concurrent single reads are coalesced up to this limit.
read_batch_delay (float) – Seconds to collect concurrent reads (default 0.001). Zero yields once to the event loop; size 1 disables grouping.
- async get_source_entries(source_cache_id)[source]#
See
get_source_entries().
- async get_source_entries_many(source_cache_ids)[source]#
Fetch source buckets in bounded batches, one SQL statement per batch.
- async get_source_headers_many(cache_ids)[source]#
Retrieve only identities, validators and routing metadata for indexing.
- async get_bucket_sources(source_cache_id, source_ids)[source]#
See
get_bucket_sources().
- async put_source_entries(source_cache_id, sources)[source]#
See
put_source_entries().
- async get_document_entries_many(document_cache_ids)[source]#
Fetch document buckets in bounded batches, one SQL statement per batch.
- async get_document_headers_many(cache_ids)[source]#
Retrieve snapshot identifiers and routing metadata without large payloads.
- async clear_sources()[source]#
See
clear_sources().- Return type:
- async clear_documents()[source]#
See
clear_documents().- Return type:
- async delete_sources(source_ids)[source]#
See
delete_sources().
- async delete_documents(source_ids)[source]#
See
delete_documents().
- async collect_garbage(max_age)[source]#
See
collect_garbage().
- class fastrag.ingestion.cache.SQLiteCache(*, path, timeout=30.0)[source]#
Bases:
CacheStoreCache pipeline sources and documents in a local SQLite file.
async with SQLiteCache(path=".fastrag/cache.sqlite") as cache: sources = SitemapCrawler(url=SITEMAP_URL, cache=cache)
- Parameters:
path (str | os.PathLike[str]) – The database file. Created, along with missing parent directories, on
__aenter__.":memory:"keeps the cache in memory for the lifetime of theasync withblock.timeout (float) – Seconds to wait for another process’s write lock before an operation fails with
TransientCacheError.
- async get_source_entries(source_cache_id)[source]#
See
get_source_entries().
- async get_source_headers_many(cache_ids)[source]#
Retrieve only identities, validators and routing metadata for indexing.
- async get_bucket_sources(source_cache_id, source_ids)[source]#
See
get_bucket_sources().
- async put_source_entries(source_cache_id, sources)[source]#
See
put_source_entries().
- async get_document_entries_many(document_cache_ids)[source]#
Fetch document buckets in one transaction.
- async get_document_headers_many(cache_ids)[source]#
Retrieve snapshot identifiers and routing metadata without large payloads.
- async clear_sources()[source]#
See
clear_sources().- Return type:
- async clear_documents()[source]#
See
clear_documents().- Return type:
- async delete_sources(source_ids)[source]#
See
delete_sources().
- async delete_documents(source_ids)[source]#
See
delete_documents().
- async collect_garbage(max_age)[source]#
See
collect_garbage().
- fastrag.ingestion.cache.document_cache_id(step_name, document_id, config_hash)[source]#
Return the cache id for one document under one step configuration.
- fastrag.ingestion.cache.source_cache_id(step_name, target, config_hash)[source]#
Return the cache id for one fetch target under one step configuration.
Modules
The pluggable cache contract every step-side cache backend implements. |
|
Cache identity helpers, shared by every step that caches. |
|
PostgreSQL-backed |
|
The ORM models behind |
|
SQLite-backed |