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
searchis 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
vunder keyid. Dim must match dim. -
getVector(
int i) → Vector -
Read row
ias 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. -
search(
Vector query, int k, {VectorMetric? metric}) → List< VectorSearchHit> -
Return the top-
knearest neighbors ofqueryundermetric(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