feat(agent-memory): index bootstrap — MemoryStore.ensureIndex()#261
Merged
Conversation
KIvanow
approved these changes
Jun 19, 2026
e517bec to
8447b8e
Compare
cbef0e3 to
2d2dc3e
Compare
8447b8e to
602bdc4
Compare
2d2dc3e to
d1c1837
Compare
602bdc4 to
ce94197
Compare
d1c1837 to
7fd146a
Compare
ce94197 to
b258743
Compare
7fd146a to
9de1897
Compare
b258743 to
71793fa
Compare
9de1897 to
da84258
Compare
71793fa to
7c2413d
Compare
da84258 to
ea7ef4a
Compare
c971f49 to
df18e14
Compare
Base automatically changed from
feature/agent-memory-phase11-integration
to
master
June 22, 2026 07:03
… index
The package queried {name}:mem:idx for recall/forget/consolidate/capacity
but never created it, leaving the index as an undocumented caller
responsibility (flagged in review on #249/#250). Spec calls for the package
to own index create/version-skew handling.
- buildMemoryIndex: HNSW + memory schema (vector, scope/tag TAGs, numeric
tunables, content TEXT) as reusable FT.CREATE args
- MemoryStore.ensureIndex(): idempotent FT.INFO -> FT.CREATE, resolving the
vector dimension from embedFn when not yet observed
- AgentMemory.initialize() creates the index so the facade is usable without
a hand-rolled FT.CREATE
- Integration suite dogfoods ensureIndex() instead of hand-rolling the index
ea7ef4a to
4728320
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Agent Memory — index bootstrap (
ensureIndex)Stacked on #259 (Phase 11).
Why
MemoryStorequeries{name}:mem:idxin five paths (recall,forgetByScope,consolidate, capacity count + scan) but the package never creates that index — it was implicitly the caller's job, with the integration suite hand-rolling anFT.CREATE. This is the gap KIvanow flagged in review on #249/#250, andspec-agent-memory.md(data model + "reuse the valkey-search helper for index create/version-skew handling") calls for the package to own it. No phase had picked it up.What's new
buildMemoryIndex—buildMemoryIndexArgs(name, dims)/memoryIndexName(name): theFT.CREATEarg list for the memory schema —vector(HNSW, FLOAT32, COSINE),threadId/agentId/namespace/tags(comma-sep)/sourceas TAG,importance/created_at/last_accessed_at/access_countas NUMERIC,contentas TEXT. Matches exactly the fieldsbuildMemoryRecordwrites andbuildRecallQuery/buildScopeFilterquery.MemoryStore.ensureIndex()— idempotent:FT.INFO→ onisIndexNotFoundError(from@betterdb/valkey-search-kit) →FT.CREATE. Resolves the vector dimension fromembedFn(probe) when no write has been observed yet, and reuses a dimension already learned from a write. Non-"not found" errors propagate. MirrorsRetriever.createIndex()in the retrieval SDK.AgentMemory.initialize()now callsmemory.ensureIndex()first, so a freshly constructed facade is immediately usable forremember/recallwithout the caller hand-rolling the index. A create failure surfaces (the tier is unusable without it).Tests
buildMemoryIndexarg shape + dim validation;ensureIndexcreate-when-missing / idempotent / dim-probe / dim-reuse / non-not-found-rethrow;AgentMemory.initialize()creates the index.store.ensureIndex()instead of a hand-rolledFT.CREATE. (Skip-guarded; runs against a livevalkey-searchin CI / with the bundle up — it was not run locally here, as the bundle wasn't running. The hermetic tests verify the arg construction and idempotency.)tsc --noEmit+ prettier clean; 115 tests pass in the package.Notes
FLATindex for test simplicity; switching it toensureIndexaligns the test on the real production path.FT.CREATEbuilder into@betterdb/valkey-search-kitsoretrievalandagent-memoryshare one. Not required here — the memory schema is fixed.Note
Medium Risk
Index creation runs on initialize and locks vector dimension to the embedder; failures block startup, but behavior is idempotent and covered by new unit/integration tests.
Overview
agent-memory now owns creation of the
{name}:mem:idxvector search index instead of leaving that to callers or integration tests.A new
buildMemoryIndexhelper builds theFT.CREATEschema (HNSW cosine vector plus TAG/NUMERIC/TEXT fields aligned with writes and recall queries).MemoryStore.ensureIndex()checksFT.INFO, creates the index only when missing (usingisIndexNotFoundError), and picks vector DIM from a prior write or anembedFn('probe')call.AgentMemory.initialize()awaitsensureIndex()before discovery so the facade is ready forremember/recallwithout manual index setup.Hermetic tests cover index args, idempotency, dim resolution, and error propagation; the live integration suite drops its hand-rolled
FT.CREATE(previously FLAT) in favor ofensureIndex()(HNSW).Reviewed by Cursor Bugbot for commit 4728320. Bugbot is set up for automated code reviews on this repo. Configure here.