search_by_text 用于非结构化数据检索。非结构化数据检索是指向量数据库支持非结构化原始数据,可以直接通过文本搜索文本。
异步调用使用async_search_by_text 接口,参数不变。
说明
参数 | 类型 | 是否必选 | 默认值 | 参数说明 |
---|---|---|---|---|
text | string | 是 | 检索的输入文本。 | |
filter | map | 否 | None | 过滤条件,详见标量过滤。
|
limit | int | 否 | 10 | 检索结果数量,最大5000个。 |
output_fields | list<string> | 否 | 过滤字段,指定要返回的标量或向量字段列表。
如果索引的距离方式为cosine,向量字段返回的向量是归一化后的向量。 | |
partition | string/int | 否 | "default" | 子索引名称,类型与 partition_by 的 field_type 一致,字段值对应 partition_by 的 field_value。
|
dense_weight | float | 否 | 0.5 | 混合检索中稠密向量的权重,1 表示纯稠密检索 ,0表示纯字面检索。 |
# 获取指定索引,程序初始化时调用即可,无需重复调用 index = vikingdb_service.get_index("example_text", "example_index_text")
res = index.search_by_text(Text(text="this is five"), filter={"op": "range", "field": "price", "lt": 4}, limit=3, output_fields=["doc_id", "text", "price", "like"], partition="default") async def search_by_text(): index = await vikingdb_service.async_get_index("async", "async") res = await index.search_by_text(Text(text="this is five"), filter={"op": "range", "field": "price", "lt": 4}, limit=3, output_fields=["doc_id", "text", "price", "like"], partition= "default") asyncio.run(search_by_text())
Python 调用执行上面的任务,返回 List<Data> 。Data 实例包含的属性如下表所示。
属性 | 说明 |
---|---|
id | 主键 id。 |
fields | 请求返回中的 fields 字段,是具体的数据,字典类型。 |
score | 表示找到的向量和输入的向量的匹配程度。 |