Class that provides a wrapper around the OpenSearch service for vector search. It provides methods for adding documents and vectors to the OpenSearch index, searching for similar vectors, and managing the OpenSearch index.

Hierarchy

  • VectorStore
    • OpenSearchVectorStore

Constructors

Properties

FilterType: OpenSearchFilter
embeddings: EmbeddingsInterface

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

Methods

  • Method to add documents to the OpenSearch index. It first converts the documents to vectors using the embeddings, then adds the vectors to the index.

    Parameters

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

      The documents to be added to the OpenSearch index.

    Returns Promise<void>

    Promise resolving to void.

  • Method to add vectors to the OpenSearch index. It ensures the index exists, then adds the vectors and associated documents to the index.

    Parameters

    • vectors: number[][]

      The vectors to be added to the OpenSearch index.

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

      The documents associated with the vectors.

    • Optionaloptions: {
          ids?: string[];
      }

      Optional parameter that can contain the IDs for the documents.

      • Optionalids?: string[]

    Returns Promise<void>

    Promise resolving to void.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

      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: OpenSearchFilter

      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<OpenSearchVectorStore>

    • 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 },
    });
  • Builds metadata terms for OpenSearch queries.

    This function takes a filter object and constructs an array of query terms compatible with OpenSearch 2.x. It supports a variety of query types including term, terms, terms_set, ids, range, prefix, exists, fuzzy, wildcard, and regexp. Reference: https://opensearch.org/docs/latest/query-dsl/term/index/

    Parameters

    • filter: undefined | OpenSearchFilter

      The filter object used to construct query terms. Each key represents a field, and the value specifies the type of query and its parameters.

    Returns object

    An array of OpenSearch query terms.

    // Example filter:
    const filter = {
    status: { "exists": true },
    age: { "gte": 30, "lte": 40 },
    tags: ["tag1", "tag2"],
    description: { "wildcard": "*test*" },

    };

    // Resulting query terms:
    const queryTerms = buildMetadataTerms(filter);
    // queryTerms would be an array of OpenSearch query objects.
  • 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<OpenSearchFilter>
    • _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 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: OpenSearchFilter

      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 to perform a similarity search on the OpenSearch index using a query vector. It returns the k most similar documents and their scores.

    Parameters

    • query: number[]

      The query vector.

    • k: number

      The number of similar documents to return.

    • Optionalfilter: OpenSearchFilter

      Optional filter for the OpenSearch query.

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

    Promise resolving to an array of tuples, each containing a Document and its 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: OpenSearchFilter

      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 to create a new OpenSearchVectorStore from an array of Documents, embeddings, and OpenSearch client arguments.

    Parameters

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

      The documents to be added to the OpenSearch index.

    • embeddings: EmbeddingsInterface

      The embeddings used to convert the documents into vectors.

    • dbConfig: OpenSearchClientArgs

      The OpenSearch client arguments.

    Returns Promise<OpenSearchVectorStore>

    Promise resolving to a new instance of OpenSearchVectorStore.

  • Static method to create a new OpenSearchVectorStore from an array of texts, their metadata, embeddings, and OpenSearch client arguments.

    Parameters

    • texts: string[]

      The texts to be converted into documents and added to the OpenSearch index.

    • metadatas: object | object[]

      The metadata associated with the texts. Can be an array of objects or a single object.

    • embeddings: EmbeddingsInterface

      The embeddings used to convert the texts into vectors.

    • args: OpenSearchClientArgs

      The OpenSearch client arguments.

    Returns Promise<OpenSearchVectorStore>

    Promise resolving to a new instance of OpenSearchVectorStore.