IDocumentStore<T>

Interfaces · AiDotNet.Interfaces

Defines the contract for document stores that index and retrieve vectorized documents.

Known implementations: DocumentStoreBase<T>

For Beginners

A document store is like a smart library that organizes information by meaning.

Think of it like a special filing cabinet:

  • Regular filing cabinet: Organized alphabetically or by date
  • Document store: Organized by meaning using math

When you search for “climate change”, it finds documents about environmental issues even if they don’t contain those exact words, because it understands the meaning.

It’s like having a librarian who truly understands what each book is about and can find exactly what you need based on your question, not just keywords.

How It Works

A document store manages a collection of documents with their vector embeddings, enabling efficient similarity-based retrieval. Implementations can range from simple in-memory storage to distributed vector databases. The interface supports adding documents, similarity search, and metadata-based filtering.

Properties

Property Summary
int DocumentCount { get; } Gets the number of documents currently stored in the document store.
int VectorDimension { get; } Gets the dimensionality of the vectors stored in this document store.

Methods

Method Summary
Document<T> GetById(string documentId) Retrieves a document by its unique identifier.
IEnumerable<Document<T>> GetAll() Gets all documents currently stored in the document store.
IEnumerable<Document<T>> GetSimilar(Vector<T> queryVector, int topK) Retrieves the top-k most similar documents to a given query vector.
IEnumerable<Document<T>> GetSimilarWithFilter(Vector<T> queryVector, MetadataFilter filter, int topK) Retrieves similar documents using a rich, boolean MetadataFilter expression tree.
IEnumerable<Document<T>> GetSimilarWithFilters(Vector<T> queryVector, int topK, Dictionary<string, object> metadataFilters) Retrieves similar documents with additional metadata filtering.
Task AddAsync(VectorDocument<T> vectorDocument, CancellationToken cancellationToken) Asynchronously adds a single vectorized document to the store.
Task AddBatchAsync(IEnumerable<VectorDocument<T>> vectorDocuments, CancellationToken cancellationToken) Asynchronously adds multiple vectorized documents to the store in a batch.
Task ClearAsync(CancellationToken cancellationToken) Asynchronously removes all documents from the store.
Task<Document<T>> GetByIdAsync(string documentId, CancellationToken cancellationToken) Asynchronously retrieves a document by its unique identifier.
Task<IEnumerable<Document<T>>> GetAllAsync(CancellationToken cancellationToken) Asynchronously gets all documents currently stored in the document store.
Task<IEnumerable<Document<T>>> GetSimilarAsync(Vector<T> queryVector, int topK, CancellationToken cancellationToken) Asynchronously retrieves the top-k most similar documents to a query vector.
Task<IEnumerable<Document<T>>> GetSimilarWithFilterAsync(Vector<T> queryVector, MetadataFilter filter, int topK, CancellationToken cancellationToken) Asynchronously retrieves similar documents using a rich, boolean MetadataFilter expression tree.
Task<IEnumerable<Document<T>>> GetSimilarWithFiltersAsync(Vector<T> queryVector, int topK, Dictionary<string, object> metadataFilters, CancellationToken cancellationToken) Asynchronously retrieves similar documents with additional metadata filtering.
Task<bool> RemoveAsync(string documentId, CancellationToken cancellationToken) Asynchronously removes a document from the store by its identifier.
bool Remove(string documentId) Removes a document from the store by its identifier.
void Add(VectorDocument<T> vectorDocument) Adds a single vectorized document to the store.
void AddBatch(IEnumerable<VectorDocument<T>> vectorDocuments) Adds multiple vectorized documents to the store in a batch operation.
void Clear() Removes all documents from the store.