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
feat(kb): switching the embedding model rebuilds into a new collection in the background and cuts over on completion #19379
Start: a switch request starts a background job that re-embeds every fact from the system of record (fact_store.iter_facts, Postgres) into a NEW collection named for the target model (autobot_memory stays as it is), with its embedding provenance stamped (autobot_shared/embedding_provenance.py).
Progress: done/total and errors are reported via a status endpoint.
During the build: search and writes keep using the old collection; facts written during the build are also queued into the new one.
Cutover, only on a completed build: the KB's vector store switches to the new collection and the resolver override is set to the new model, atomically from the reader's view.
Failure: a failed or cancelled build leaves the active model and collection unchanged, and says why.
The old collection is not touched (its deletion is the next child).
Acceptance criteria
Search answers from the old collection during the build (test).
Cutover happens only after a complete build; failure leaves everything as it was (tests).
Design constraint from the #19383 review. This is dormant until this issue lands.
active_embedding_model() feeds the KB init, services.npu_client and the embedding-cache keys. Once set_embedding_model_override() is called, queries are embedded with the new model. The KB collection, however, still holds vectors from the old model, and their dimensions may differ.
AC proposal for this issue:
this rebuild is the only caller of set_embedding_model_override();
it fails closed: the override is written only after the new collection is fully built and verified;
a guard test fails on any second caller of the setter.
Cutover only with zero failures. Any fact that fails to embed blocks the cutover. The job reports the failed fact ids, and the active model and collection stay as they were.
Admins only start a switch (admin permission, like the other embedding settings endpoints). A switch is a full re-embed of every fact.
Design notes from mapping the code (origin/main ~129148ebe9):
The KB's collection binding is several attributes: _async_chroma_collection, vector_store, _write_buffer (its flush_fn closes over the old store), the lazy vector_index, and the collection name (knowledge/base.py:395-416). A cutover must drain the write buffer and rebind all of them.
The KB singleton is per process, and Celery holds its own (knowledge_factory.py:23). So the active space has to be one persisted record (model + collection + dim + generation). Each process rebinds when the generation changes. The query-side model and the collection then come from the same record, so a search can't mix spaces.
fact_store.iter_facts deliberately excludes facts created after the walk starts, so writes during the build are recorded and replayed before cutover.
The new collection is created stamped with embedding provenance (cognition_seeder.py:178 pattern). The KB collection is unstamped today.
Checked against main (f88cd37 or later): each row was read from the code, and the tests and paths named were confirmed to exist there. Tests were not run for this comment.
AC
Evidence
Search answers from the old collection during the build (test).
MET. autobot-backend/knowledge/embedding_switch.py_build writes only to a new store from _open_collection(kb, run.collection, ...). kb is not rebound until _cut_over. Test: autobot-backend/knowledge/embedding_switch_test.py::test_the_kb_stays_on_its_old_collection_while_the_build_runs; also autobot-backend/knowledge/embedding_switch_test.py::test_the_active_space_is_untouched_until_the_build_completes.
Cutover happens only after a complete build; failure leaves everything as it was (tests).
MET. run_switch returns via _finish(run, "failed", ...) if failed_ids or not converged ("cutover needs zero failures") before _cut_over. set_embedding_model_override is called only in _cut_over (:381), after the settle script. Tests: autobot-backend/knowledge/embedding_switch_test.py::test_a_complete_build_cuts_over_after_every_fact_is_in, autobot-backend/knowledge/embedding_switch_test.py::test_one_failed_fact_blocks_the_cutover, autobot-backend/knowledge/embedding_switch_test.py::test_a_cancel_stops_before_cutover, autobot-backend/knowledge/embedding_switch_test.py::test_a_build_past_its_deadline_fails_without_switching. Single-writer guard (from the comment's proposal): repo_tests/embedding_override_single_writer_19379_test.py.
Progress is visible through an endpoint.
MET. autobot-backend/api/embeddings.py:289@router.get("/switch/status")get_embedding_switch_status, backed by switch_status(). The router is mounted at /embeddings (autobot-backend/initialization/router_registry/feature_routers.py:196). Also POST /switch (:259, admin only via check_admin_permission) and DELETE /switch (:302). Body bullets: autobot_memory is untouched (a new collection from target_collection), and the collection is stamped via provenance_to_metadata(EmbeddingProvenance(model, dim)).
Activity
mrveiss commentedon Oct 23, 2026
Design constraint from the #19383 review. This is dormant until this issue lands.
active_embedding_model()feeds the KB init,services.npu_clientand the embedding-cache keys. Onceset_embedding_model_override()is called, queries are embedded with the new model. The KB collection, however, still holds vectors from the old model, and their dimensions may differ.AC proposal for this issue:
set_embedding_model_override();mrveiss commentedon Oct 25, 2026
Maintainer decisions (2026-10-25):
Design notes from mapping the code (origin/main ~129148ebe9):
_async_chroma_collection,vector_store,_write_buffer(itsflush_fncloses over the old store), the lazyvector_index, and the collection name (knowledge/base.py:395-416). A cutover must drain the write buffer and rebind all of them.knowledge_factory.py:23). So the active space has to be one persisted record (model + collection + dim + generation). Each process rebinds when the generation changes. The query-side model and the collection then come from the same record, so a search can't mix spaces.fact_store.iter_factsdeliberately excludes facts created after the walk starts, so writes during the build are recorded and replayed before cutover.cognition_seeder.py:178pattern). The KB collection is unstamped today.set_embedding_model_override(), pinned by a guard (the constraint from code review on PR refactor(kb): one runtime embedding-model resolver with a user override; readers routed through it; dead copies retired (#19377) #19383).fix(kb): the embedding switch survives a dead worker, and a query nev…
fix(kb): the switch heartbeats before each batch and before the final…
test(guards): re-pin three reach floors mid-window, their populations…
fix(kb): the switch's heartbeat and lock release are atomic -- expire…
fix(kb): CodeRabbit round on the embedding switch -- a worker that lo…
test(guards): re-pin two reach floors mid-window, their populations g…
fix(kb): cancel and cutover are atomic (cancel only while building, s…
fix(train): the embedding-model namespace strip uses partition and a …
fix(train): the search tests expect the bound space's store argument …
fix(train): the bound-store collection read in _query_chromadb stays …
github-actions commentedon Oct 28, 2026
Landed in train train-2026-10-28-86b (#19880, merge
0b473f2ed5) via #19641mrveiss commentedon Nov 1, 2026
Checked against
main(f88cd37 or later): each row was read from the code, and the tests and paths named were confirmed to exist there. Tests were not run for this comment.autobot-backend/knowledge/embedding_switch.py_buildwrites only to a new store from_open_collection(kb, run.collection, ...).kbis not rebound until_cut_over. Test:autobot-backend/knowledge/embedding_switch_test.py::test_the_kb_stays_on_its_old_collection_while_the_build_runs; alsoautobot-backend/knowledge/embedding_switch_test.py::test_the_active_space_is_untouched_until_the_build_completes.run_switchreturns via_finish(run, "failed", ...)iffailed_ids or not converged("cutover needs zero failures") before_cut_over.set_embedding_model_overrideis called only in_cut_over(:381), after the settle script. Tests:autobot-backend/knowledge/embedding_switch_test.py::test_a_complete_build_cuts_over_after_every_fact_is_in,autobot-backend/knowledge/embedding_switch_test.py::test_one_failed_fact_blocks_the_cutover,autobot-backend/knowledge/embedding_switch_test.py::test_a_cancel_stops_before_cutover,autobot-backend/knowledge/embedding_switch_test.py::test_a_build_past_its_deadline_fails_without_switching. Single-writer guard (from the comment's proposal):repo_tests/embedding_override_single_writer_19379_test.py.autobot-backend/api/embeddings.py:289@router.get("/switch/status")get_embedding_switch_status, backed byswitch_status(). The router is mounted at/embeddings(autobot-backend/initialization/router_registry/feature_routers.py:196). AlsoPOST /switch(:259, admin only viacheck_admin_permission) andDELETE /switch(:302). Body bullets:autobot_memoryis untouched (a new collection fromtarget_collection), and the collection is stamped viaprovenance_to_metadata(EmbeddingProvenance(model, dim)).