InMemoryVectorStore class

A VectorStore that keeps everything in memory.

Embeddings are stored as Float32List, which halves memory compared to doubles at a precision cost that is irrelevant for similarity search. Each document's vector norm is computed once at upsert time, so a search costs one dot product per candidate document.

Search is exact: every candidate is scored. There is no approximate index, which keeps results deterministic and works well up to roughly 100k chunks. See the package README for the measured trade-off.

The store can be serialized with toBytes and restored with InMemoryVectorStore.fromBytes. On the Dart VM and Flutter (not web), package:rag_kit/io.dart adds file-based save and load on top of these.

Inheritance
Available extensions

Constructors

InMemoryVectorStore()
Creates an empty store.
InMemoryVectorStore.fromBytes(Uint8List bytes)
Restores a store from bytes produced by toBytes.
factory

Properties

dimension int?
The embedding dimension of the stored documents, or null while the store is empty.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<void>
Removes all documents.
override
count() Future<int>
The number of stored documents.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeWhere(bool test(Document document)) Future<int>
Removes every document for which test returns true.
override
save(String path) Future<void>

Available on InMemoryVectorStore, provided by the InMemoryVectorStoreFiles extension

Writes the store to the file at path, overwriting it if it exists.
Returns up to topK documents most similar to query, best first.
override
toBytes() Uint8List
Serializes the store to the rag_kit binary format.
toString() String
A string representation of this object.
inherited
upsert(List<Document> documents) Future<void>
Inserts documents, replacing any existing document with the same id.
override

Operators

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