Interface defining the structure and operations of a vector store, which facilitates the storage, retrieval, and similarity search of document vectors.

VectorStoreInterface provides methods for adding, deleting, and searching documents based on vector embeddings, including support for similarity search with optional filtering and relevance-based retrieval.

interface VectorStoreInterface {
    FilterType: string | object;
    embeddings: EmbeddingsInterface;
    addDocuments(documents: DocumentInterface<Record<string, any>>[], options?: AddDocumentOptions): Promise<void | string[]>;
    addVectors(vectors: number[][], documents: DocumentInterface<Record<string, any>>[], options?: AddDocumentOptions): Promise<void | string[]>;
    asRetriever(kOrFields?: number | Partial<VectorStoreRetrieverInput<VectorStoreInterface>>, filter?: string | object, callbacks?: Callbacks, tags?: string[], metadata?: Record<string, unknown>, verbose?: boolean): VectorStoreRetriever<VectorStoreInterface>;
    delete(_params?: Record<string, any>): Promise<void>;
    maxMarginalRelevanceSearch?(query: string, options: MaxMarginalRelevanceSearchOptions<string | object>, callbacks: undefined | Callbacks): Promise<DocumentInterface<Record<string, any>>[]>;
    similaritySearch(query: string, k?: number, filter?: string | object, callbacks?: Callbacks): Promise<DocumentInterface<Record<string, any>>[]>;
    similaritySearchVectorWithScore(query: number[], k: number, filter?: string | object): Promise<[DocumentInterface<Record<string, any>>, number][]>;
    similaritySearchWithScore(query: string, k?: number, filter?: string | object, callbacks?: Callbacks): Promise<[DocumentInterface<Record<string, any>>, number][]>;
    toJSON(): Serialized;
    toJSONNotImplemented(): SerializedNotImplemented;
}

Hierarchy (view full)

Implemented by

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.

Instance of EmbeddingsInterface used to generate vector embeddings for documents, enabling vector-based search operations.

Methods

  • Adds an array of documents to the vector store.

    Parameters

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

      An array of documents to be embedded and stored in the vector store.

    • Optionaloptions: AddDocumentOptions

      Optional configurations for embedding and storage operations.

    Returns Promise<void | string[]>

    A promise that resolves to an array of document IDs or void, depending on implementation.

  • Adds precomputed vectors and their corresponding documents to the vector store.

    Parameters

    • vectors: number[][]

      An array of vectors, with each vector representing a document.

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

      An array of DocumentInterface instances corresponding to each vector.

    • Optionaloptions: AddDocumentOptions

      Optional configurations for adding documents, potentially covering indexing or metadata handling.

    Returns Promise<void | string[]>

    A promise that resolves to an array of document IDs or void, depending on implementation.

  • Converts the vector store into a retriever, making it suitable for use in retrieval-based workflows and allowing additional configuration.

    Parameters

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

      Optional parameter for specifying either the number of documents to retrieve or partial retriever configurations.

    • Optionalfilter: string | object

      Optional filter based on FilterType for retrieval restriction.

    • Optionalcallbacks: Callbacks

      Optional callbacks for tracking retrieval events or progress.

    • Optionaltags: string[]

      General-purpose tags to add contextual information to the retriever.

    • Optionalmetadata: Record<string, unknown>

      General-purpose metadata providing additional context for retrieval.

    • Optionalverbose: boolean

      If true, enables detailed logging during retrieval.

    Returns VectorStoreRetriever<VectorStoreInterface>

    An instance of VectorStoreRetriever configured with the specified options.

  • Deletes documents from the vector store based on the specified parameters.

    Parameters

    • Optional_params: Record<string, any>

      A flexible object containing key-value pairs that define the conditions for selecting documents to delete.

    Returns Promise<void>

    A promise that resolves once the deletion operation 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

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

    • List of documents selected by maximal marginal relevance.
  • Searches for documents similar to a text query, embedding the query and retrieving documents based on vector similarity.

    Parameters

    • query: string

      The text query to search for.

    • Optionalk: number

      Optional number of similar documents to return.

    • Optionalfilter: string | object

      Optional filter based on FilterType to restrict results.

    • Optionalcallbacks: Callbacks

      Optional callbacks for tracking progress or events during the search process.

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

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

  • Searches for documents similar to a given vector query and returns them with similarity scores.

    Parameters

    • query: number[]

      A vector representing the query for similarity search.

    • k: number

      The number of similar documents to return.

    • Optionalfilter: string | object

      Optional filter based on FilterType to restrict results.

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

    A promise that resolves to an array of tuples, each containing a DocumentInterface and its corresponding similarity score.

  • Searches for documents similar to a text query and includes similarity scores in the result.

    Parameters

    • query: string

      The text query to search for.

    • Optionalk: number

      Optional number of similar documents to return.

    • Optionalfilter: string | object

      Optional filter based on FilterType to restrict results.

    • Optionalcallbacks: Callbacks

      Optional callbacks for tracking progress or events during the search process.

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

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