Class LocalVectorStore
Simple on-disk vector store (cosine similarity)'. Each item is two files:
- {id}.vec : raw float32 array (dimension = fixed)
- {id}.json : payload json (arbitrary metadata; role, content, timestamps, etc.)
Options:
- preloadVectors: load all vectors into memory on startup (fast search, higher RAM)
- normalizeOnWrite: store L2-normalized vectors to speed cosine (dot == cosine)
public sealed class LocalVectorStore : IVectorStore
- Inheritance
-
objectLocalVectorStore
- Implements
Constructors
LocalVectorStore(string, int, bool, bool)
Creates a new local vector store at the specified root directory. If the directory does not exist, it will be created.
public LocalVectorStore(string id, int dimension = 1536, bool preloadVectors = false, bool normalizeOnWrite = true)
Parameters
idstringThe unique identifier for the vector store. Use AI Agent's UniqueId.
dimensionintThe dimension of a vector refers to the number of components or features that define it. This is a fixed value for the entire vector store and cannot be changed later. Each embedding AI model has a specific output dimension (e.g. 1536 for OpenAI's text-embedding-3-small), and this must match the dimension of the vectors being stored.
For Gemini models (e.g., gemini-embedding-001), the dimension can freely be set in the request (config.outputDimensionality) unlike OpenAI models that have fixed dimensions. we recommend using 1536 or 3072 for best performance and cost balance.preloadVectorsboolWhether to preload all vectors into memory on startup.
normalizeOnWriteboolWhether to store L2-normalized vectors to speed up cosine similarity calculations.
Exceptions
- ArgumentOutOfRangeException
- ArgumentNullException
Properties
Count
public int Count { get; }
Property Value
- int
Dimension
public int Dimension { get; }
Property Value
- int
Methods
DeleteAsync(string)
public UniTask<bool> DeleteAsync(string id)
Parameters
idstring
Returns
- UniTask<bool>
ExistsAsync(string)
public UniTask<bool> ExistsAsync(string id)
Parameters
idstring
Returns
- UniTask<bool>
SearchAsync(float[], int, float)
public UniTask<IReadOnlyList<SearchHit>> SearchAsync(float[] query, int k, float minSim = 0.2)
Parameters
queryfloat[]kintminSimfloat
Returns
- UniTask<IReadOnlyList<SearchHit>>
UpsertAsync(string, float[], object)
public UniTask UpsertAsync(string id, float[] vec, object payload)
Parameters
idstringvecfloat[]payloadobject
Returns
- UniTask