symfonic.memory.backends.in_memory¶
in_memory ¶
In-memory backends for testing and prototyping.
Zero-dependency GraphBackend and VectorBackend over plain dicts, scoped by tenant_id.
InMemoryGraphBackend ¶
GraphBackend over dicts keyed by (tenant_id, node_id/edge_id).
Testing and local development only.
Source code in src/symfonic/memory/backends/in_memory.py
add_edge
async
¶
Add an edge to the in-memory store.
add_node
async
¶
Add a node to the in-memory store.
v8.0: stamps the materialised scope_path into the node's
property bag (zero-migration) so the prefix-isolation filter (§5.d)
can be enforced on every read.
Source code in src/symfonic/memory/backends/in_memory.py
delete_edge
async
¶
Delete a single edge by its ID.
delete_node
async
¶
Delete a node, optionally cascading to connected edges.
Source code in src/symfonic/memory/backends/in_memory.py
delete_subtree
async
¶
Erase owned subtree, edges and cursors in one non-yielding operation.
Source code in src/symfonic/memory/backends/in_memory.py
get_neighbors
async
¶
get_neighbors(scope: TenantScope, node_id: NodeId, relationship: str | None = None) -> list[MemoryNode]
Get nodes connected to the given node by edges.
Source code in src/symfonic/memory/backends/in_memory.py
get_node
async
¶
Get a node by ID within the scope's visible prefix chain.
Source code in src/symfonic/memory/backends/in_memory.py
query_edges
async
¶
query_edges(scope: TenantScope, filters: dict[str, Any] | None = None, limit: int = 50, offset: int = 0) -> list[MemoryEdge]
Query edges with optional relationship filter and pagination.
Source code in src/symfonic/memory/backends/in_memory.py
query_nodes
async
¶
query_nodes(scope: TenantScope, filters: dict[str, Any], limit: int | None = 50) -> list[MemoryNode]
Filter nodes by properties within the tenant scope.
limit=None returns every matching node (no truncation);
limit=0 returns no rows (v8.7.1 — unified across backends).
Source code in src/symfonic/memory/backends/in_memory.py
query_subtree
async
¶
query_subtree(scope: TenantScope, filters: dict[str, Any], limit: int | None = None) -> list[MemoryNode]
Filter nodes at scope or below it (the descendant read).
Source code in src/symfonic/memory/backends/in_memory.py
transaction ¶
All of a batch, or none of it -- see :mod:.in_memory_transaction.
traverse
async
¶
BFS traversal from start node up to max_depth.
Source code in src/symfonic/memory/backends/in_memory.py
update_node
async
¶
Partial update of node properties.
Source code in src/symfonic/memory/backends/in_memory.py
upsert_edge
async
¶
Insert edge or increment weight by 1 if (tenant, source, target, rel) matches.
Source code in src/symfonic/memory/backends/in_memory.py
InMemoryVectorBackend ¶
In-memory implementation of the VectorBackend protocol.
Stores embeddings in a list and uses brute-force cosine similarity for search. Suitable for testing only.
Source code in src/symfonic/memory/backends/in_memory_vector.py
add
async
¶
add(scope: TenantScope, ids: list[str], embeddings: list[list[float]], metadatas: list[dict[str, Any]], documents: list[str]) -> None
Add vectors with metadata to the store.
v8.0: stamps the materialised scope_path into the metadata bag so
the prefix-isolation filter (§5.d) can run on every search.
Source code in src/symfonic/memory/backends/in_memory_vector.py
count
async
¶
delete
async
¶
Delete vectors by their IDs.
Source code in src/symfonic/memory/backends/in_memory_vector.py
search
async
¶
Brute-force cosine similarity search.
v8.0: ALWAYS-ON prefix-isolation (§5.d) — only entries whose stored
scope_path is a prefix of the query path are scored. Dual-reads
pre-v8.0 metadata (no scope_path) as a 1-level root path.