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

  • VectorStore
    • ElasticVectorSearch

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.

  • 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 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: object | {
          field: string;
          operator: string;
          value: any;
      }[]

      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.

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

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

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