Class for interacting with an Elasticsearch database. It extends the VectorStore base class and provides methods for adding documents and vectors to the Elasticsearch database, performing similarity searches, deleting documents, and more.

Hierarchy

Constructors

Properties

FilterType: ElasticFilter

Methods

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

    Parameters

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

      The documents to add to the database.

    • Optional options: {
          ids?: string[];
      }

      Optional parameter that can contain the IDs for the documents.

      • Optional ids?: string[]

    Returns Promise<string[]>

    A promise that resolves with the IDs of the added documents.

  • Method to add vectors to the Elasticsearch database. It ensures the index exists, then adds the vectors and their corresponding documents to the database.

    Parameters

    • vectors: number[][]

      The vectors to add to the database.

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

      The documents corresponding to the vectors.

    • Optional options: {
          ids?: string[];
      }

      Optional parameter that can contain the IDs for the documents.

      • Optional ids?: string[]

    Returns Promise<string[]>

    A promise that resolves with the IDs of the added documents.

  • Parameters

    • query: string
    • Optional k: number
    • Optional filter: ElasticFilter
    • Optional _callbacks: Callbacks

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

  • Method to perform a similarity search in the Elasticsearch database using a vector. It returns the k most similar documents along with their similarity scores.

    Parameters

    • query: number[]

      The query vector.

    • k: number

      The number of most similar documents to return.

    • Optional filter: ElasticFilter

      Optional filter to apply to the search.

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

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

  • Parameters

    • query: string
    • Optional k: number
    • Optional filter: ElasticFilter
    • Optional _callbacks: Callbacks

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

  • 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.
  • Static method to create an ElasticVectorSearch instance from texts. It creates Document instances from the texts and their corresponding metadata, then calls the fromDocuments method to create the ElasticVectorSearch instance.

    Parameters

    • texts: string[]

      The texts to create the ElasticVectorSearch instance from.

    • metadatas: object | object[]

      The metadata corresponding to the texts.

    • embeddings: EmbeddingsInterface

      The embeddings to use for the documents.

    • args: ElasticClientArgs

      The arguments to create the Elasticsearch client.

    Returns Promise<ElasticVectorSearch>

    A promise that resolves with the created ElasticVectorSearch instance.

Generated using TypeDoc