curl -s 'https://www.unum.cloud/docs/usearch/cpp/refinement.md' | claude -p "How would this fit my code?"
refine re-runs the neighbor selection over entries already in the graph and answers a usearch_refine_report_t of the nodes re-selected, those whose neighbors changed, the islands found and reconnected, the neighborhoods re-stitched with the links added and dropped, the verdict, and the opening and reachability health checks around the round, so a batch built at a low expansion factor reaches the quality of a slower build afterwards.
A verdict other than usearch_refine_improved_k is what settled looks like.
On a RAM handle searches may run throughout, on a VRAM one they may not, and insertions never may.
On a loaded NVMe handle memory_limit bounds the bytes a round holds for the one part it rewrites: zero rounds the part in RAM, and a smaller budget streams its rounds from the drives.
A dense_refine_plan_t carries a round across calls: a stop leaves it live, the next call holding it continues where it stopped, phase reports the phase the call stopped in, and refine_plan_finish closes it.
us::dense_refine_plan_t plan;while (receiver.refine({.progress = {before_the_deadline}, .plan = &plan}) == us::status_code_t::cancelled_k) std::printf("stopped in %s at %zu of %zu\n", usearch_phase_name(plan.phase().phase), plan.phase().completed, plan.phase().total);auto [report, status] = receiver.refine_plan_finish(std::move(plan));
A deferred call reads and writes the plan it carries, which stays where it is until the call is final.
reshard moves the entries of its sources into its targets, keeping their links rather than re-inserting their entries, then runs a round on every target that took entries; the receiver supplies the executor.
Several sources gather into the one target among them, one source cuts into several empty targets, and one handle alone recuts its own shards in place under shard_capacity.
Every handle stays yours: a source the targets do not name ends empty and live.
Readers of a RAM target may keep searching throughout, while a VRAM one admits no overlapping search.
usearch_dense_index_t const gathered[3] = {index.handle(), first_shard.handle(), second_shard.handle()};us::status_t const gather = index.on(executor).reshard(gathered, {gathered, 1}).status;usearch_dense_index_t const source[1] = {index.handle()}, parts[2] = {left.handle(), right.handle()};us::status_t const cut = index.on(executor).reshard(source, parts).status; // two empty targets take a part each
A stopped reshard cuts only its closing rounds, every entry already moved, and reports status_code_t::cancelled_k; a dense_reshard_plan_t continues it as a refine plan does, and reshard_plan_finish closes it.
API
Types
refine_configThe knobs of refine and the plan_type_ it opens or continues.