获取嵌入节点
概述
Get Embedding节点用于为给定输入文本生成向量嵌入。当您需要将文本转换为可用于K近邻搜索等任务的数值表示时,该节点特别有用。
该节点要求在运行图时上下文中必须有一个可用的集成。该集成负责生成嵌入向量。目前唯一支持的集成是OpenAI。然而,在父应用程序中运行Rivet时,您可以注册自定义集成。
- 输入
- 输出
- 编辑器设置
输入项
标题 | 数据类型 | 描述 | 默认值 | 备注 |
---|---|---|---|---|
Input | string | The text for which the embedding should be generated. | (required) | The input will be coerced into a string if it is not a string. |
Integration | string | The name of the integration to use for generating the embedding. | (required if the input toggle for Integration is enabled) | The input will be coerced into a string if it is not a string. |
输出
标题 | 数据类型 | 描述 | 备注 |
---|---|---|---|
Embedding | vector | The vector embedding generated for the input text. | The output will be a vector containing the numerical representation of the input text. |
编辑器设置
设置 | 描述 | 默认值 | 使用输入切换 | 输入数据类型 |
---|---|---|---|---|
Integration | The name of the integration to use for generating the embedding. | openai | Yes | string |
示例1:为文本生成嵌入向量
- 创建一个文本节点并将文本设置为
"Hello, world!"
。 - 创建一个Get Embedding节点并将Text节点连接到其
Input
输入端口。 - 运行图表。Get Embedding节点的
Embedding
输出应包含输入文本的向量嵌入。
错误处理
如果运行图表时上下文中集成不可用,Get Embedding Node 将会报错。如果未提供Input
输入,它也会报错。
常见问题
问:什么是嵌入(embedding)?
A: 嵌入(embedding)是一段文本的数值表示形式。嵌入对于执行K近邻搜索非常有用,这是AI应用中的常见操作。
问:我可以使用自己的集成吗?
A: 是的,您可以使用自己的集成,方法是在运行图表时将其传递给上下文。该集成必须实现EmbeddingGenerator
接口,其中包括一个用于生成嵌入的方法。