Repository navigation
fix(memory): keep exported semantic vectors through memory import - #25775
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The import keeps a vector only when the payload names its model, that model produces the payload's signature, and the signature matches the store and the active backend. Any other row lands without a vector, as it does today. Notes
[DESIGN-REVIEWED] 2a85be5 Description read[DESCRIPTION-READ] 725d77fb09f9a7950e421362d462087dc238b1828ae3bdfb4add4ffb7e3bd040 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. One payload key repeats what the signature already proves. Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: after a CLI memory export and import, imported facts can be found by meaning straight away, not only by keyword. FIX (#9732).
[FIRST-PRINCIPLES-REVIEWED] 2a85be5 Description read[DESCRIPTION-READ] b34cb5c1345ff09aff55a4c0e5b34f1a59b6dffcd6ffefaef8ee5d4d977c097f That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
6bb8e8f to
9201905
Compare
9201905 to
2a85be5
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
Approve at 2a85be5.
The import keeps an exported vector only on a store that cannot compute it, only when the payload's model and width produce its signature, and only when that signature matches both the store and the active backend (bulk_ingest.py#L70-L110). Each vector must decode to exactly dim finite floats (#L113-L126), and the space token travels with it, so a reconcile before commit drops it. Anything else lands without a vector, as it does on main. Every AI lane passes; the cancelled check runs are superseded by newer successes; PR Readiness is green.
AI findings judged non-blocking
- First Principles:
embedding_modelrepeats what the signature proves. It only makes the carry rule stricter; a refused payload falls back to today's behaviour, and the key was asked for on #10388 (bulk_ingest.py#L43-L67).
— crew-pr-reviewer (r135)
Problem / Motivation
Goal: after
kirocrew memory exportandkirocrew memory import, semantic rows are vector-searchable at once instead of keyword-only.import_memorywrites every semantic row with no vector. The CLI store has no embedder, so the row's own embed tail never runs, andmemory exportwrites each stored vector BLOB throughjson.dumps(..., default=str), which produces a bytesreprthat nothing can read back.Why it matters
After a restore, recall over the imported facts silently finds nothing by meaning until a gateway boot sweep re-embeds them, and the import summary does not say so for semantic rows. The export file also carries a large unreadable string per row.
Not a goal
POST /api/memory/import): its store has an embedder and keeps embedding rows itself.Intended? / Repro
Intended? No. The issue describes the import as asymmetric by accident, and the CLI's own note (
_IMPORT_EMBED_NOTEinsrc/kiro_crew/cli_commands_memory.py) treats a vector-less import as a gap to warn about, not a design. The write path already accepts a resolved vector (set_semantic(..., embedding=, embedding_resolved=, embedding_generation=), added for pre-embedding callers), so nothing forbids carrying one.Repro (read on current main
6b5bedad1b):src/kiro_crew/vector_memory_runtime/bulk_ingest.py:175:self.set_semantic(entry["key"], val, conf, src)passes no vector, while the episodic branch at:185passesembedding=self._try_embed(...).src/kiro_crew/vector_memory_runtime/semantic.py:1368: the semantic write tail embeds only whenstore.embed_fn is not None; the CLI store has none, so the row stays NULL.src/kiro_crew/cli_commands_memory.py:1089exportsstore.get_all_semantic()(which includes theembeddingBLOB) and:1098serializes it withdefault=str.SELECT count(*), sum(embedding IS NOT NULL) FROM semantic_memory WHERE is_deleted=0).What changed (motivation → approach → change)
Symptom: imported semantic rows have no vector. Cause: the export's vector is unreadable and the import never passes one. Change: export a readable vector plus the model it came from, and let the import keep it only where that model is provably the one this store uses.
cli_commands_memory.py): each semantic row's vector BLOB ships as base64 of its float32 bytes. When at least one ships, the payload ends withembedding_space_sigandembedding_model: {"model_id", "dim"}(bulk_ingest.export_embedding_space). The model is named only when this process can produce the signature from a model id and width: the bundled model (the owner of any unrecorded space) or the active backend (metadata only, no model load); otherwisenull. The signature is read before and after the row read, and both keys arenullif a model swap committed in between. A payload with no vectors keeps its previous shape byte for byte.bulk_ingest.import_memory): a row's vector is persisted as it is only when_payload_space_carryableholds: the store has no embedder; the payload names its model; that model and width produce the payload's signature; the width matches the store; and the signature equals both the store's recorded space (unrecorded counts as the bundled model's, as instore_embedding_space_is_stale) and the active backend's, with no pending rebuild. Each vector must decode to exactlydimfinite float32 values, so a legacyreprstring, a wrong width or a NaN is dropped and that row lands NULL as before. The vector is wrapped in_EmbeddingVectorwith the store's space token read at the decision, so the publish transaction (_vector_commit/_embedding_current) drops it if a reconcile lands before it commits. A store with an embedder ignores payload vectors and embeds the row's own text.docs/system-specs/modules/cli.md: the export/import row describes the vector fields and the carry rule.Review item from #10388 (iamwhatever, CHANGES_REQUESTED)
Addressed: the export ships
embedding_model: {"model_id", "dim"}besideembedding_space_sig, and the import requires it. A payload without a model, or whose model does not produce its own signature, carries no vectors (testsno-model,model-not-matching-signature,bool-dim).Security
The payload is user-supplied input. A carried vector is only accepted at the store's exact width, as finite float32 values, under a signature that must match the store and the active backend, and only on a store that cannot compute the vector itself. The worst a hand-edited payload can do is mis-rank its own imported rows; row text and keyword search are unaffected, and a dashboard (embedder-backed) import never trusts payload vectors. No new endpoint, file path or permission.
Backwards compatibility
embedding_model, so nothing is carried and rows land NULL as before.embeddingfields, which the old importer ignores.test/test_memory_markdown_read.pyis unchanged; its stub gainsrecorded_embedding_space).Removes nothing: no key, field or error path is removed. The semantic
embeddingfield changes from an unreadablereprstring to base64.Tests
test/test_vector_memory_coverage.py::TestImportCarriesExportedVectorstest_vector_from_the_same_model_is_persisted: the exact float32 vector lands insemantic_memory.embedding. On main it is NULL.test_unusable_vector_imports_the_row_without_it(no model, model not matching the signature, bool dim, foreign space, legacy repr, wrong width, non-finite): row imported, vector NULL.test_model_swap_during_the_space_check_drops_the_vector: a reconcile landing while the space is judged leaves the row NULL, because the space token is read once before the check and the commit re-checks it.test_store_in_another_space_does_not_take_the_vector: an unrecorded (bundled) store refuses a custom-model payload.test_store_with_an_embedder_embeds_the_row_itself: the store's own vector wins.test_export_names_the_model_of_its_vectors,test_unrecorded_store_exports_the_bundled_model.test/test_cli_commands_coverage_memory_eval.py: export ships base64 plus the two keys last; both keysnullwhen the space changed during the read; the import note prints for semantic-only imports.Proof: not provable -- other: this host runs no local tests; CI runs the new tests
Manual verification
N/A: no UI. Static gates run locally: black (diff region), isort, flake8,
scripts/check_file_line_cap.py,scripts/docs_lint.py,scripts/check_comment_history.pywithCOMMENT_HISTORY_BASE_REF=origin/main. Tests run in CI.Why no screenshot: CLI and storage change only; no dashboard or website file is touched.
Related Issues
Fixes #9732
Supersedes #10388. That PR predates the split of
vector_memory.pyintovector_memory_runtime/*and also changed episodic export, streaming and--no-vectors; this one is the smallest fix on current main.Sibling sweep
Swept: git grep -n -E "import_memory(|default=str" -- src/kiro_crew
Sibling: src/kiro_crew/cli_commands_memory.py -- changed here (the only export that serializes vector BLOBs)
Sibling: src/kiro_crew/dashboard/handlers/memory.py -- not affected (its store has an embedder, so it embeds each row itself)
Pattern harvest
Rule candidate: a value restored from an export may be trusted only where it cannot be recomputed and its provenance (here, model id + width → signature) matches the destination exactly; carry the destination's state token with it so the commit re-checks the match under its own lock.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.