说明
目前向量数据库已支持多模态检索,可以直接通过文本搜索文本、文本搜索图片、图片搜索图片等,原有的searchByText 接口可迁移至searchWithMultiModal
searchByText 用于非结构化数据检索。非结构化数据检索是指向量数据库支持非结构化原始数据,可以直接通过文本搜索文本。
说明
请求参数是 SearchByTextParam,SearchByTextParam 实例包含的参数如下表所示。
参数 | 类型 | 是否必选 | 默认值 | 参数说明 |
---|---|---|---|---|
text | string | 是 | 检索的输入文本。 | |
filter | map | 否 | 过滤条件,详见标量过滤。
| |
limit | int | 否 | 10 | 检索结果数量,最大5000个。 |
denseWeight | float | 否 | 0.5 | 对于混合检索,dense_weight 用于控制稠密向量在检索中的权重。范围为[0.2,1]。仅在检索的索引为混合索引时有效。 |
outputFields | list<string> | 否 | 过滤字段,指定要返回的标量或向量字段列表。
如果索引的距离方式为cosine,向量字段返回的向量是归一化后的向量。 | |
partition | string/int | 否 | "default" | 子索引名称,类型与 partitionBy 的 fieldType 一致,字段值对应 partitionBy 的 fieldValue。
|
//获取指定索引,程序初始化时调用即可,无需重复调用 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 | 文本非结构化检索时返回。 |