Commit aa84fa4
feat(repair): preserve embeddings on rebuild — cherry-pick of upstream MemPalace#1367 (embeddings portion only)
Cherry-picks the `_extract_drawers` embeddings-preserve fix from upstream
PR MemPalace#1367 (@zhapostolski), per the cherry-pick evaluation in
#31 and @messelink's review guidance: take the
embeddings fix, SKIP the divergence-floor cap (which would re-create
_refresh_vector_disabled_flag false-positives on our sync_threshold=
50000 palace per MemPalace#1287's design).
What the embeddings-preserve fix does:
- _extract_drawers now includes "embeddings" in the col.get() call
- Returns a 4-tuple: ids, docs, metas, embeddings (or None when any
embedding slot is missing — HNSW unreadable case)
- _rebuild_collection_via_temp accepts an all_embeddings= kwarg and
passes embeddings through to upsert() when available
- rebuild_index threads embeddings from _extract_drawers into
_rebuild_collection_via_temp
When embeddings ARE available (the common case), rebuild skips ONNX
recomputation entirely. On a 150K+ palace this cuts rebuild from hours
to minutes. Fallback to recompute when any embedding is None (the bug
condition we're trying to repair).
Updates two call sites in mempalace/cli.py (the cmd_repair path) and
mempalace/repair.py (the rebuild_index path) for the new 4-tuple
signature.
Adds 3 tests:
- test_extract_drawers_preserves_embeddings_when_all_present
- test_extract_drawers_falls_back_to_none_when_any_embedding_missing
- test_extract_drawers_embeddings_absent_in_batch_signals_recompute
Plus updates the existing 5 _extract_drawers tests to unpack the new
4-tuple. All 75 tests pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 18606af commit aa84fa4
3 files changed
Lines changed: 127 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1378 | 1378 | | |
1379 | 1379 | | |
1380 | 1380 | | |
1381 | | - | |
1382 | | - | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
1383 | 1388 | | |
1384 | 1389 | | |
1385 | 1390 | | |
| |||
1422 | 1427 | | |
1423 | 1428 | | |
1424 | 1429 | | |
| 1430 | + | |
1425 | 1431 | | |
1426 | 1432 | | |
1427 | 1433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
133 | 148 | | |
134 | 149 | | |
135 | 150 | | |
| 151 | + | |
136 | 152 | | |
137 | 153 | | |
138 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
139 | 159 | | |
140 | 160 | | |
141 | 161 | | |
| |||
151 | 171 | | |
152 | 172 | | |
153 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
154 | 185 | | |
155 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
156 | 190 | | |
157 | 191 | | |
158 | 192 | | |
| |||
194 | 228 | | |
195 | 229 | | |
196 | 230 | | |
| 231 | + | |
197 | 232 | | |
198 | 233 | | |
199 | 234 | | |
200 | 235 | | |
201 | 236 | | |
202 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
203 | 243 | | |
204 | 244 | | |
205 | 245 | | |
| |||
210 | 250 | | |
211 | 251 | | |
212 | 252 | | |
213 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
214 | 257 | | |
215 | 258 | | |
216 | 259 | | |
| |||
225 | 268 | | |
226 | 269 | | |
227 | 270 | | |
228 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
229 | 275 | | |
230 | 276 | | |
231 | 277 | | |
| |||
755 | 801 | | |
756 | 802 | | |
757 | 803 | | |
758 | | - | |
759 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
760 | 811 | | |
761 | 812 | | |
762 | 813 | | |
| |||
793 | 844 | | |
794 | 845 | | |
795 | 846 | | |
| 847 | + | |
796 | 848 | | |
797 | 849 | | |
798 | 850 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
167 | 223 | | |
168 | 224 | | |
169 | 225 | | |
| |||
0 commit comments