You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(examples): derive SQL memory IDs from keys so search results are reproducible - #10
createSqlMemoryStore (examples/_shared/tools/storage/sql-memory.ts) gives every written memory a fresh randomUUID(), while get, query and search all order by that ID (ORDER BY id LIMIT ?). Whenever more rows match than limit, the rows that come back depend only on the random IDs. As a result:
writing the same memories into two databases (or rebuilding one) returns different search results;
the order of query pages also changes from one build to the next.
The Qdrant adapter already avoids this: it derives point IDs from the key with memoryPointId(key) (qdrant-memory.ts).
We ran into this while comparing two Worker layouts of the same agent on a benchmark. The only reason the model received different requests under the two layouts was that SQLite memory search returned different rows. With key-derived IDs, the request bodies sent to the model were byte-identical for every task we compared.
Change
Keyed memories now get the same key-derived UUID that qdrant-memory.ts uses. I copied the helper as memoryRecordId so that sql-memory.ts doesn't have to import qdrant-memory.ts, which pulls in @codesoul-co/ditto-retrieval. If you prefer, I can move the helper into a small shared file instead.
Memories without a key still get randomUUID().
New test in test/examples-memory.test.ts. It writes the same keyed memories into two SQLite files and checks two things: the IDs match the Qdrant point IDs, and a limited search returns the same rows in both files. The test fails on the current dev.
Compatibility
Both bundled schemas (SQLite and Postgres) declare memory_key TEXT UNIQUE and use idempotentKeys = true, so this change adds no new conflicts. Existing rows keep their IDs; only new writes are affected.
One behavior change for custom setups: with idempotentKeys = false and a table where memory_key is not unique, writing the same key twice used to create a duplicate row. It now fails on the primary key. This seems closer to the intended key semantics, but I'm happy to limit key-derived IDs to idempotentKeys = true if you prefer.
Ordering for memories without a key is still arbitrary. That is out of scope here.
Validation
Run with npm run check on Windows 11, Node 24.14.0, on top of dev at f0e5297:
Thanks for tracking the different search results down to the SQLite IDs. Please use the key-derived ID only when idempotentKeys is enabled and the record has a key. The SQL integration example uses the default mode and explicitly allows several records to share a key. Two writes with the same key should still return distinct IDs there.
Could you add a regression test for those two writes alongside the reproducibility test? For the UUID calculation, please share one small helper between the SQL and Qdrant adapters so they stay in sync.
Key-derived IDs are now used only when idempotentKeys is enabled and the record has a key. The default mode keeps randomUUID(), so the SQL integration example can still store several records under one key.
New regression test using the integration example's schema (memory_key indexed, not unique). Two writes with the same key return distinct IDs, neither ID is the key-derived one, and get({ keys }) returns both records. The test fails against this PR's previous commit.
The UUID calculation now lives in one helper, keyedMemoryId in examples/_shared/tools/storage/memory-id.ts. qdrant-memory.ts imports it and still exports memoryPointId, so existing imports keep working. sql-memory.ts no longer has its own copy.
sql-memory.ts now imports memory-id.ts, so the new file has to be copied wherever sql-memory.ts is copied. I added it to:
the copy lists in scripts/check-package-basics.ts and scripts/check-json-agent-package.ts;
the copy instructions in the package guide and the package-basics, integrations and handbook READMEs, in English and Chinese;
the table in the storage README.
These two scripts spawn npm directly, which doesn't work on Windows, so I couldn't run them here. Instead I copied exactly the files on the updated list into a separate directory and ran openSqliteMemory write and search there; both worked. Without memory-id.ts in the copy, that run fails with ERR_MODULE_NOT_FOUND.
npm run check on Windows 11, Node 24.14.0: 519 tests, 512 passed, 3 skipped, 4 failed. The 4 failures are the same Windows-only tests as before.
The "Compatibility" section of the description is now out of date: default mode no longer changes behavior.
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
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.
Problem
createSqlMemoryStore(examples/_shared/tools/storage/sql-memory.ts) gives every written memory a freshrandomUUID(), whileget,queryandsearchall order by that ID (ORDER BY id LIMIT ?). Whenever more rows match thanlimit, the rows that come back depend only on the random IDs. As a result:searchresults;querypages also changes from one build to the next.The Qdrant adapter already avoids this: it derives point IDs from the key with
memoryPointId(key)(qdrant-memory.ts).We ran into this while comparing two Worker layouts of the same agent on a benchmark. The only reason the model received different requests under the two layouts was that SQLite memory search returned different rows. With key-derived IDs, the request bodies sent to the model were byte-identical for every task we compared.
Change
qdrant-memory.tsuses. I copied the helper asmemoryRecordIdso thatsql-memory.tsdoesn't have to importqdrant-memory.ts, which pulls in@codesoul-co/ditto-retrieval. If you prefer, I can move the helper into a small shared file instead.randomUUID().test/examples-memory.test.ts. It writes the same keyed memories into two SQLite files and checks two things: the IDs match the Qdrant point IDs, and a limitedsearchreturns the same rows in both files. The test fails on the currentdev.Compatibility
memory_key TEXT UNIQUEand useidempotentKeys = true, so this change adds no new conflicts. Existing rows keep their IDs; only new writes are affected.idempotentKeys = falseand a table wherememory_keyis not unique, writing the same key twice used to create a duplicate row. It now fails on the primary key. This seems closer to the intended key semantics, but I'm happy to limit key-derived IDs toidempotentKeys = trueif you prefer.Validation
Run with
npm run checkon Windows 11, Node 24.14.0, on top ofdevatf0e5297:writeis switched back torandomUUID()with everything else unchanged.devon this machine, and none of them touches the files changed here. They all look Windows-specific:capability-boundary.test.ts:examples/capabilities/tools/fixtures.ts: model/service transport belongs in a registered adapterexamples-rag.test.tsandexamples-retrieval.test.ts:EPERMonsymlink. Windows allows symlinks only in Developer Mode or with admin rights.sandbox-executor.test.ts: the environment-key assertion. Windows addsSYSTEMROOT,TEMPand similar keys; this was also noted in fix: stop ReAct on rejected or unknown output receipts #4.