最近更新时间:2024.04.16 13:11:53
首次发布时间:2023.12.08 10:47:34
searchByText 用于非结构化数据检索。非结构化数据检索是指向量数据库支持非结构化原始数据,可以直接通过文本搜索文本。当用户通过文本搜索时,向量数据库通过测量文本之间的距离来确定两段文本的相似程度,返回文本的相似度。该功能适用于重复识别、文本搜索与匹配、问答等场景。
说明
请求参数是 SearchByTextParam,SearchByTextParam 实例包含的参数如下表所示。
参数 | 类型 | 是否必选 | 默认值 | 参数说明 |
---|---|---|---|---|
text | string | 是 | 检索的输入文本。 | |
filter | map | 否 | 过滤条件,详见 filter 表达式说明。
| |
limit | int | 否 | 10 | 检索结果数量,最大5000个。 |
dense_weight | float | 否 | 0.5 | 对于混合检索,dense_weight 用于控制稠密向量在检索中的权重。范围为[0.2,1]。仅在检索的索引为混合索引时有效。 |
outputFields | list<string> | 否 | 过滤字段,指定要返回的标量或向量字段列表。
如果索引的距离方式为cosine,向量字段返回的向量是归一化后的向量。 | |
partition | string/int | 否 | "default" | 子索引名称,类型与 partitionBy 的 fieldType 一致,字段值对应 partitionBy 的 fieldValue。
|
算子 | 算子说明 | 示例 |
---|---|---|
must | 针对指定字段名生效,语义为必须在 [...] 之中,即 "must in"。 |
|
must_not | 针对指定字段名生效,语义为必须不在 [...] 之中,即 "must not in"。 |
|
range | 针对指定字段名生效,语义为必须在指定范围内。 |
|
range_out | 针对指定字段名生效,语义为必须在指定范围外。配置使用 |
|
georange | 支持地理距离范围筛选 。 |
|
and | 逻辑算子,针对逻辑查询需求,对多个条件取交集。 |
|
or | 逻辑算子,针对逻辑查询需求,对多个条件取并集。 |
|
Index index = vikingDBService.getIndex("test_text", "test_index_text"); HashMap<String, Object> filter = new HashMap<>(); filter.put("op", "range"); filter.put("field", "price"); filter.put("lt", 4); Text text = new Text().setText("this.is test").build(); SearchByTextParam searchByTextParam = new SearchByTextParam() .setText(text) .setFilter(filter) .setDenseWeight(0.5) .build(); List<DataObject> datas = index.searchByText(searchByTextParam);
Java 调用执行上面的任务,返回 List<DataObject> 。DataObject 实例包含的属性如下表所示。
属性 | 说明 |
---|---|
id | 主键 id。 |
fields | 请求返回中的 fields 字段,是具体的数据,map 类型。 |
score | 表示找到的向量和输入的向量的匹配程度。 |
text | 文本非结构化检索时返回。 |