Stores¶
Every shipped Store backend. All five satisfy the same Store Protocol - see Custom stores for the contract.
Always available¶
MemoryStore ¶
In-memory Store implementation. Thread-safe via threading.RLock.
SQLiteStore ¶
SQLite-backed Store. Single-host, crash-safe via WAL.
Invariants: check_same_thread=False (the cache's RLock
serializes), all SQL is parameterized, multi-statement writes are wrapped
in with conn: (auto BEGIN / COMMIT / rollback-on-exception), and the
version_counter is incremented in the same transaction as the data
write.
iter_index_rows ¶
Bulk-read just (id, embedding_bytes, namespace) for index rebuild.
Skips the JSON metadata parse and full StoredEntry construction
that iter_all does — at 100k entries this is the difference
between a sub-100ms open and a 500ms+ open. Used by
SemanticCache._rebuild_index_from_store via duck-typing.
Optional extras¶
These are imported from their submodules to keep import mneme lightweight when their dependencies aren't installed.
RedisStore ¶
RedisStore(*, url: str | None = None, client: Redis | None = None, key_prefix: str = 'mneme', use_native_ttl: bool = True)
Redis-backed Store. Provide a connection url or a pre-built client.
Key layout under key_prefix:
{p}:metaHASH — schema_meta (fingerprint, dim, schema_version){p}:next_idSTRING — INCR-backed monotonic id{p}:versionSTRING — INCR-backed version_counter{p}:entry:{id}HASH — full entry fields{p}:hash:{ns}:{query_hash}STRING — id (exact-lookup index){p}:lru:{ns}ZSET — member=id, score=last_accessed_at{p}:by_idZSET — member=id, score=id (foriter_since/iter_all){p}:by_ttlZSET — member=id, score=created_at+ttl (fordelete_expired){p}:quota:{ns}STRING — namespace quota{p}:namespacesSET — known namespaces
When use_native_ttl=True (default), the entry HASH and its dependent
keys also receive Redis-level EXPIREAT. Application-level TTL stored
in the entry remains authoritative.
PostgresStore ¶
PostgresStore(dsn: str | None = None, *, connection: Connection | None = None, pool: Any = None, schema: str = 'mneme')
Postgres-backed Store. Provide a DSN, a connection, or a connection pool.
DynamoDBStore ¶
DynamoDBStore(table_name: str, *, region_name: str | None = None, endpoint_url: str | None = None, aws_profile: str | None = None, create_table: bool = False, billing_mode: Literal['PAY_PER_REQUEST', 'PROVISIONED'] = 'PAY_PER_REQUEST', provisioned_capacity: tuple[int, int] | None = None)
DynamoDB-backed Store. Optional [dynamodb] extra.
Authentication uses boto3's default credential chain (env vars / shared
config / IAM role). Pass endpoint_url to target moto or a local
DynamoDB emulator.