FileVectorStore class final

A VectorStore that snapshots itself to a file after every mutation.

Open it with FileVectorStore.open and pass it to Retriever the same way as InMemoryVectorStore. A later process that opens the same path sees the same documents and the same search ranking, without embedding the corpus again.

This is the in-memory index plus a file, not a database:

  • Loads everything on open. open reads the whole file into RAM. Search then scores every document, the same as InMemoryVectorStore: exact cosine, where applied before scoring, insertion order on tied scores.
  • Rewrites the whole file on every write. upsert, removeWhere and clear each replace path with a full snapshot. Retriever.addText calls upsert then removeWhere, so a re-index is two full writes.
  • Scale. The same ceiling as InMemoryVectorStore: practical to roughly 100k chunks (about 300 MB as float32 at 768 dimensions). Past that, search time and the rewrite on every mutation both hurt. This store does not become reasonable at a million vectors.
  • One writer. Two processes, or two FileVectorStore instances, pointing at the same path will overwrite each other. There is no lock, no write-ahead log, and no merge.
  • Not fsync, not a checksum. The write goes to a temporary file that is renamed into place, so a crash mid-write cannot destroy a previously saved index. A crash after the in-memory update and before that rename, or a power loss that drops buffers the OS has not flushed, leaves the previous snapshot on disk. Single flipped bits inside embedding data are not detected. This is not a durability guarantee.
  • Each method is its own snapshot. A crash between the upsert and the removeWhere inside Retriever.addText can leave a shorter re-index with its old tail still stored.

Dart VM and Flutter only. Import package:rag_kit/io.dart. Web applications should keep using InMemoryVectorStore.toBytes. The file format is the one documented on InMemoryVectorStore.toBytes.

import 'package:rag_kit/io.dart';

final store = await FileVectorStore.open('index.bin');
final retriever = Retriever(embedder: myEmbedder, store: store);
await retriever.addText(text, sourceId: 'handbook');

// Later, in another process, without embedding the corpus again:
final reopened = await FileVectorStore.open('index.bin');
final hits = await Retriever(embedder: myEmbedder, store: reopened)
    .retrieve('how do I request leave?');
Inheritance

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
path String
Path of the snapshot file this store reads and writes.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<void>
Removes all documents.
override
close() Future<void>
Writes the current snapshot to path.
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
Returns up to topK of the most similar documents an implementation can find for query, best first.
override
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

Static Methods

open(String path) Future<FileVectorStore>
Opens the store at path.