InMemoryVectorStore class final

Holds vectors in memory and scans them exhaustively.

final store = InMemoryVectorStore(dimensions: 3);
await store.upsertOne(VectorRecord(
  id: 'doc-1',
  vector: [0.1, 0.9, 0.0],
  text: 'Dart supports pattern matching.',
  metadata: {'lang': 'dart'},
));

final hits = await store.searchVector(
  [0.1, 0.8, 0.1],
  filter: MetadataFilter.equals('lang', 'dart'),
);
Implemented types
Available extensions

Constructors

InMemoryVectorStore({required int dimensions, SimilarityMetric metric = SimilarityMetric.cosine, int? maxRecords, String name = 'in-memory'})
Creates an empty index of fixed width.
InMemoryVectorStore.fromJson(JsonMap json)
Restores a store from snapshot.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
info VectorStoreInfo
What this store is.
final
length int
How many records are held across every namespace.
no setter
maxRecords int?
Upper bound on records held across all namespaces, or null for none.
final
namespaces Iterable<String>
The namespaces that currently hold anything.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkDimensions(List<VectorRecord> records) → void

Available on VectorStore, provided by the VectorStoreOperations extension

Validates records against this store's dimensions.
checkNamespace(String? namespace) → void

Available on VectorStore, provided by the VectorStoreOperations extension

Validates namespace against this store's capabilities.
clear({String? namespace}) Future<void>
Removes everything in namespace, or everywhere when it is null.
override
count({String? namespace, MetadataFilter? filter}) Future<int>
How many records are stored, optionally restricted by filter.
override
delete(Iterable<String> ids, {String? namespace}) Future<int>
Removes the records with ids, returning how many existed.
override
deleteOne(String id, {String? namespace}) Future<bool>

Available on VectorStore, provided by the VectorStoreOperations extension

Removes one record, returning whether it existed.
deleteWhere(MetadataFilter filter, {String? namespace}) Future<int>
Removes every record matching filter, returning how many were removed.
override
dispose() Future<void>
Releases every resource held by this object.
exists(String id, {String? namespace}) Future<bool>

Available on VectorStore, provided by the VectorStoreOperations extension

Whether a record with id exists.
get(String id, {String? namespace}) Future<VectorRecord?>
Returns the record with id, or null.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
Returns the records nearest to query.
override
searchVector(List<double> vector, {int topK = 8, MetadataFilter? filter, double minScore = 0, bool includeVectors = false, String? namespace, AgenticContext? context}) Future<List<VectorMatch>>

Available on VectorStore, provided by the VectorStoreOperations extension

Searches with a raw vector.
snapshot() → JsonMap
Serialises the whole index, vectors included.
toString() String
A string representation of this object.
override
upsert(List<VectorRecord> records, {String? namespace, AgenticContext? context}) Future<void>
Inserts or replaces records.
override
upsertAll(Iterable<VectorRecord> records, {String? namespace, AgenticContext? context}) Future<int>

Available on VectorStore, provided by the VectorStoreOperations extension

Upserts records in batches of VectorStoreInfo.maxUpsertBatch.
upsertOne(VectorRecord record, {String? namespace, AgenticContext? context}) Future<void>

Available on VectorStore, provided by the VectorStoreOperations extension

Upserts a single record.

Operators

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