Skip to main content

Elasticsearch

介绍如何在Elasticsearch中使用托管的嵌入模型生成嵌入的步骤

使用ElasticsearchEmebddings类的最简单方法是

  • 使用from_credentials构造函数(如果您使用Elastic Cloud)
  • 或使用from_es_connection构造函数与任何Elasticsearch集群
!pip -q install elasticsearch langchain

......

Testing with from_credentials

This required an Elastic Cloud cloud_id

# 使用凭据实例化ElasticsearchEmbeddings
embeddings = ElasticsearchEmbeddings.from_credentials(
model_id,
es_cloud_id="your_cloud_id",
es_user="your_user",
es_password="your_password",
)

......

Testing with Existing Elasticsearch client connection

This can be used with any Elasticsearch deployment

# 创建Elasticsearch连接
es_connection = Elasticsearch(
hosts=["https://es_cluster_url:port"], basic_auth=("user", "password")
)

......