Repository navigation
Conversation
375b63f to
8b766b4
Compare
8b766b4 to
bd27024
Compare
|
Thank you, @ofek! The direction of this work is very important, but even on toy-scale graphs of thousands of nodes, removing half, and reinserting it is penalized by 2-6x on my old Apple M2. The v3, coming later this month, changes the core algorithm, but it can still benefit from similar efforts. Let me think of the best ways to include this work there 🤗 |
`remove` followed by `add` reuses the removed node's slot: `update` rewrites the node at its new position. Whatever was reachable only through its old position is cut off. On points on a line, a search from the far side then misses the whole other half. Before the node moves, search around its old position without ever entering it, nor any node that a concurrent `update` is moving. Each old base-level neighbor that the search doesn't reach gets a link from the nodes it did reach, and a link back, as the moving node gave both ways. The move then drops only the links this bridge accounted for, and keeps those that concurrent insertions added meanwhile. Of two overlapping updates, at least one sees the other's node as moving. The bridge runs only if a neighbor would be left with at most one incoming link, the same threshold as for pruned links, so a move costs about as much as before. unum-cloud#801 by Ofek Lev and unum-cloud#821 by cpegeric fix the same cut. Their tests are here: unum-cloud#821's points on a line and churn rounds, and unum-cloud#801's two bridge tests.
`remove` followed by `add` reuses the removed node's slot: `update` rewrites the node at its new position. Whatever was reachable only through its old position is cut off. On points on a line, a search from the far side then misses the whole other half. Before the node moves, search around its old position without ever entering it, nor any node that a concurrent `update` is moving. Each old base-level neighbor that the search doesn't reach gets a link from the nodes it did reach, and a link back, as the moving node gave both ways. The move then drops only the links this bridge accounted for, and keeps those that concurrent insertions added meanwhile. Of two overlapping updates, at least one sees the other's node as moving. The bridge runs only if a neighbor would be left with at most one incoming link, the same threshold as for pruned links, so a move costs about as much as before. unum-cloud#801 by Ofek Lev and unum-cloud#821 by cpegeric fix the same cut. Their tests are here: unum-cloud#821's points on a line and churn rounds, and unum-cloud#801's two bridge tests.
|
@ofek, #805 now repairs slot reuse in On #821's benchmark, a |
|
@ofek, as promised, here's where v3 lands: #846 proposes removal as an exclusive call that renumbers the survivors instead of reusing deleted slots, so the bridges your tests guard are re-linked as part of the call. Your |
|
That's awesome, thanks! |
Intent
Reusing a deleted slot can make a surviving vector unreachable through graph search. Rebuilding the reused node's outgoing links can remove the only incoming path to a live node. Its key and vector remain present, and exact search still finds it.
A small reproduction uses squared L2 distance with
connectivity=2,connectivity_base=4, andexpansion_search=1000:(10, 0, 0),(0, 0, 0), and(-1, 0, 0).(0, 0, 0)and add(3000, 0, 0), reusing the deleted slot.(0, 0, 0). Before the fix, graph search returns(10, 0, 0)while exact search returns the surviving nearest vector,(-1, 0, 0).Changes
The fix preserves graph reachability in the reproduced slot-reuse and direct-update cases. It reconnects the updated node's former neighbors without discarding their links to other surviving vectors. Reserving room for reverse links prevents later pruning from undoing that repair.
Existing callers and saved indexes remain compatible: the public API, serialized format, and timing of the success callback are unchanged. Updates perform additional local graph work within the existing degree limits and reuse temporary storage across calls.
Validation
The regression tests verify that every surviving vector in each fixture remains reachable, because key lookup alone cannot detect this failure. They also exercise the reverse-link step with one and two free slots and assert that existing edges survive, guarding against a second pruning pass undoing the repair. Both 32-bit and packed 40-bit slots are covered.
The full C++ suites used Release builds with NumKong, OpenMP, and JeMalloc disabled. The focused commands use a local harness generated from the committed regression tests.
ctest --test-dir build/deleted-slot-release --output-on-failure --timeout 240Windows x64, MSVC, C++17. Full C++ suite:
ctest --test-dir "$native_dir/build" --output-on-failure --timeout 240Linux under WSL, GCC, C++17. The build directory was configured with
USEARCH_BUILD_TEST_CPP=ON,USEARCH_BUILD_BENCH_CPP=OFF, andCMAKE_BUILD_TYPE=Release. Full C++ suite:./focused.exeWindows x64, Clang, C++17,
-O1. Focused regression cases:ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=halt_on_error=1 ./focusedLinux under WSL, GCC, C++11,
-O1 -g1 -pthread -fsanitize=address,undefined -fno-omit-frame-pointer. Focused regression cases exited with status 0 and no sanitizer diagnostics:Disabling reverse-link capacity reservation makes each new fixture fail independently, confirming that both tests detect the intended regression.
./focused-mutated 1Linux GCC, C++11. One free slot before repair. Expected failure, exit status 1:
./focused-mutated 2Linux GCC, C++11. Two free slots before repair. Expected failure, exit status 1:
clang-format --dry-run --Werror -lines=3394:3415 -lines=4330:4386 include/usearch/index.hpp && clang-format --dry-run --Werror -lines=1248:1252 -lines=1277:1383 cpp/test.cpp && git diff --checkChanged-line formatting and whitespace checks exited with status 0: