- Elasticsearch 指南其他版本
- 8.17 中的新功能
- Elasticsearch 基础
- 快速入门
- 设置 Elasticsearch
- 升级 Elasticsearch
- 索引模块
- 映射
- 文本分析
- 索引模板
- 数据流
- 摄取管道
- 别名
- 搜索您的数据
- 重新排名
- 查询 DSL
- 聚合
- 地理空间分析
- 连接器
- EQL
- ES|QL
- SQL
- 脚本
- 数据管理
- 自动缩放
- 监视集群
- 汇总或转换数据
- 设置高可用性集群
- 快照和还原
- 保护 Elastic Stack 的安全
- Watcher
- 命令行工具
- elasticsearch-certgen
- elasticsearch-certutil
- elasticsearch-create-enrollment-token
- elasticsearch-croneval
- elasticsearch-keystore
- elasticsearch-node
- elasticsearch-reconfigure-node
- elasticsearch-reset-password
- elasticsearch-saml-metadata
- elasticsearch-service-tokens
- elasticsearch-setup-passwords
- elasticsearch-shard
- elasticsearch-syskeygen
- elasticsearch-users
- 优化
- 故障排除
- 修复常见的集群问题
- 诊断未分配的分片
- 向系统中添加丢失的层
- 允许 Elasticsearch 在系统中分配数据
- 允许 Elasticsearch 分配索引
- 索引将索引分配过滤器与数据层节点角色混合,以在数据层之间移动
- 没有足够的节点来分配所有分片副本
- 单个节点上索引的分片总数已超过
- 每个节点的分片总数已达到
- 故障排除损坏
- 修复磁盘空间不足的数据节点
- 修复磁盘空间不足的主节点
- 修复磁盘空间不足的其他角色节点
- 启动索引生命周期管理
- 启动快照生命周期管理
- 从快照恢复
- 故障排除损坏的存储库
- 解决重复的快照策略失败问题
- 故障排除不稳定的集群
- 故障排除发现
- 故障排除监控
- 故障排除转换
- 故障排除 Watcher
- 故障排除搜索
- 故障排除分片容量健康问题
- 故障排除不平衡的集群
- 捕获诊断信息
- REST API
- API 约定
- 通用选项
- REST API 兼容性
- 自动缩放 API
- 行为分析 API
- 紧凑和对齐文本 (CAT) API
- 集群 API
- 跨集群复制 API
- 连接器 API
- 数据流 API
- 文档 API
- 丰富 API
- EQL API
- ES|QL API
- 功能 API
- Fleet API
- 图表探索 API
- 索引 API
- 别名是否存在
- 别名
- 分析
- 分析索引磁盘使用量
- 清除缓存
- 克隆索引
- 关闭索引
- 创建索引
- 创建或更新别名
- 创建或更新组件模板
- 创建或更新索引模板
- 创建或更新索引模板(旧版)
- 删除组件模板
- 删除悬挂索引
- 删除别名
- 删除索引
- 删除索引模板
- 删除索引模板(旧版)
- 存在
- 字段使用情况统计信息
- 刷新
- 强制合并
- 获取别名
- 获取组件模板
- 获取字段映射
- 获取索引
- 获取索引设置
- 获取索引模板
- 获取索引模板(旧版)
- 获取映射
- 导入悬挂索引
- 索引恢复
- 索引段
- 索引分片存储
- 索引统计信息
- 索引模板是否存在(旧版)
- 列出悬挂索引
- 打开索引
- 刷新
- 解析索引
- 解析集群
- 翻转
- 收缩索引
- 模拟索引
- 模拟模板
- 拆分索引
- 解冻索引
- 更新索引设置
- 更新映射
- 索引生命周期管理 API
- 推理 API
- 信息 API
- 摄取 API
- 许可 API
- Logstash API
- 机器学习 API
- 机器学习异常检测 API
- 机器学习数据帧分析 API
- 机器学习训练模型 API
- 迁移 API
- 节点生命周期 API
- 查询规则 API
- 重新加载搜索分析器 API
- 存储库计量 API
- 汇总 API
- 根 API
- 脚本 API
- 搜索 API
- 搜索应用程序 API
- 可搜索快照 API
- 安全 API
- 身份验证
- 更改密码
- 清除缓存
- 清除角色缓存
- 清除权限缓存
- 清除 API 密钥缓存
- 清除服务帐户令牌缓存
- 创建 API 密钥
- 创建或更新应用程序权限
- 创建或更新角色映射
- 创建或更新角色
- 批量创建或更新角色 API
- 批量删除角色 API
- 创建或更新用户
- 创建服务帐户令牌
- 委托 PKI 身份验证
- 删除应用程序权限
- 删除角色映射
- 删除角色
- 删除服务帐户令牌
- 删除用户
- 禁用用户
- 启用用户
- 注册 Kibana
- 注册节点
- 获取 API 密钥信息
- 获取应用程序权限
- 获取内置权限
- 获取角色映射
- 获取角色
- 查询角色
- 获取服务帐户
- 获取服务帐户凭据
- 获取安全设置
- 获取令牌
- 获取用户权限
- 获取用户
- 授予 API 密钥
- 具有权限
- 使 API 密钥失效
- 使令牌失效
- OpenID Connect 准备身份验证
- OpenID Connect 身份验证
- OpenID Connect 注销
- 查询 API 密钥信息
- 查询用户
- 更新 API 密钥
- 更新安全设置
- 批量更新 API 密钥
- SAML 准备身份验证
- SAML 身份验证
- SAML 注销
- SAML 失效
- SAML 完成注销
- SAML 服务提供商元数据
- SSL 证书
- 激活用户配置文件
- 禁用用户配置文件
- 启用用户配置文件
- 获取用户配置文件
- 建议用户配置文件
- 更新用户配置文件数据
- 具有用户配置文件权限
- 创建跨集群 API 密钥
- 更新跨集群 API 密钥
- 快照和还原 API
- 快照生命周期管理 API
- SQL API
- 同义词 API
- 文本结构 API
- 转换 API
- 使用情况 API
- Watcher API
- 定义
- 迁移指南
- 发行说明
- Elasticsearch 版本 8.17.0
- Elasticsearch 版本 8.16.1
- Elasticsearch 版本 8.16.0
- Elasticsearch 版本 8.15.5
- Elasticsearch 版本 8.15.4
- Elasticsearch 版本 8.15.3
- Elasticsearch 版本 8.15.2
- Elasticsearch 版本 8.15.1
- Elasticsearch 版本 8.15.0
- Elasticsearch 版本 8.14.3
- Elasticsearch 版本 8.14.2
- Elasticsearch 版本 8.14.1
- Elasticsearch 版本 8.14.0
- Elasticsearch 版本 8.13.4
- Elasticsearch 版本 8.13.3
- Elasticsearch 版本 8.13.2
- Elasticsearch 版本 8.13.1
- Elasticsearch 版本 8.13.0
- Elasticsearch 版本 8.12.2
- Elasticsearch 版本 8.12.1
- Elasticsearch 版本 8.12.0
- Elasticsearch 版本 8.11.4
- Elasticsearch 版本 8.11.3
- Elasticsearch 版本 8.11.2
- Elasticsearch 版本 8.11.1
- Elasticsearch 版本 8.11.0
- Elasticsearch 版本 8.10.4
- Elasticsearch 版本 8.10.3
- Elasticsearch 版本 8.10.2
- Elasticsearch 版本 8.10.1
- Elasticsearch 版本 8.10.0
- Elasticsearch 版本 8.9.2
- Elasticsearch 版本 8.9.1
- Elasticsearch 版本 8.9.0
- Elasticsearch 版本 8.8.2
- Elasticsearch 版本 8.8.1
- Elasticsearch 版本 8.8.0
- Elasticsearch 版本 8.7.1
- Elasticsearch 版本 8.7.0
- Elasticsearch 版本 8.6.2
- Elasticsearch 版本 8.6.1
- Elasticsearch 版本 8.6.0
- Elasticsearch 版本 8.5.3
- Elasticsearch 版本 8.5.2
- Elasticsearch 版本 8.5.1
- Elasticsearch 版本 8.5.0
- Elasticsearch 版本 8.4.3
- Elasticsearch 版本 8.4.2
- Elasticsearch 版本 8.4.1
- Elasticsearch 版本 8.4.0
- Elasticsearch 版本 8.3.3
- Elasticsearch 版本 8.3.2
- Elasticsearch 版本 8.3.1
- Elasticsearch 版本 8.3.0
- Elasticsearch 版本 8.2.3
- Elasticsearch 版本 8.2.2
- Elasticsearch 版本 8.2.1
- Elasticsearch 版本 8.2.0
- Elasticsearch 版本 8.1.3
- Elasticsearch 版本 8.1.2
- Elasticsearch 版本 8.1.1
- Elasticsearch 版本 8.1.0
- Elasticsearch 版本 8.0.1
- Elasticsearch 版本 8.0.0
- Elasticsearch 版本 8.0.0-rc2
- Elasticsearch 版本 8.0.0-rc1
- Elasticsearch 版本 8.0.0-beta1
- Elasticsearch 版本 8.0.0-alpha2
- Elasticsearch 版本 8.0.0-alpha1
- 依赖项和版本
执行推理 API
编辑执行推理 API
编辑通过使用推理端点对输入文本执行推理任务。
推理 API 使您能够使用某些服务,例如内置的机器学习模型(ELSER、E5)、通过 Eland 上传的模型、Cohere、OpenAI、Azure、Google AI Studio、Google Vertex AI、Anthropic、Watsonx.ai 或 Hugging Face。对于内置模型和通过 Eland 上传的模型,推理 API 提供了一种使用和管理训练模型的替代方法。但是,如果您不打算使用推理 API 来使用这些模型,或者您想使用非 NLP 模型,请使用机器学习训练模型 API。
请求
编辑POST /_inference/<inference_id>
POST /_inference/<task_type>/<inference_id>
先决条件
编辑- 需要
monitor_inference
集群权限 (内置的inference_admin
和inference_user
角色授予此权限)
描述
编辑执行推理 API 使您能够使用机器学习模型对您作为输入提供的数据执行特定任务。该 API 返回一个包含任务结果的响应。您使用的推理端点可以执行在创建端点时使用创建推理 API定义的特定任务。
路径参数
编辑-
<inference_id>
- (必需,字符串) 推理端点的唯一标识符。
-
<task_type>
- (可选,字符串) 模型执行的推理任务类型。
查询参数
编辑-
timeout
- (可选,超时) 控制等待推理完成的时间量。默认为 30 秒。
请求正文
编辑-
input
-
(必需,字符串或字符串数组) 要在其上执行推理任务的文本。
input
可以是单个字符串或数组。目前,对于
completion
任务类型的推理端点,仅支持将单个字符串作为输入。 -
query
- (必需,字符串) 仅适用于
rerank
推理端点。搜索查询文本。 -
task_settings
- (可选,对象) 单个推理请求的任务设置。这些设置特定于您指定的
<task_type>
,并覆盖初始化服务时指定的任务设置。
示例
编辑补全示例
编辑以下示例对示例问题执行补全操作。
resp = client.inference.inference( task_type="completion", inference_id="openai_chat_completions", input="What is Elastic?", ) print(resp)
response = client.inference.inference( task_type: 'completion', inference_id: 'openai_chat_completions', body: { input: 'What is Elastic?' } ) puts response
const response = await client.inference.inference({ task_type: "completion", inference_id: "openai_chat_completions", input: "What is Elastic?", }); console.log(response);
POST _inference/completion/openai_chat_completions { "input": "What is Elastic?" }
该 API 返回以下响应
{ "completion": [ { "result": "Elastic is a company that provides a range of software solutions for search, logging, security, and analytics. Their flagship product is Elasticsearch, an open-source, distributed search engine that allows users to search, analyze, and visualize large volumes of data in real-time. Elastic also offers products such as Kibana, a data visualization tool, and Logstash, a log management and pipeline tool, as well as various other tools and solutions for data analysis and management." } ] }
重排序示例
编辑以下示例对示例输入执行重排序操作。
resp = client.inference.inference( task_type="rerank", inference_id="cohere_rerank", input=[ "luke", "like", "leia", "chewy", "r2d2", "star", "wars" ], query="star wars main character", ) print(resp)
response = client.inference.inference( task_type: 'rerank', inference_id: 'cohere_rerank', body: { input: [ 'luke', 'like', 'leia', 'chewy', 'r2d2', 'star', 'wars' ], query: 'star wars main character' } ) puts response
const response = await client.inference.inference({ task_type: "rerank", inference_id: "cohere_rerank", input: ["luke", "like", "leia", "chewy", "r2d2", "star", "wars"], query: "star wars main character", }); console.log(response);
POST _inference/rerank/cohere_rerank { "input": ["luke", "like", "leia", "chewy","r2d2", "star", "wars"], "query": "star wars main character" }
该 API 返回以下响应
{ "rerank": [ { "index": "2", "relevance_score": "0.011597361", "text": "leia" }, { "index": "0", "relevance_score": "0.006338922", "text": "luke" }, { "index": "5", "relevance_score": "0.0016166499", "text": "star" }, { "index": "4", "relevance_score": "0.0011695103", "text": "r2d2" }, { "index": "1", "relevance_score": "5.614787E-4", "text": "like" }, { "index": "6", "relevance_score": "3.7850367E-4", "text": "wars" }, { "index": "3", "relevance_score": "1.2508839E-5", "text": "chewy" } ] }
稀疏嵌入示例
编辑以下示例对示例句子执行稀疏嵌入操作。
resp = client.inference.inference( task_type="sparse_embedding", inference_id="my-elser-model", input="The sky above the port was the color of television tuned to a dead channel.", ) print(resp)
response = client.inference.inference( task_type: 'sparse_embedding', inference_id: 'my-elser-model', body: { input: 'The sky above the port was the color of television tuned to a dead channel.' } ) puts response
const response = await client.inference.inference({ task_type: "sparse_embedding", inference_id: "my-elser-model", input: "The sky above the port was the color of television tuned to a dead channel.", }); console.log(response);
POST _inference/sparse_embedding/my-elser-model { "input": "The sky above the port was the color of television tuned to a dead channel." }
该 API 返回以下响应
{ "sparse_embedding": [ { "port": 2.1259406, "sky": 1.7073475, "color": 1.6922266, "dead": 1.6247464, "television": 1.3525393, "above": 1.2425821, "tuned": 1.1440028, "colors": 1.1218185, "tv": 1.0111054, "ports": 1.0067928, "poem": 1.0042328, "channel": 0.99471164, "tune": 0.96235967, "scene": 0.9020516, (...) }, (...) ] }
文本嵌入示例
编辑以下示例使用 Cohere 集成对示例句子执行文本嵌入操作。
resp = client.inference.inference( task_type="text_embedding", inference_id="my-cohere-endpoint", input="The sky above the port was the color of television tuned to a dead channel.", task_settings={ "input_type": "ingest" }, ) print(resp)
const response = await client.inference.inference({ task_type: "text_embedding", inference_id: "my-cohere-endpoint", input: "The sky above the port was the color of television tuned to a dead channel.", task_settings: { input_type: "ingest", }, }); console.log(response);
POST _inference/text_embedding/my-cohere-endpoint { "input": "The sky above the port was the color of television tuned to a dead channel.", "task_settings": { "input_type": "ingest" } }
该 API 返回以下响应
{ "text_embedding": [ { "embedding": [ { 0.018569946, -0.036895752, 0.01486969, -0.0045204163, -0.04385376, 0.0075950623, 0.04260254, -0.004005432, 0.007865906, 0.030792236, -0.050476074, 0.011795044, -0.011642456, -0.010070801, (...) }, (...) ] } ] }