IvfFlatIndex class

Cell-probe inverted-file index over dense vectors. FAISS IndexIVFFlat port.

Lifecycle: train(samples)add(id, v)…search(q, k).

Parameters:

  • nlist — number of Voronoi cells (k-means centroids). Larger = smaller lists (faster search) but need more training data.
  • nprobe — how many nearest cells to scan at query time. 1 lower-bound (fastest, lowest recall); nlist upper-bound (equivalent to a Flat scan).
  • defaultMetric — scoring metric at search time. The coarse quantizer is always L2 (matches FAISS).

Constructors

IvfFlatIndex(int dim, {required int nlist, int nprobe = 1, VectorMetric defaultMetric = VectorMetric.l2sq, int seed = 1234, int niter = 25})

Properties

defaultMetric VectorMetric
final
dim int
final
hashCode int
The hash code for this object.
no setterinherited
isTrained bool
no setter
length int
no setter
liveIds Iterable<Object?>
V50: snapshot of all ids across every cell.
no setter
nlist int
final
nprobe int
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(Object? id, Vector v) → void
Add v under key id. Requires train to have been called.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeId(Object? id) bool
Remove the first entry whose id equals id. O(nlist + cellSize).
Top-k nearest neighbors of query under metric (or defaultMetric). Optional per-call nprobe overrides the field.
toJson() Map<String, Object?>
Serialize the trained coarse quantizer + every populated cell.
toString() String
A string representation of this object.
inherited
train(List<Vector> samples) → void
Train the coarse quantizer on samples. Must be called once before add. samples should be representative of the data distribution and contain at least nlist vectors.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

fromJson(Map<String, Object?> j) IvfFlatIndex
Reconstruct an IvfFlatIndex from toJson output.