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
-
- Object
- VectorStore
- InMemoryVectorStore
- Available extensions
Constructors
- InMemoryVectorStore()
- Creates an empty store.
- InMemoryVectorStore.fromBytes(Uint8List bytes)
-
Restores a store from bytes produced by toBytes.
factory
Properties
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
testreturns true.override -
save(
String path) → Future< void> -
Available on InMemoryVectorStore, provided by the InMemoryVectorStoreFiles extension
Writes the store to the file atpath, overwriting it if it exists. -
search(
List< double> query, {int topK = 5, double? minScore, bool where(Document document)?}) → Future<List< ScoredChunk> > -
Returns up to
topKdocuments most similar toquery, 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