langchain/libs/partners/elasticsearch
Ash Vardanian d01bad5169
core[patch]: Convert SimSIMD back to NumPy (#19473)
This patch fixes the #18022 issue, converting the SimSIMD internal
zero-copy outputs to NumPy.

I've also noticed, that oftentimes `dtype=np.float32` conversion is used
before passing to SimSIMD. Which numeric types do LangChain users
generally care about? We support `float64`, `float32`, `float16`, and
`int8` for cosine distances and `float16` seems reasonable for
practically any kind of embeddings and any modern piece of hardware, so
we can change that part as well 🤗
2024-03-25 16:36:26 -07:00
..
langchain_elasticsearch core[patch]: Convert SimSIMD back to NumPy (#19473) 2024-03-25 16:36:26 -07:00
scripts partners: add Elasticsearch package (#17467) 2024-02-26 23:19:47 +00:00
tests elasticsearch: check for deployed models (#18973) 2024-03-18 21:32:00 -07:00
.gitignore partners: add Elasticsearch package (#17467) 2024-02-26 23:19:47 +00:00
LICENSE partners: add Elasticsearch package (#17467) 2024-02-26 23:19:47 +00:00
Makefile partners: add Elasticsearch package (#17467) 2024-02-26 23:19:47 +00:00
poetry.lock elasticsearch[patch]: add top-level import, remove obsolete dependency (#18644) 2024-03-07 19:38:31 -08:00
pyproject.toml elasticsearch[patch]: release 0.1.1 (#18978) 2024-03-12 16:46:22 +00:00
README.md docs: Update elasticsearch README (#18497) 2024-03-05 15:49:16 -08:00

langchain-elasticsearch

This package contains the LangChain integration with Elasticsearch.

Installation

pip install -U langchain-elasticsearch

Elasticsearch setup

Elastic Cloud

You need a running Elasticsearch deployment. The easiest way to start one is through Elastic Cloud. You can sign up for a free trial.

  1. Create a deployment
  2. Get your Cloud ID:
    1. In the Elastic Cloud console, click "Manage" next to your deployment
    2. Copy the Cloud ID and paste it into the es_cloud_id parameter below
  3. Create an API key:
    1. In the Elastic Cloud console, click "Open" next to your deployment
    2. In the left-hand side menu, go to "Stack Management", then to "API Keys"
    3. Click "Create API key"
    4. Enter a name for the API key and click "Create"
    5. Copy the API key and paste it into the es_api_key parameter below

Elastic Cloud

Alternatively, you can run Elasticsearch via Docker as described in the docs.

Usage

ElasticsearchStore

The ElasticsearchStore class exposes Elasticsearch as a vector store.

from langchain_elasticsearch import ElasticsearchStore

embeddings = ... # use a LangChain Embeddings class or ElasticsearchEmbeddings

vectorstore = ElasticsearchStore(
    es_cloud_id="your-cloud-id",
    es_api_key="your-api-key",
    index_name="your-index-name",
    embeddings=embeddings,
)

ElasticsearchEmbeddings

The ElasticsearchEmbeddings class provides an interface to generate embeddings using a model deployed in an Elasticsearch cluster.

from langchain_elasticsearch import ElasticsearchEmbeddings

embeddings = ElasticsearchEmbeddings.from_credentials(
    model_id="your-model-id",
    input_field="your-input-field",
    es_cloud_id="your-cloud-id",
    es_api_key="your-api-key",
)

ElasticsearchChatMessageHistory

The ElasticsearchChatMessageHistory class stores chat histories in Elasticsearch.

from langchain_elasticsearch import ElasticsearchChatMessageHistory

chat_history = ElasticsearchChatMessageHistory(
    index="your-index-name",
    session_id="your-session-id",
    es_cloud_id="your-cloud-id",
    es_api_key="your-api-key",
)