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: object
embeddings: Embeddings
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_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;
    }

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.

  • 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

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

  • The name of the serializable. Override to provide an alias or to preserve the serialized module name in minified environments.

    Implemented as a static method to support loading logic.

    Returns string

Generated using TypeDoc