feat(engine): pluggable memories storage backend - #2917
Merged
Conversation
nicoloboschi
force-pushed
the
feat/pluggable-memories-provider
branch
16 times, most recently
from
July 30, 2026 08:31
f67985e to
3abd292
Compare
…ts/chunks Squashes the feat/pluggable-memories-provider work into one commit. - Carve the `memory_units` + link slice out from behind raw SQL into a pluggable MemoriesExtension (engine/memories/), so a different engine (memlake) can own memories, links, retrieval, consolidation and curation while documents, chunks, banks and the entity registry stay in Postgres. The default PostgresMemories keeps everything exactly where it was; every call site routes through the store interface rather than branching on the implementation. - Route recall (semantic+BM25+graph), scan/get, stats/counts, consolidation writes, curation edits, bank/document deletion, entity postings and graph reads through the store. - Cross-store write-group transactions (begin/decide/mint/witness + recovery sweep) so a store that keeps memories elsewhere commits atomically with the Postgres side of a retain/consolidation/curation/delete. - Documents & chunks: when the store owns a dedicated document store (owns_document_store), a document's bulky extracted text + chunk texts move out of Postgres into it (Postgres keeps thin rows: id, content_hash, chunk_index, tags); reads overlay the text from the store; the original file goes through a memlake FileStorage backend. All gated so the Postgres path is unchanged.
nicoloboschi
force-pushed
the
feat/pluggable-memories-provider
branch
from
July 30, 2026 12:05
3abd292 to
5ea84c9
Compare
nicoloboschi
marked this pull request as ready for review
July 30, 2026 12:40
nicoloboschi
added a commit
that referenced
this pull request
Aug 11, 2026
Re-applies the per-bank store-capability seam onto current main. The pluggable memories backend (#2917) is on main, but the per-bank capabilities landed later on feat/pluggable-memories-provider (#3350, plus fix #3381) while main advanced ~179 commits. A pluggable memories store may keep memory rows outside SQL and/or own the document store. The process-level flags writes_memory_rows_in_sql / owns_document_store gain per-bank forms — writes_memory_rows_in_sql_for(bank_id) and owns_document_store_for(bank_id), defaulting to the class attrs — and every bank-scoped call site in memory_engine, consolidation/consolidator, retain/* and reflect/tools consults the per-bank form. Process-level maintenance gates keep reading the class attr. Also two NameError fixes of the same class (a bare bank_id where the in-scope variable differs): list_banks (row["bank_id"], originally #3381) and get_chunk (chunk["bank_id"], newly surfaced by pyflakes while rebasing). Conflict resolution: only consolidation/consolidator.py conflicted — main added consolidation sites since the branch; all are bank_id-scoped, so all convert to the per-bank form. Validation: pyflakes on all changed engine files reports 0 undefined names; py_compile clean; per-bank + list_banks unit tests included.
nicoloboschi
added a commit
that referenced
this pull request
Aug 11, 2026
Re-applies the per-bank store-capability seam onto current main. The pluggable memories backend (#2917) is on main, but the per-bank capabilities landed later on feat/pluggable-memories-provider (#3350, plus fix #3381) while main advanced ~179 commits. A pluggable memories store may keep memory rows outside SQL and/or own the document store. The process-level flags writes_memory_rows_in_sql / owns_document_store gain per-bank forms — writes_memory_rows_in_sql_for(bank_id) and owns_document_store_for(bank_id), defaulting to the class attrs — and every bank-scoped call site in memory_engine, consolidation/consolidator, retain/* and reflect/tools consults the per-bank form. Process-level maintenance gates keep reading the class attr. Also two NameError fixes of the same class (a bare bank_id where the in-scope variable differs): list_banks (row["bank_id"], originally #3381) and get_chunk (chunk["bank_id"], newly surfaced by pyflakes while rebasing). Conflict resolution: only consolidation/consolidator.py conflicted — main added consolidation sites since the branch; all are bank_id-scoped, so all convert to the per-bank form. Validation: pyflakes on all changed engine files reports 0 undefined names; py_compile clean; per-bank + list_banks unit tests included.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The
memory_unitstable and the joins around it (memory_links,unit_entities) are as much a search index as a store — every recall arm (semantic, BM25, graph, temporal) is a query over them. Today that's hard-wired to Postgres SQL, scattered across the retain, recall, consolidation, curation and graph-maintenance paths.This makes that slice a pluggable extension point, so a different engine can own memory storage and retrieval without touching how documents, chunks, banks, operations or the entity registry are stored. It's loaded like every other Hindsight extension:
With nothing configured, behaviour is identical to today — the default is now an explicit
PostgresMemoriesimplementation rather than the absence of one.Shape of the change
MemoriesExtension(engine/memories/base.py) covering the write path, the recall arms, addressed reads, the graph view, observations and the maintenance passes. An implementation may be the sole store: it mints its own unit ids and carries entity postings / causal edges inline, so nothing memory- or link-shaped need reach Postgres.PostgresMemoriesis a thin delegator; its SQL moves unchanged intoengine/memories/pg/{curation,graph,reads,writes}.py, grouped by what calls it. Because it's an explicit store, the default path stays the one the whole suite exercises.observation_historydrops its FK tomemory_units, which assumed every observation is a row there — true only while Postgres is the store.Compatibility & risk