Skip to content

Stores

Every shipped Store backend. All five satisfy the same Store Protocol - see Custom stores for the contract.

Always available

MemoryStore

MemoryStore(*, max_entries: int | None = None)

In-memory Store implementation. Thread-safe via threading.RLock.

SQLiteStore

SQLiteStore(path: str | Path, *, timeout: float = 5.0, cache_size_kb: int = 10000)

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

iter_index_rows() -> Iterator[tuple[int, bytes, str]]

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}:meta HASH — schema_meta (fingerprint, dim, schema_version)
  • {p}:next_id STRING — INCR-backed monotonic id
  • {p}:version STRING — 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_id ZSET — member=id, score=id (for iter_since / iter_all)
  • {p}:by_ttl ZSET — member=id, score=created_at+ttl (for delete_expired)
  • {p}:quota:{ns} STRING — namespace quota
  • {p}:namespaces SET — 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.