langchain.js
    Preparing search index...

    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 {
        embeddings: EmbeddingsInterface;
        FilterType: string | object;
        lc_kwargs: SerializedFields;
        lc_namespace: string[];
        lc_serializable: boolean;
        get lc_aliases(): undefined | { [key: string]: string };
        get lc_attributes(): undefined | SerializedFields;
        get lc_id(): string[];
        get lc_secrets(): undefined | { [key: string]: string };
        get lc_serializable_keys(): undefined | string[];
        _vectorstoreType(): string;
        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 Summary)

    Implemented by

    Index

    Properties

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

    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.

    lc_kwargs: SerializedFields
    lc_namespace: string[]

    A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.

    lc_serializable: boolean = false

    Accessors

    • get lc_aliases(): undefined | { [key: string]: string }

      A map of aliases for constructor args. Keys are the attribute names, e.g. "foo". Values are the alias that will replace the key in serialization. This is used to eg. make argument names match Python.

      Returns undefined | { [key: string]: string }

    • get lc_attributes(): undefined | SerializedFields

      A map of additional attributes to merge with constructor args. Keys are the attribute names, e.g. "foo". Values are the attribute values, which will be serialized. These attributes need to be accepted by the constructor as arguments.

      Returns undefined | SerializedFields

    • get lc_id(): string[]

      The final serialized identifier for the module.

      Returns string[]

    • get lc_secrets(): undefined | { [key: string]: string }

      A map of secrets, which will be omitted from serialization. Keys are paths to the secret in constructor args, e.g. "foo.bar.baz". Values are the secret ids, which will be used when deserializing.

      Returns undefined | { [key: string]: string }

    • get lc_serializable_keys(): undefined | string[]

      A manual list of keys that should be serialized. If not overridden, all fields passed into the constructor will be serialized.

      Returns undefined | string[]

    Methods

    • Returns a string identifying the type of vector store implementation, useful for distinguishing between different vector storage backends.

      Returns string

      A string indicating the vector store type.

    • 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

      • query: string

        Text to look up documents similar to.

      • options: MaxMarginalRelevanceSearchOptions<string | object>

        Options for configuring a maximal marginal relevance (MMR) search.

        MMR search optimizes for both similarity to the query and diversity among the results, balancing the retrieval of relevant documents with variation in the content returned.

        Fields:

        • fetchK (optional): The initial number of documents to retrieve from the vector store before applying the MMR algorithm. This larger set provides a pool of documents from which the algorithm can select the most diverse results based on relevance to the query.

        • filter (optional): A filter of type FilterType to refine the search results, allowing additional conditions to target specific subsets of documents.

        • k: The number of documents to return in the final results. This is the primary count of documents that are most relevant to the query.

        • lambda (optional): A value between 0 and 1 that determines the balance between relevance and diversity:

          • A lambda of 0 emphasizes diversity, maximizing content variation.
          • A lambda of 1 emphasizes similarity to the query, focusing on relevance. Values between 0 and 1 provide a mix of relevance and diversity.
        • OptionalfetchK?: number
        • Optionalfilter?: FilterType
        • k: number
        • Optionallambda?: number
      • callbacks: undefined | Callbacks

      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.