Skip to main content

An integration package connecting Elasticsearch and LangChain

Project description

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",
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_elasticsearch-0.1.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

langchain_elasticsearch-0.1.1-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_elasticsearch-0.1.1.tar.gz.

File metadata

File hashes

Hashes for langchain_elasticsearch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 57e7d3a664bd313e0400685f0a98d234cf6cf4a164f8738a96e55694da6e1e3a
MD5 2d53a9967b0774f38c8af16cad4f80f0
BLAKE2b-256 a54540573abc9d179a5a8c053db87afb35d3a2acc4163b4ac92846580ab5e81a

See more details on using hashes here.

File details

Details for the file langchain_elasticsearch-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_elasticsearch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eabf32f5a5fefd958cfb630648e2b2f68eaf3c25ccc8c6c01d4afbd2ccecc9cb
MD5 ee50a8b0e012eedc308ab82b14410ef9
BLAKE2b-256 0bba06098761a401321abd2c8e31ef3e083e06b29d5f438586e134b52df296a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page