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
embeddings: Embeddings

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.

  • Method to delete documents from the Elasticsearch database.

    Parameters

    • params: {
          ids: string[];
      }

      Object containing the IDs of the documents to delete.

      • ids: string[]

    Returns Promise<void>

    A promise that resolves when the deletion is complete.

  • Method to delete an index from the Elasticsearch database if it exists.

    Returns Promise<void>

    A promise that resolves when the deletion is complete.

  • Method to check if an index exists in the Elasticsearch database.

    Returns Promise<boolean>

    A promise that resolves with a boolean indicating whether the index exists.

  • Parameters

    • query: string
    • k: number = 4
    • filter: undefined | ElasticFilter = undefined
    • _callbacks: undefined | Callbacks = undefined

    Returns Promise<Document<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
    • k: number = 4
    • filter: undefined | ElasticFilter = undefined
    • _callbacks: undefined | Callbacks = undefined

    Returns Promise<[Document<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<Document<Record<string, any>>[]>

    • List of documents selected by maximal marginal relevance.
  • Static method to create an ElasticVectorSearch instance from Document instances. It adds the documents to the Elasticsearch database, then returns the ElasticVectorSearch instance.

    Parameters

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

      The Document instances to create the ElasticVectorSearch instance from.

    • embeddings: Embeddings

      The embeddings to use for the documents.

    • dbConfig: ElasticClientArgs

      The configuration for the Elasticsearch database.

    Returns Promise<ElasticVectorSearch>

    A promise that resolves with the created ElasticVectorSearch instance.

  • Static method to create an ElasticVectorSearch instance from an existing index in the Elasticsearch database. It checks if the index exists, then returns the ElasticVectorSearch instance if it does.

    Parameters

    • embeddings: Embeddings

      The embeddings to use for the documents.

    • dbConfig: ElasticClientArgs

      The configuration for the Elasticsearch database.

    Returns Promise<ElasticVectorSearch>

    A promise that resolves with the created ElasticVectorSearch instance if the index exists, otherwise it throws an error.

  • 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: Embeddings

      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