Types¶
Public dataclasses, Protocols, and type aliases. Everything here is re-exported by mneme.__init__.
Dataclasses¶
Hit
dataclass
¶
Hit(response: str, similarity: float, confidence: float, age_seconds: int, layer: HitLayer, namespace: str, metadata: dict[str, Any])
Stats
dataclass
¶
Stats(namespace: str | None, entries: int, hits_exact: int, hits_semantic: int, misses: int, evictions: int, expirations: int, embedder_fingerprint: str, vector_dtype: str, memory_bytes_estimate: int, index_memory_bytes: int | None = None, index_tombstone_count: int | None = None)
Health
dataclass
¶
Health(healthy: bool, schema_version: int, integrity_ok: bool, embedder_fingerprint_match: bool, entries: int, namespaces: int, oldest_entry_age_seconds: int | None, index_backend: str, store_backend: str, vector_dtype: str, multi_process_mode: str)
StoredEntry
dataclass
¶
StoredEntry(id: int, namespace: str, query_hash: str, query: str, response: str, embedding: bytes, metadata: dict[str, Any], created_at: int, last_accessed_at: int, ttl: int | None, access_count: int)
Protocols¶
Embedder ¶
Bases: Protocol
Sync embedder. Returns 1-D float32 vectors of length dim.
AsyncEmbedder ¶
Bases: Protocol
Async embedder. Returns 1-D float32 vectors of length dim.
Index ¶
Bases: Protocol
In-memory vector index over L2-normalized float32 vectors.
Store ¶
Bases: Protocol
Persistent backend. Source of truth for entries; vectors persisted as float32.
Implementations must provide write atomicity for insert (vector and
metadata committed together) and durable reads for get_by_hash.
open ¶
Initialize storage. Validate fingerprint/dim against any existing data;
raise EmbedderMismatchError or EmbedderDimensionError on mismatch.
insert ¶
Returns the assigned id and bumps version_counter in the same txn.
snapshot_to ¶
Copy the entire store to dest_path. Format is implementation-defined.
Sync ↔ async embedder adapters¶
to_async_embedder ¶
Wrap a sync Embedder so it satisfies AsyncEmbedder.
to_sync_embedder ¶
Wrap an AsyncEmbedder so it satisfies Embedder (sync).
Type aliases¶
mneme exports four Literal aliases for configuration keys:
VectorDtype-"float32"|"float16"|"int8". The in-memory matrix dtype.HitLayer-"exact"|"semantic". Which layer answered aget.IndexBackend-"numpy"|"hnsw"|"auto". The index implementation.MultiProcessMode-"single"|"stale-tolerant"|"mmap-shared". Coordination across processes.
Plus three callable aliases:
ConfidenceFn-Callable[[float, int, dict[str, Any]], float]- your confidence scorer.Validator-Callable[[str], bool]- your response validator.MetricsHook-Callable[[str, dict[str, Any]], None]- your metrics fan-out.