Python API reference¶
Generated from the source, so it never drifts from the code.
For task-oriented examples, see the Python library guide.
Memory store¶
localmem_mcp.store.MemoryStore
¶
Local memory store backed by SQLite and on-device embeddings.
Source code in src/localmem_mcp/core/store.py
add
¶
Embed and persist a memory. Returns the stored record.
Source code in src/localmem_mcp/core/store.py
update
¶
Correct an existing memory in place. Returns None if there's no such memory.
Only the fields you pass are changed. Changing content re-embeds the
memory so search finds the correction; a tag- or source-only update
leaves the vector alone. created_at is preserved and updated_at
refreshed. The FTS5 index stays in sync via the AFTER UPDATE trigger.
Source code in src/localmem_mcp/core/store.py
delete
¶
Delete a memory. Returns True if it existed, False if it didn't.
Source code in src/localmem_mcp/core/store.py
matching
¶
Memories a bulk delete would remove, newest first.
Same filters as :meth:delete_many, without deleting — the CLI uses
this to show what forget --tag stale would remove before asking.
Source code in src/localmem_mcp/core/store.py
delete_many
¶
Bulk-delete memories matching all given tags and/or age.
Requires at least one of tags or older_than_days; an unfiltered
call raises :class:ValueError so the store can't be wiped by accident.
Deletion is hard — rows are gone, not hidden — and the FTS5 index stays
in sync via the AFTER DELETE trigger. Returns the number removed.
Source code in src/localmem_mcp/core/store.py
get
¶
Fetch one memory by id, or None if there's no such memory.
Source code in src/localmem_mcp/core/store.py
recent
¶
Most recently stored memories, newest first.
Source code in src/localmem_mcp/core/store.py
search
¶
Semantic search, nudged by exact keyword matches.
Every stored memory is scored by cosine similarity against the query embedding; memories that also match the FTS5 index get a bounded keyword bonus so literal terms are not lost to paraphrase.
Source code in src/localmem_mcp/core/store.py
count
¶
stats
¶
Database location, memory count, and the embedding model in use.
Data types¶
localmem_mcp.store.Memory
dataclass
¶
Embedders¶
localmem_mcp.store.Embedder
¶
Bases: Protocol
Anything that can turn text into a fixed-length vector.
localmem_mcp.store.FastEmbedEmbedder
¶
Local ONNX embeddings via fastembed.
The model is loaded lazily so importing this module (and starting the MCP
server) stays fast — the first store_memory/search_memory call pays the
load cost, not process startup.
Source code in src/localmem_mcp/core/embedders.py
embed
¶
Embed texts locally, loading the model on the first call.
Helpers¶
localmem_mcp.store.default_db_path
¶
Where memories live unless told otherwise.
Honours LOCALMEM_DB_PATH, then LOCALMEM_HOME, then ~/.localmem.
Source code in src/localmem_mcp/core/utils.py
Server¶
The MCP tool functions are documented in the MCP tools guide. These are the module-level helpers for embedding the server in your own process.
localmem_mcp.server.get_store
¶
Return the process-wide store, opening it on first use.
Source code in src/localmem_mcp/mcp/app.py
localmem_mcp.server.configure
¶
Point the server at a specific database/model before serving.