@@ -101,14 +101,32 @@ impl MemoryEngine {
101101 let state = MemoryState :: load ( & config. state_path ( ) ) ?;
102102 let document_index = DocumentIndexManifest :: load ( & config. document_index_path ( ) ) ?;
103103 let graph = GraphStore :: load ( & config. graph_state_path ( ) , & config. graph_pending_path ( ) ) ?;
104+ let switch_store =
105+ ModelSwitchStore :: load ( & config. model_switch_path ( ) , config. project_id ( ) ) ?;
104106 let persisted_active =
105107 ActiveEmbedding :: load ( & config. active_embedding_path ( ) , config. project_id ( ) ) ?;
106- if let Some ( active) = & persisted_active
107- && active. profile_id != "legacy-custom"
108- {
109- let embedding =
110- crate :: model:: embedding_config_for_profile ( & active. profile_id , config. embedding ( ) ) ?;
111- config. set_embedding ( embedding) ;
108+ if let Some ( active) = & persisted_active {
109+ if active. profile_id == "legacy-custom" {
110+ if let Some ( embedding) = switch_store
111+ . current
112+ . iter ( )
113+ . chain ( switch_store. history . iter ( ) . rev ( ) )
114+ . find ( |job| {
115+ job. phase == crate :: embedding_generation:: SwitchPhase :: Succeeded
116+ && job. target_generation_id == active. generation_id
117+ && job. target_profile_id == active. profile_id
118+ } )
119+ . and_then ( |job| job. target_embedding . clone ( ) )
120+ {
121+ config. set_embedding ( embedding) ;
122+ }
123+ } else {
124+ let embedding = crate :: model:: embedding_config_for_profile (
125+ & active. profile_id ,
126+ config. embedding ( ) ,
127+ ) ?;
128+ config. set_embedding ( embedding) ;
129+ }
112130 }
113131 let embedder = LlamaCppEmbedder :: load ( config. embedding ( ) , config. model_cache ( ) ) ?;
114132 let active_embedding = match persisted_active {
@@ -157,9 +175,6 @@ impl MemoryEngine {
157175 now_ms ( ) ?,
158176 ) ?
159177 } ;
160- let switch_store =
161- ModelSwitchStore :: load ( & config. model_switch_path ( ) , config. project_id ( ) ) ?;
162-
163178 let mut engine = Self {
164179 config,
165180 collection,
0 commit comments