# Refinement

> USearch for JavaScript

A cheap insertion pass followed by one refinement reaches a better graph, in less total time, than a single expensive insertion pass:

```javascript
const pool = index.on(executor);
pool.insert(keys, vectors, { expansionFactor: 32 });
while (pool.refine({ expansionFactor: 128 }).changed > vectors.rows / 100) {}
```

Each call answers a `DenseRefineReport`: the entries re-selected and changed, the islands found and reconnected, and the closing `reachability` audit.

Refinement is a build step rather than a repair.
It adds and removes nothing, and searches may run throughout.

### Absorbing & Splitting

Bigger indexes come from absorbing, never mutating: `absorb` appends every donor in turn, keeping its graph and linking it in across the appended part, and a donor the library consumed refuses every later verb with `Status.Uninitialized`.
A donor it did not absorb, like one of another scalar refused with `Status.ConfigMismatch`, stays a live index you still own, though its entries may already have moved.
A deferred absorb holds its donors until it is final, so meanwhile they refuse every verb and no other absorb can name them.

```javascript
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 answer the closing refines' report, as `refine` does.

```javascript
index.on(executor).split([left, right], { seed: 42 });
```

`import * as usearch from 'usearch';`

## DenseRefineConfig

Optional per-call settings of the refinement pass that follows an insertion.

```typescript
interface DenseRefineConfig
```

- `expansionFactor?` `number`: Breadth of the candidates the re-selection walk explores; absent lets the engine derive it.
- `stats?` `DenseTraversalStats`: The reading this call overwrites with its own telemetry; absent skips reporting.

## DenseSplitConfig

Optional per-call settings of a split.

```typescript
interface DenseSplitConfig
```

- `seed?` `number | bigint`: Picks the part roots: equal seeds over an unchanged index split equally.
- `expansionFactor?` `number`: Breadth of the candidates of the closing refines' walks; absent lets the engine derive it.

## DenseRefineReport

What one [`refine`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#refine), [`absorb`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#absorb) or [`split`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#split) did to the graph.

```typescript
interface DenseRefineReport
```

- `reselected` `number`: Entries whose neighbors were selected again, the islands of every heal round included.
- `changed` `number`: Of those, the entries whose neighbor set gained a member it lacked; zero means settled.
- `islandsFound` `number`: Entries the first audit found not reached both ways.
- `islandsReconnected` `number`: Links written between an island and an entry the audit reached both ways.
- `reachability` `DenseReachability`: The audit closing the heal, as a fresh [`health`](https://www.unum.cloud/docs/usearch/javascript/metrics.md#health) right after would take it.

