说明
目前向量数据库已支持多模态检索,可以直接通过文本搜索文本、文本搜索图片、图片搜索图片等,原有的search_by_text 接口可迁移至search_with_multi_modal
search_by_text 用于非结构化数据检索。非结构化数据检索是指向量数据库支持非结构化原始数据,可以直接通过文本搜索文本。
说明
参数 | 类型 | 是否必选 | 默认值 | 参数说明 |
|---|---|---|---|---|
text | string | 是 | 检索的输入文本。 | |
filter | map | 否 | None | 过滤条件,详见标量过滤。
|
limit | int | 否 | 10 | 检索结果数量,最大5000个。 |
offset | int | 否 | 0 | 偏移量。仅分页场景下使用,不建议设置过大值,否则有深分页影响。默认值为0。设置值至少为0,语义和mysql的offset相同。 |
output_fields | list<string> | 否 | 过滤字段,指定要返回的标量或向量字段列表。
如果索引的距离方式为cosine,向量字段返回的向量是归一化后的向量。 | |
partition | string/int | 否 | "default" | 子索引名称,类型与 partition_by 的 field_type 一致,字段值对应 partition_by 的 field_value。
|
dense_weight | float | 否 | 0.5 | 混合检索中稠密向量的权重,1 表示纯稠密检索 ,0表示纯字面检索。 |
scale_k | float64 | 否 | 1 | 检索sef是索引参数sef的scale_k倍。默认1,取值范围[0.1, 100],值越大检索结果越精确,但相应地会降低性能。 |
need_return_vector | bool | 否 | 用于检索返回向量化后的数据。将__VECTOR__字段填充到fields中。 |
# 获取指定索引,程序初始化时调用即可,无需重复调用 from volcengine.viking_db.IndexClient import IndexClient index_client = IndexClient("test_collection", "test_index", "api-vikingdb.volces.com", "cn-beijing", "your ak", "your sk", "http")
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_client = IndexClient("test_collection", "test_index", "api-vikingdb.volces.com", "cn-beijing", "your ak", "your sk", "http") res = await index_client.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 | 表示找到的向量和输入的向量的匹配程度。 |