Python · Refinement

Refinement

from usearch import RefineReport 3.0.0-rc.1 · 4c3e5023

refine re-selects the neighbors of every stored entry against the finished graph, improving edges that were chosen when the graph around them was still incomplete. It is a build step rather than a repair: a cheap insertion pass followed by one refinement reaches a better graph, in less total time, than a single expensive insertion pass, so a wide expansion_factor belongs here rather than in insert.

while index.on(pool).refine(expansion_factor=128).changed > len(index) // 100:
    pass  # Loop until fewer than one node in a hundred still moves an edge

The return is a RefineReport: the nodes re-selected and, of those, changed; the islands found and reconnected; and the reachability audit closing the heal. A caller loops until changed falls below whatever change rate they consider settled. Searches may run throughout on a RAM handle but not on a VRAM one, and a stopped sweep still re-links its islands before raising CancelledError, leaving the graph correct for the next call to sweep again, which is what makes a whole-graph pass affordable under a time budget.

§ Absorbing & Splitting

first.on(pool).absorb(second, third)  # both donors are consumed and must not be used afterwards
first.on(pool).split(left, right, seed=7)  # two empty receivers take a part each, `first` is left empty

Donors are absorbed one after another, each keeping its graph and linked in by walks across the appended part. A later verb on a consumed donor raises UninitializedError, and a stopped absorb cuts only its closing refinement, every donor already consumed. Both answer a RefineReport of their closing refinements.

API

ClassRefineReportWhat one refine-family call did to the graph.5
lib.pyi:1767 ↗
class RefineReport(structseq[Any], tuple[int, int, int, int, DenseReachability])
reselectedEntries whose neighbors were selected again, islands of every heal round included.
lib.pyi:1774 ↗
reselected: int
changedOf those, the entries whose neighbor set gained a member it lacked; zero means settled.
lib.pyi:1779 ↗
changed: int
islands_foundEntries the first audit found not reached both ways.
lib.pyi:1784 ↗
islands_found: int
islands_reconnectedLinks written between an island and an entry reached both ways.
lib.pyi:1789 ↗
islands_reconnected: int
reachabilityThe audit closing the heal, as health would take it right after.
lib.pyi:1794 ↗
reachability: DenseReachability