Swift · Refinement

Refinement

import USearch 3.0.0-rc.1 · 4c3e5023

refine re-selects the neighbors of every stored entry against the finished graph and returns a DenseRefineReport: the entries re-selected and changed, the islands found and reconnected, and the closing audit. A cheap insertion pass followed by one refinement reaches a better graph in less total time than one expensive insertion pass. Zero changed means the graph has settled, and searches may run throughout.

while try index.on(executor).refine(config: DenseRefineConfig(expansionFactor: 128)).changed != 0 {}

§ Absorbing & Splitting

Bigger indexes come from absorbing, never mutating: absorb appends every donor’s entries with its graph, then refines across the appended part. It consumes every donor it absorbs, so every later verb on one reports uninitialized, and an absorb stopped early hands the rest back to their indexes.

try index.on(executor).absorb([shard])

split is the inverse: it hands graph-local parts of the index to empty receivers of the same configuration, one part each, keeping their edges and leaving the index empty but live. Both report the closing refines as refine does.

let report = try index.on(executor).split(into: [left, right], config: DenseSplitConfig(seed: 42))

API

StructDenseRefineReportWhat one refine, absorb or split did to the graph.5
DenseIndex.swift:171 ↗
struct DenseRefineReport

Conforms to

Equatable, Sendable
reselectedThe entries whose neighbors were selected again, the islands of every heal round included.
DenseIndex.swift:173 ↗
var reselected: Int
changedOf those, the entries whose neighbor set gained a member it lacked; zero means settled.
DenseIndex.swift:175 ↗
var changed: Int
islandsFoundThe entries the first audit found not reached both ways.
DenseIndex.swift:177 ↗
var islandsFound: Int
islandsReconnectedThe links written between an island and an entry the audit reached both ways.
DenseIndex.swift:179 ↗
var islandsReconnected: Int
reachabilityThe audit closing the heal, as a fresh health right after would take it.
DenseIndex.swift:181 ↗
var reachability: DenseReachability
StructDenseRefineConfigThe knobs of refine.5
DenseIndex.swift:280 ↗
struct DenseRefineConfig

Every zeroed field derives.

expansionFactorThe breadth of the candidates the re-selection walk explores; zero derives it from the geometry.
DenseIndex.swift:282 ↗
var expansionFactor: Int
progressCalled with nodes swept; a stop leaves the graph correct and merely less improved.
DenseIndex.swift:284 ↗
var progress: Progress?
progressStepsReports the call makes at most, the last at completion; zero derives to ten.
DenseIndex.swift:286 ↗
var progressSteps: Int
statsThe traversal telemetry to write.
DenseIndex.swift:288 ↗
var stats: DenseTraversalStats?
init
DenseIndex.swift:290 ↗
init(expansionFactor: Int = 0, progress: Progress? = nil, progressSteps: Int = 0, stats: DenseTraversalStats? = nil)
StructDenseAbsorbConfigThe knobs of absorb.3
DenseIndex.swift:433 ↗
struct DenseAbsorbConfig
progressCalled with donors absorbed.
DenseIndex.swift:435 ↗
var progress: Progress?
progressStepsReports the call makes at most, the last at completion; zero derives to ten.
DenseIndex.swift:437 ↗
var progressSteps: Int
init
DenseIndex.swift:439 ↗
init(progress: Progress? = nil, progressSteps: Int = 0)
StructDenseSplitConfigThe knobs of split.6
DenseIndex.swift:446 ↗
struct DenseSplitConfig

Every zeroed field derives.

seedPicks the part roots: equal seeds over an unchanged index split equally.
DenseIndex.swift:448 ↗
var seed: UInt64
expansionFactorThe breadth of the candidates of the closing refines' walks; zero derives.
DenseIndex.swift:450 ↗
var expansionFactor: Int
progressCalled with nodes the closing refines re-selected; a stop never undoes a move.
DenseIndex.swift:452 ↗
var progress: Progress?
progressStepsReports the call makes at most, the last at completion; zero derives to ten.
DenseIndex.swift:454 ↗
var progressSteps: Int
statsThe traversal telemetry to write.
DenseIndex.swift:456 ↗
var stats: DenseTraversalStats?
init
DenseIndex.swift:458 ↗
init(seed: UInt64 = 0, expansionFactor: Int = 0, progress: Progress? = nil, progressSteps: Int = 0, stats: DenseTraversalStats? = nil)