Elasticsearch 开放推理 API 增加了对 Anthropic 的 Claude 的支持

2024-08-30 21:52

本文主要是介绍Elasticsearch 开放推理 API 增加了对 Anthropic 的 Claude 的支持,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

作者:来自 Elastic Jonathan Buttner

我们很高兴地宣布 Elasticsearch Open Inference API 的最新功能:集成 Anthropic 的 Claude。这项功能使 Elastic 用户能够直接连接到 Anthropic 平台,并使用 Claude 3.5 Sonnet 等大型语言模型来构建 GenAI 应用程序,并实现问答等用例。以前,客户可以从 Amazon Bedrock 等提供商处访问此功能,但现在可以使用他们的 Anthropic 帐户来实现这些目的。

使用 Anthropic 的消息来回答问题

在此博客中,我们将使用 Claude Messages API 在提取(ingestion)过程中回答问题,以便在搜索之前准备好答案。在开始与 Elasticsearch 交互之前,请确保你拥有 Anthropic API 密钥,方法是先创建一个评估帐户并生成一个密钥。我们将使用 Kibana 的控制台在 Elasticsearch 中执行这些后续步骤,而无需设置 IDE。

首先,我们配置一个推理端点,它将与 Anthropic 的消息 API 交互:

PUT _inference/completion/anthropic_completion
{"service": "anthropic","service_settings": {"api_key": "<api key>","model_id": "claude-3-5-sonnet-20240620"},"task_settings": {"max_tokens": 1024}
}

成功创建推理端点后,我们将收到类似以下的响应,状态代码为 200 OK:

{"model_id": "anthropic_completion","task_type": "completion","service": "anthropic","service_settings": {"model_id": "claude-3-5-sonnet-20240620","rate_limit": {"requests_per_minute": 50}},"task_settings": {"max_tokens": 1024}
}

现在,我们可以调用已配置的端点来对任何文本输入执行 completion。让我们向模型询问 GenAI 的简短描述:

POST _inference/completion/anthropic_completion
{"input": "What is a short description of GenAI?"
}

我们应该收到状态代码为 200 OK 的响应,其中包含 GenAI 的简短描述:

{"completion": [{"result": "GenAI, short for Generative Artificial Intelligence, refers to AI systems that can create new content, such as text, images, audio, or video, based on patterns learned from existing data. These systems use advanced machine learning techniques, often involving deep neural networks, to generate human-like outputs in response to prompts or inputs. GenAI has diverse applications across industries, including content creation, design, coding, and problem-solving."}]
}

现在,我们可以设置一个问题目录,其中包含我们希望在采集期间得到解答的问题。我们将使用 Elasticsearch Bulk API 来索引有关 Elastic 产品的这些问题:

POST _bulk
{ "index" : { "_index" : "questions" } }
{"question": "What is Elasticsearch?"}
{ "index" : { "_index" : "questions" } }
{"question": "What is Kibana?"}
{ "index" : { "_index" : "questions" } }
{"question": "What is Logstash?"}

索引成功后应返回类似以下的响应:

{"errors": false,"took": 1552829728,"items": [{"index": {"_index": "questions","_id": "ipR_qJABkw3SJM5Tm3IC","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"_seq_no": 0,"_primary_term": 1,"status": 201}},{"index": {"_index": "questions","_id": "i5R_qJABkw3SJM5Tm3IC","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"_seq_no": 1,"_primary_term": 1,"status": 201}},{"index": {"_index": "questions","_id": "jJR_qJABkw3SJM5Tm3IC","_version": 1,"result": "created","_shards": {"total": 2,"successful": 1,"failed": 0},"_seq_no": 2,"_primary_term": 1,"status": 201}}]
}

我们现在将使用 script、inference 和 remove 处理器来创建我们的问答 ingest pipeline :

PUT _ingest/pipeline/question_answering_pipeline
{"processors": [{"script": {"source": "ctx.prompt = 'Please answer the following question: ' + ctx.question"}},{"inference": {"model_id": "anthropic_completion","input_output": {"input_field": "prompt","output_field": "answer"}}},{"remove": {"field": "prompt"}}]
}

管道在名为 prompt 的临时字段中为 question 字段添加前缀文本:“Please answer the following question:  ”。临时 prompt 字段的内容通过 inference API 发送到 Anthropic 服务。使用摄取管道提供了广泛的灵活性,因为你可以设置预提示以满足你的需求。这种方法也可用于汇总文档。

接下来,我们将通过调用 reindex API 将包含问题的文档通过问答管道发送。

POST _reindex
{"source": {"index": "questions","size": 50},"dest": {"index": "answers","pipeline": "question_answering_pipeline"}
}

我们应该收到类似以下的回应:

{"took": 9571,"timed_out": false,"total": 3,"updated": 0,"created": 3,"deleted": 0,"batches": 1,"version_conflicts": 0,"noops": 0,"retries": {"bulk": 0,"search": 0},"throttled_millis": 0,"requests_per_second": -1,"throttled_until_millis": 0,"failures": []
}

在生产设置中,你可能会使用另一种提取机制以自动方式提取文档。查看我们的 “将数据添加到 Elasticsearch” 指南,了解有关 Elastic 提供的将数据提取到 Elasticsearch 的各种选项的更多信息。我们还致力于展示提取机制并提供使用第三方工具将数据引入 Elasticsearch 的指导。例如,查看使用 Meltano 将数据从 Snowflake 提取到 Elasticsearch:开发人员的旅程,了解如何使用 Meltano 提取数据。

我们现在可以使用 Search API 搜索我们预先生成的答案:

POST answers/_search
{"query": {"match_all": {}}
}

响应将包含预先生成的答案:

{"took": 11,"timed_out": false,"_shards": { ... },"hits": {"total": { ... },"max_score": 1.0,"hits": [{"_index": "answers","_id": "4RO6YY8Bv2OsAP2iNusn","_score": 1.0,"_ignored": ["answer.keyword"],"_source": {"model_id": "azure_openai_completion","question": "What is Elasticsearch?","answer": "Elasticsearch is an open-source, RESTful, distributed search and analytics engine built on Apache Lucene. It can handle a wide variety of data types, including textual, numerical, geospatial, structured, and unstructured data. Elasticsearch is scalable and designed to operate in real-time, making it an ideal choice for use cases such as application search, log and event data analysis, and anomaly detection."}},{ ... },{ ... }]}
}

预先生成常见问题的答案对于降低运营成本特别有效。通过最大限度地减少对即时响应生成的需求,你可以显著减少所需的计算资源量。此外,这种方法可确保每个用户都收到相同的精确信息。一致性至关重要,尤其是在需要高可靠性和准确性的领域,例如医疗、法律或技术支持。

准备好自己尝试一下了吗?开始免费试用。
Elasticsearch 集成了 LangChain、Cohere 等工具。加入我们的高级语义搜索网络研讨会,构建你的下一个 GenAI 应用程序!

原文:Elasticsearch open inference API adds support for Anthropic’s Claude — Search Labs

这篇关于Elasticsearch 开放推理 API 增加了对 Anthropic 的 Claude 的支持的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1122036

相关文章

SpringBoo WebFlux+MongoDB实现非阻塞API过程

《SpringBooWebFlux+MongoDB实现非阻塞API过程》本文介绍了如何使用SpringBootWebFlux和MongoDB实现非阻塞API,通过响应式编程提高系统的吞吐量和响应性能... 目录一、引言二、响应式编程基础2.1 响应式编程概念2.2 响应式编程的优势2.3 响应式编程相关技术

Mybatis对MySQL if 函数的不支持问题解读

《Mybatis对MySQLif函数的不支持问题解读》接手项目后,为了实现多租户功能,引入了Mybatis-plus,发现之前运行正常的SQL语句报错,原因是Mybatis不支持MySQL的if函... 目录MyBATis对mysql if 函数的不支持问题描述经过查询网上搜索资料找到原因解决方案总结Myb

java中4种API参数传递方式统一说明

《java中4种API参数传递方式统一说明》在Java中,我们可以使用不同的方式来传递参数给方法或函数,:本文主要介绍java中4种API参数传递方式的相关资料,文中通过代码介绍的非常详细,需要的... 目录1. 概述2. 参数传递方式分类2.1 Query Parameters(查询参数)2.2 Path

Java调用DeepSeek API的8个高频坑与解决方法

《Java调用DeepSeekAPI的8个高频坑与解决方法》现在大模型开发特别火,DeepSeek因为中文理解好、反应快、还便宜,不少Java开发者都用它,本文整理了最常踩的8个坑,希望对... 目录引言一、坑 1:Token 过期未处理,鉴权异常引发服务中断问题本质典型错误代码解决方案:实现 Token

SpringBoot简单整合ElasticSearch实践

《SpringBoot简单整合ElasticSearch实践》Elasticsearch支持结构化和非结构化数据检索,通过索引创建和倒排索引文档,提高搜索效率,它基于Lucene封装,分为索引库、类型... 目录一:ElasticSearch支持对结构化和非结构化的数据进行检索二:ES的核心概念Index:

Python实现快速扫描目标主机的开放端口和服务

《Python实现快速扫描目标主机的开放端口和服务》这篇文章主要为大家详细介绍了如何使用Python编写一个功能强大的端口扫描器脚本,实现快速扫描目标主机的开放端口和服务,感兴趣的小伙伴可以了解下... 目录功能介绍场景应用1. 网络安全审计2. 系统管理维护3. 网络故障排查4. 合规性检查报错处理1.

golang实现nacos获取配置和服务注册-支持集群详解

《golang实现nacos获取配置和服务注册-支持集群详解》文章介绍了如何在Go语言中使用Nacos获取配置和服务注册,支持集群初始化,客户端结构体中的IpAddresses可以配置多个地址,新客户... 目录golang nacos获取配置和服务注册-支持集群初始化客户端可选参数配置new一个客户端 支

Elasticsearch 的索引管理与映射配置实战指南

《Elasticsearch的索引管理与映射配置实战指南》在本文中,我们深入探讨了Elasticsearch中索引与映射的基本概念及其重要性,通过详细的操作示例,我们了解了如何创建、更新和删除索引,... 目录一、索引操作(一)创建索引(二)删除索引(三)关闭索引(四)打开索引(五)索引别名二、映射操作(一

linux ssh如何实现增加访问端口

《linuxssh如何实现增加访问端口》Linux中SSH默认使用22端口,为了增强安全性或满足特定需求,可以通过修改SSH配置来增加或更改SSH访问端口,具体步骤包括修改SSH配置文件、增加或修改... 目录1. 修改 SSH 配置文件2. 增加或修改端口3. 保存并退出编辑器4. 更新防火墙规则使用uf

使用Go调用第三方API的方法详解

《使用Go调用第三方API的方法详解》在现代应用开发中,调用第三方API是非常常见的场景,比如获取天气预报、翻译文本、发送短信等,Go作为一门高效并发的编程语言,拥有强大的标准库和丰富的第三方库,可以... 目录引言一、准备工作二、案例1:调用天气查询 API1. 注册并获取 API Key2. 代码实现3