FlatIndex class

Brute-force nearest-neighbor index (FAISS IndexFlatL2 / IndexFlatIP equivalent). Stores every added vector verbatim in a contiguous Float32List and scans them on each query.

This is deliberately the simplest possible index: no clustering, no approximation, no build step. It is the reference implementation the planner falls back to when no ANN index is present, and it also serves as ground truth for any future HNSW/IVF layer.

Constructors

FlatIndex(int dim, {VectorMetric defaultMetric = VectorMetric.l2sq})

Properties

defaultMetric → VectorMetric
Default metric used when search is called without one.
final
dim → int
Vector dimension. Every vector added must have this dim.
final
hashCode → int
The hash code for this object.
no setterinherited
length → int
Number of vectors currently stored.
no setter
liveIds → Iterable<Object?>
V50: snapshot of live ids in insertion order.
no setter
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. Dim must match dim.
getVector(int i) → Vector
Read row i as a fresh Vector (copy). Mainly for tests.
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. Returns true if something was removed. O(N) — this class is meant for small-to- medium in-memory indices; a paged variant is a follow-up.
Return the top-k nearest neighbors of query under metric (defaults to defaultMetric). Result is sorted best-first — smallest first for L2/cosine, largest first for inner-product.
toJson() → Map<String, Object?>
Serialize the entire built state to a JSON-encodable map. Used by the SQL layer to persist warmed indexes across close() / reopen.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

fromJson(Map<String, Object?> j) → FlatIndex
Reconstruct a FlatIndex from toJson output. Throws on any structural mismatch so callers can fall back to a fresh build.