跳至主要内容

KNN数据集节点

KNN Dataset Node Screenshot

概述

KNN(K-最近邻)数据集节点用于在给定嵌入向量的情况下查找数据集中的k个最近邻。当您想要在数据集中找到与给定项目最相似的项目时,此节点特别有用。

节点在运行图时需要上下文中有一个可用的数据集提供者。数据集提供者负责管理数据集的存储和检索。在Rivet应用程序中,数据集提供者会自动为您处理。

有关数据集的更多信息,请参阅用户指南中的Data Studio部分。

输入项

标题数据类型描述默认值备注
EmbeddingobjectThe embedding to use as the reference point for finding the nearest neighbors.(required)
Dataset IDstringThe ID of the dataset to search for the nearest neighbors. This input is only available if Use Dataset ID Input is enabled.(required if if the input toggle for Dataset ID is enabled)The input will be coerced into a string if it is not a string.
KnumberThe number of nearest neighbors to find. This input is only available if Use K Input is enabled.(required if if the input toggle for K is enabled)The input will be coerced into a number if it is not a number.

示例1:在数据集中查找最近邻

  1. 首先,在Data Studio中创建一个名为Employees的新数据集。
  2. 在新图表中,添加一个Append to Dataset Node并将数据集ID设置为Employees
  3. 添加一个Text Node并将值设为John Doe。我们将获取这个文本节点的嵌入向量。
  4. 添加一个Get Embedding Node并将Text Node连接到它。将Get Embedding Node的Embedding输出连接到Append to Dataset Node的Embedding输入。
  5. 将文本节点连接到追加到数据集节点的Data输入端口。
  6. 运行图表。这会将"John Doe"及其嵌入添加到Employees数据集中。
  7. 将文本节点的值更改为Jane Doe并再次运行图表。这会将"Jane Doe"及其嵌入附加到Employees数据集中。

KNN Dataset Node Example 1

  1. 接下来,创建一个新图表,添加一个KNN数据集节点,并将数据集ID设置为Employees,K值设为1。
  2. 添加一个Text Node并将值设置为Jane。我们将查找与此文本节点最近的邻居。
  3. 添加一个Get Embedding Node并将Text Node连接到它。将Get Embedding Node的Embedding输出连接到KNN Dataset Node的Embedding输入。
  4. 运行图形。这将在Employees数据集中找到与"Jane"最近的邻居,即"Jane Doe"。

KNN Dataset Node Example 1

错误处理

如果在运行图时上下文环境中没有可用的数据集提供程序,KNN数据集节点将会报错。如果没有提供Embedding输入,它也会报错。

常见问题

问:什么是数据集提供者?

A: 数据集提供者是一个负责管理数据集存储和检索的对象。当图表运行时,它会被传递给上下文。数据集提供者必须实现DatasetProvider接口,该接口包含获取、存放和删除数据集的方法。更多信息请参阅API参考文档

问:有没有办法在不使用数据集的情况下获取最近邻?

您可以使用Vector KNN Node通过其他集成(如Pinecone)来查找最近邻。

问:如果数据集不存在会发生什么?

A: 如果数据集不存在,KNN Dataset Node 将会报错。

另请参阅