Class that extends SaveableVectorStore and provides methods for adding documents and vectors to a usearch index, performing similarity searches, and saving the index.

Hierarchy

  • SaveableVectorStore
    • USearch

Constructors

Properties

FilterType: string | object

Defines the filter type used in search and delete operations. Can be an object for structured conditions or a string for simpler filtering.

embeddings: EmbeddingsInterface

Embeddings interface for generating vector embeddings from text queries, enabling vector-based similarity searches.

Accessors

Methods

  • Method that adds documents to the usearch index. It generates embeddings for the documents and adds them to the index.

    Parameters

    • documents: Document<Record<string, any>>[]

      An array of Document instances to be added to the index.

    Returns Promise<string[]>

    A promise that resolves with an array of document IDs.

  • Method that adds vectors to the usearch index. It also updates the mapping between vector IDs and document IDs.

    Parameters

    • vectors: number[][]

      An array of vectors to be added to the index.

    • documents: Document<Record<string, any>>[]

      An array of Document instances corresponding to the vectors.

    Returns Promise<string[]>

    A promise that resolves with an array of document IDs.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

    • OptionalkOrFields: number | Partial<VectorStoreRetrieverInput<USearch>>

      If a number is provided, it sets the k parameter (number of items to retrieve).

      • If an object is provided, it should contain various configuration options.
    • Optionalfilter: string | object

      Optional filter criteria to limit the items retrieved based on the specified filter type.

    • Optionalcallbacks: Callbacks

      Optional callbacks that may be triggered at specific stages of the retrieval process.

    • Optionaltags: string[]

      Tags to categorize or label the VectorStoreRetriever. Defaults to an empty array if not provided.

    • Optionalmetadata: Record<string, unknown>

      Additional metadata as key-value pairs to add contextual information for the retrieval process.

    • Optionalverbose: boolean

      If true, enables detailed logging for the retrieval process. Defaults to false.

    Returns VectorStoreRetriever<USearch>

    • A configured VectorStoreRetriever instance based on the provided parameters.

    Basic usage with a k value:

    const retriever = myVectorStore.asRetriever(5);
    

    Usage with a configuration object:

    const retriever = myVectorStore.asRetriever({
    k: 10,
    filter: myFilter,
    tags: ['example', 'test'],
    verbose: true,
    searchType: 'mmr',
    searchKwargs: { alpha: 0.5 },
    });
  • Deletes documents from the vector store based on the specified parameters.

    Parameters

    • Optional_params: Record<string, any>

      Flexible key-value pairs defining conditions for document deletion.

    Returns Promise<void>

    A promise that resolves once the deletion is complete.

  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

    • query: string

      Text to look up documents similar to.

    • options: MaxMarginalRelevanceSearchOptions<string | object>
    • _callbacks: undefined | Callbacks

    Returns Promise<DocumentInterface<Record<string, any>>[]>

    • List of documents selected by maximal marginal relevance.
  • Method that saves the usearch index and the document store to disk.

    Parameters

    • directory: string

      The directory where the index and document store should be saved.

    Returns Promise<void>

    A promise that resolves when the save operation is complete.

  • Searches for documents similar to a text query by embedding the query and performing a similarity search on the resulting vector.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: string | object

      Optional filter based on FilterType.

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

    Returns Promise<DocumentInterface<Record<string, any>>[]>

    A promise resolving to an array of DocumentInterface instances representing similar documents.

  • Method that performs a similarity search in the usearch index. It returns the k most similar documents to a given query vector, along with their similarity scores.

    Parameters

    • query: number[]

      The query vector.

    • k: number

      The number of most similar documents to return.

    Returns Promise<[Document<Record<string, any>>, number][]>

    A promise that resolves with an array of tuples, each containing a Document and its similarity score.

  • Searches for documents similar to a text query by embedding the query, and returns results with similarity scores.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: string | object

      Optional filter based on FilterType.

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

    Returns Promise<[DocumentInterface<Record<string, any>>, number][]>

    A promise resolving to an array of tuples, each containing a document and its similarity score.

  • Returns Serialized

  • Static method that creates a new USearch instance from a list of documents. It generates embeddings for the documents and adds them to the usearch index.

    Parameters

    • docs: Document<Record<string, any>>[]

      An array of Document instances to be added to the index.

    • embeddings: EmbeddingsInterface

      An instance of Embeddings used to generate embeddings for the documents.

    • OptionaldbConfig: {
          docstore?: SynchronousInMemoryDocstore;
      }

      Optional configuration for the document store.

    Returns Promise<USearch>

    A promise that resolves with a new USearch instance.

  • Static method that creates a new USearch instance from a list of texts. It generates embeddings for the texts and adds them to the usearch index.

    Parameters

    • texts: string[]

      An array of texts to be added to the index.

    • metadatas: object | object[]

      Metadata associated with the texts.

    • embeddings: EmbeddingsInterface

      An instance of Embeddings used to generate embeddings for the texts.

    • OptionaldbConfig: {
          docstore?: SynchronousInMemoryDocstore;
      }

      Optional configuration for the document store.

    Returns Promise<USearch>

    A promise that resolves with a new USearch instance.

  • Loads a vector store instance from the specified directory, using the provided embeddings to ensure compatibility.

    This static method reconstructs a SaveableVectorStore from previously saved data. Implementations should interpret the saved data format to recreate the vector store instance.

    Parameters

    • _directory: string

      The directory path from which the vector store data will be loaded.

    • _embeddings: EmbeddingsInterface

      An instance of EmbeddingsInterface to align the embeddings with the loaded vector data.

    Returns Promise<SaveableVectorStore>

    A promise that resolves to a SaveableVectorStore instance constructed from the saved data.