Table of Contents

Class InMemoryVectorStore

Namespace
Mythosia.VectorDb.InMemory
Assembly
Mythosia.VectorDb.InMemory.dll

Thread-safe in-memory implementation of IVectorStore using cosine similarity for TopK search. Supports metadata storage, filtering, upsert, and delete operations. Suitable for development, testing, and small-scale workloads.

public class InMemoryVectorStore : IVectorStore, IRagDiagnosticsStore, IDisposable
Inheritance
InMemoryVectorStore
Implements
Inherited Members

Methods

CountAsync(VectorFilter?, CancellationToken)

Returns the number of records matching the optional filter. When filter is null, returns the total record count. Implementations may ignore MinScore as it is not meaningful for counting.

public Task<long> CountAsync(VectorFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

filter VectorFilter
cancellationToken CancellationToken

Returns

Task<long>

DeleteAsync(string, VectorFilter?, CancellationToken)

Deletes a single record by its Id. Implementations may use filter to narrow by metadata conditions.

public Task DeleteAsync(string id, VectorFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

id string
filter VectorFilter
cancellationToken CancellationToken

Returns

Task

DeleteByFilterAsync(VectorFilter, CancellationToken)

Deletes all records matching the specified filter.

public Task DeleteByFilterAsync(VectorFilter filter, CancellationToken cancellationToken = default)

Parameters

filter VectorFilter
cancellationToken CancellationToken

Returns

Task

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetAsync(string, VectorFilter?, CancellationToken)

Retrieves a single record by its Id. Implementations may use filter to narrow results by metadata conditions.

public Task<VectorRecord?> GetAsync(string id, VectorFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

id string
filter VectorFilter
cancellationToken CancellationToken

Returns

Task<VectorRecord>

GetBatchAsync(IEnumerable<string>, VectorFilter?, CancellationToken)

Retrieves multiple records by their Ids in a single batch operation. Records that do not exist or do not match filter are omitted from the result. The order of results is not guaranteed to match the order of ids.

public Task<IReadOnlyList<VectorRecord>> GetBatchAsync(IEnumerable<string> ids, VectorFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

ids IEnumerable<string>
filter VectorFilter
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<VectorRecord>>

GetTotalRecordCount()

Returns the total number of records.

public int GetTotalRecordCount()

Returns

int

HybridSearchAsync(float[], string, int, VectorFilter?, CancellationToken)

Performs a hybrid search combining dense vector similarity and keyword matching. Implementations with native hybrid support should override this method.

public Task<IReadOnlyList<VectorSearchResult>> HybridSearchAsync(float[] denseVector, string query, int topK = 5, VectorFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

denseVector float[]

The dense embedding vector for semantic similarity.

query string

The original text query for keyword-based matching.

topK int

Maximum number of results to return.

filter VectorFilter

Optional filter criteria (metadata conditions, min score).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IReadOnlyList<VectorSearchResult>>

Results ordered by descending hybrid relevance score.

ListAllRecordsAsync(CancellationToken)

Returns ALL records. For diagnostic/debugging use only.

public Task<IReadOnlyList<VectorRecord>> ListAllRecordsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<IReadOnlyList<VectorRecord>>

ScoredListAsync(float[], CancellationToken)

Computes cosine similarity scores for a query vector against ALL records. Results are sorted by descending score. No TopK or MinScore filtering is applied.

public Task<IReadOnlyList<VectorSearchResult>> ScoredListAsync(float[] queryVector, CancellationToken cancellationToken = default)

Parameters

queryVector float[]
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<VectorSearchResult>>

SearchAsync(float[], int, VectorFilter?, CancellationToken)

Performs a similarity search. Implementations should respect Conditions and MinScore when present.

public Task<IReadOnlyList<VectorSearchResult>> SearchAsync(float[] queryVector, int topK = 5, VectorFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

queryVector float[]

The query embedding vector.

topK int

Maximum number of results to return.

filter VectorFilter

Optional filter criteria (metadata conditions, min score).

cancellationToken CancellationToken

Cancellation token.

Returns

Task<IReadOnlyList<VectorSearchResult>>

Results ordered by descending similarity score.

UpsertAsync(VectorRecord, CancellationToken)

Inserts or updates a single vector record. If a record with the same Id already exists, it is overwritten.

public Task UpsertAsync(VectorRecord record, CancellationToken cancellationToken = default)

Parameters

record VectorRecord
cancellationToken CancellationToken

Returns

Task

UpsertBatchAsync(IEnumerable<VectorRecord>, CancellationToken)

Inserts or updates multiple vector records in a batch.

public Task UpsertBatchAsync(IEnumerable<VectorRecord> records, CancellationToken cancellationToken = default)

Parameters

records IEnumerable<VectorRecord>
cancellationToken CancellationToken

Returns

Task