# Refinement

> USearch for Python

`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`.

```python
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

```python
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.

`from usearch import RefineReport`

## RefineReport

What one refine-family call did to the graph.

```python
class RefineReport(structseq[Any], tuple[int, int, int, int, DenseReachability])
```

## reselected

Entries whose neighbors were selected again, islands of every heal round included.

```python
reselected: int
```

## changed

Of those, the entries whose neighbor set gained a member it lacked; zero means settled.

```python
changed: int
```

## islands_found

Entries the first audit found not reached both ways.

```python
islands_found: int
```

## islands_reconnected

Links written between an island and an entry reached both ways.

```python
islands_reconnected: int
```

## reachability

The audit closing the heal, as [`health`](https://www.unum.cloud/docs/usearch/python/metrics.md#health) would take it right after.

```python
reachability: DenseReachability
```

