Commit e0cc001
committed
fix(embedded): race-free len, full alias docstring, faster brute force
- hnsw.rs: `__len__` now reads the count from the underlying HnswIndex
instead of `next_id`. The previous derivation could observe phantom
IDs under concurrent fit/__len__ — `fit` bumps next_id under its own
mutex, releases it, then acquires the index lock for the actual
inserts (with the GIL released around the build). A concurrent
`__len__` between those two windows would see the bumped counter
before the inserts landed. Locking `inner` makes the count reflect
committed inserts only.
- hnsw.rs: `__repr__` now reports the same len source plus a `<busy>`
marker when the index lock is contended (via `try_lock`). Stops a
debug REPL from blocking on a concurrent build.
- hnsw.rs: docstring for the `metric` constructor argument now lists
every accepted alias (cosine/angular, euclidean/l2, dot/dot_product/
ip/inner_product, manhattan/l1) instead of a partial list. The error
message and the parser were already exhaustive; the docstring just
needed to catch up.
- tests/unit/test_hnsw.py: the brute-force top-k helper uses
`np.argpartition` (O(N)) instead of `np.argsort` (O(N log N)) — only
the SET of nearest k matters for the recall metric, not the order
inside it.
- tests/unit/test_hnsw.py: the recall test allocates the 10K × 16 float
matrix directly as float32 via `standard_normal(dtype=np.float32)`
instead of allocating float64 then `.astype(np.float32)`. Halves the
peak memory for that test.1 parent a0eb616 commit e0cc001
2 files changed
Lines changed: 37 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| |||
208 | 213 | | |
209 | 214 | | |
210 | 215 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
215 | 224 | | |
216 | | - | |
217 | | - | |
| 225 | + | |
| 226 | + | |
218 | 227 | | |
219 | 228 | | |
220 | 229 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
228 | 241 | | |
229 | 242 | | |
230 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | | - | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
62 | | - | |
63 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| |||
0 commit comments