Skip to main content

Module memories

Module memories 

Source
Expand description

Persistence layer for the memories table and its vector companion.

Functions here encapsulate every SQL statement touching memories, memory_embeddings and the FTS5 fts_memories shadow table. Callers receive typed MemoryRow or NewMemory values and never build SQL strings.

One submodule per storage surface: rows holds the typed shapes, crud the single-row lookups and mutations, listing the paginated reads, vectors the memory_embeddings companion and its KNN query, fts the FTS5 shadow table, and soft_delete the tombstone lifecycle.

Structs§

MemoryRow
Fully materialized row from the memories table.
NewMemory
Input payload for inserting or updating a memory.

Functions§

clear_deleted_at
Clears deleted_at to restore a soft-deleted memory.
count
Count.
delete_vec
Deletes the vector row for memory_id from memory_embeddings.
find_by_hash
Looks up a live memory by exact body_hash within a namespace.
find_by_name
Finds a live memory by (namespace, name) and returns key metadata.
find_by_name_any_state
Looks up a memory by (namespace, name) regardless of deletion state.
fts_search
Executes an FTS5 search against fts_memories with query preprocessing.
insert
Inserts a new row into the memories table.
knn_search
Runs a KNN search over memory_embeddings, optionally restricted to namespaces.
list
Lists live memories in a namespace ordered by updated_at descending.
list_deleted_before
Fetches all memory_ids in a namespace that are soft-deleted and whose deleted_at is older than before_ts (unix epoch seconds).
read_by_name
Fetches a live memory by (namespace, name) and returns all columns.
read_full
Fetches a live memory by (namespace, name) and returns all columns. Fetches a live memory by primary key and returns all columns.
soft_delete
Soft-deletes a memory by setting deleted_at = unixepoch().
sync_fts_after_update
Syncs FTS5 external-content index after an UPDATE on the memories table.
update
Updates an existing memory optionally guarded by optimistic concurrency.
upsert_vec
Replaces the vector row for a memory in memory_embeddings.