多模态数据检索是指向量数据库支持直接通过图文等多模态数据类型进行检索,且支持模态的组合,如文搜图,图搜图,图搜文+图,文搜视频,图搜视频等。此外,多模态检索支持对检索结果进行重排的能力,以获得更佳精准的召回结果。
说明
适用于创建向量库时选择"需要向量化":当导入的数据是原始数据时,可以通过此接口输入文本、图片等进行检索。
说明
请求向量数据库 VikingDB 的 OpenAPI 接口时,可以使用 ak、sk 构造签名进行鉴权。请参见数据面API调用流程,复制调用示例并填入必要信息
URI | /api/vikingdb/data/search/multi_modal | 统一资源标识符 |
|---|---|---|
方法 | POST | 客户端对向量数据库服务器请求的操作类型 |
请求头 | Content-Type: application/json | 请求消息类型 |
Authorization: HMAC-SHA256 *** | 鉴权 |
说明
场景 1:QPS(CPU 占用)超限
场景 2:Token(TPM)超限
仅列出本接口特有的用于多模态检索和重排参数。更多信息请参见检索公共参数。
参数名 | 必选 | 类型 | 备注 |
|---|---|---|---|
text | 至少选1 | string | 检索的文本内容 |
image | string |
| |
video | map | { | |
instruction | 否 | map | instruction 配置 |
rerank | 否 | map | rerank 重排参数:在召回后,可选rerank对数据进行重排操作 |
tensor_rerank | 否 | map | 张量重排参数:详见tensor_rerank子参数列表 |
参数名 | 必选 | 类型 | 备注 |
|---|---|---|---|
model_name | 是 | string | rerank模型名称。支持的模型列表见重排序-Rerank |
model_version | 是 | string | rerank模型版本。 |
input_limit | 否 | int | 召回后进入rerank阶段的数据量。默认取search中limit参数值。但不得超过100。要求:search.limit<=search.rerank.input_limit<=100。 |
instruction | 否 | string | rerank指令。默认不填。在特定使用场景下,填写指令可提高rerank效果。下面给出一些参考示例:
|
score_threshold | 否 | float | 可选,按rerank分数阈值过滤。小于score_threshold的数据将不会返回。默认值为0 |
fail_strategy | 否 | string | 当rerank调用失败时的处理策略:
|
timeout_ms | 否 | int | rerank超时时间。超时则算作rerank失败,进入fail_strategy机制。 |
参数名 | 类型 | 必选 | 说明 |
|---|---|---|---|
input_limit | int | 是 | 进入张量重排的候选数量,范围:[1, 1000],默认值:100 |
参数 | 一级参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|---|
instruction | Map | 否 | Instruction 配置 | ||
auto_fill | Boolean | 是 | true | 自动填充 Instruction 内容 |
模型名称 | 模型版本 | 支持向量化类型 | 默认稠密向量维度 | 可选稠密向量维度 | 文本截断长度 | 支持稀疏向量 | 支持张量 | 可支持instruction | 支持入库Instruction | 支持检索Instruction |
|---|---|---|---|---|---|---|---|---|---|---|
bge-large-zh | (default) | text | 1024 | 1024 | 512 | 否 | 否 | 是 | null |
|
bge-m3 | (default) | text | 1024 | 1024 | 8192 | 是 | 否 | 否 | null | null |
bge-visualized-m3 | (default) | text、image及其组合 | 1024 | 1024 | 8192 | 否 | 否 | 否 | null | null |
doubao-embedding | 240715 | text | 2048 | 512, 1024, 2048 | 4096 | 否 | 否 | 是 | null |
|
doubao-embedding-large | 240915 | text | 2048 | 512, 1024, 2048, 4096 | 4096 | 否 | 否 | 是 | null |
|
doubao-embedding-vision | 250328 | text、image及其组合 | 2048 | 2048, 1024 | 8192 | 否 | 否 | 是 | null |
|
doubao-embedding-vision | 250615 | 兼容241215和250328的用法*。*另外,支持full_modal_seq(文/图/视频序列) | 2048 | 2048, 1024 | 128k | 否 | 否 | 是 | null |
|
doubao-embedding-vision | 251215 | 兼容241215和250328的用法,支持full_modal_seq(文/图/视频序列)。另外支持张量 | 2048 | 2048, 1024 | 128k | 是 | 是 | 是 |
|
|
req_path = "/api/vikingdb/data/search/multi_modal" req_body = { "collection_name": "test_coll_with_vectorize", "index_name": "idx_1", "text": "向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "instruction": { "auto_fill": true }, "output_fields": [ "f_text" ], "limit": 2 }
{ "code": "Success", "message": "The API call was executed successfully.", "request_id": "02175438839168500000000000000000000ffff0a003ee4fc3499", "result": { "data": [ { "id": "uid_001", "fields": { "f_text": "向量是指在数学中具有一定大小和方向的量" }, "score": 9.899999618530273, "ann_score": 9.899999618530273 }, { "id": "uid_002", "fields": { "f_text": "向量是高中数学里的一个重要概念" }, "score": 8.324234999961, "ann_score": 8.324234999961, } ], "total_return_count": 2, "real_text_query": "根据这个问题,找到能回答这个问题的相应文本或图片:向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "token_usage": { "doubao-embedding-vision__250328": { "prompt_tokens":53, "completion_tokens":0, "image_tokens":0, "total_tokens":53 } } } }
req_path = "/api/vikingdb/data/search/multi_modal" req_body = { "collection_name": "test_coll_with_vectorize", "index_name": "idx_1", "text": "向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "image": "tos://my_bucket/vector_icon.jpg", "output_fields": [ "f_text", "f_image" ], "instruction": { "auto_fill": true }, "limit": 2 }
{ "code": "Success", "message": "The API call was executed successfully.", "request_id": "02175438839168500000000000000000000ffff0a003ee4fc3499", "result": { "data": [ { "id": "uid_001", "fields": { "f_text": "向量是指在数学中具有一定大小和方向的量", "f_image": "tos://my_bucket/vector_1.jpg" }, "score": 9.899999618530273, "ann_score": 9.899999618530273 }, { "id": "uid_002", "fields": { "f_text": "向量是高中数学里的一个重要概念", "f_image": "tos://my_bucket/vector_2.jpg" }, "score": 8.324234999961, "ann_score": 8.324234999961, } ], "total_return_count": 2, "real_text_query": "根据这个问题,找到能回答这个问题的相应文本或图片:向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "token_usage": { "doubao-embedding-vision__250328": { "prompt_tokens":1335, "completion_tokens":0, "image_tokens":1231, "total_tokens":1335 } } } }
req_path = "/api/vikingdb/data/search/multi_modal" req_body = { "collection_name": "jiangyuan_video_collection", "index_name": "jiangyuan_video_index", "text": "猫", "video": { "value": "tos://data-import/2101858484/2025_08_19_10_51_40Oheg6Pua9jaD33cVl2GhcKyjumEM7aXy/cat_video.mp4", "fps": 1.0, }, "output_fields": [ "f_id", "f_video" ], "instruction": { "auto_fill": false }, "limit": 2 }
{ "code": "Success", "message": "The API call was executed successfully.", "request_id": "02175574557162300000000000000000000ffff0a007af7628242", "result": { "data": [ { "id": "4", "fields": { "f_id": "4", "f_video": { "value": "tos://my_bucket/xxxx1.mp4", "fps": 1.0, } }, "score": 0.9932262897491455, "ann_score": 0.9932262897491455 }, { "id": "1", "fields": { "f_id": "1", "f_video": { "value": "tos://my_bucket/xxxx2.mp4", "fps": 1.0, } }, "score": 0.41645175218582153, "ann_score": 0.41645175218582153 } ], "total_return_count": 2, "real_text_query": "猫", "token_usage": { "doubao-embedding-vision__250615": { "prompt_tokens": 18146, "completion_tokens": 0, "image_tokens": 17892, "total_tokens": 18146 } } } }
{ "collection_name": "test_coll_with_vectorize", "index_name": "idx_1", "text": "向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "image": "tos://my_bucket/vector_icon.jpg", "output_fields": [ "f_text", "f_image" ], "instruction": { "auto_fill": true }, "limit": 2, "rerank": { "model_name": "doubao-seed-rerank", "model_version": "251028", "instruction": "Whether the Document and Query represent duplicate questions" } }
{ "code": "Success", "message": "The API call was executed successfully.", "request_id": "02175438839168500000000000000000000ffff0a003ee4fc3499", "result": { "data": [ { "id": "uid_001", "fields": { "f_text": "向量是指在数学中具有一定大小和方向的量", "f_image": "tos://my_bucket/vector_1.jpg" }, "score": 0.51, "ann_score": 9.899999618530273 }, { "id": "uid_002", "fields": { "f_text": "向量是高中数学里的一个重要概念", "f_image": "tos://my_bucket/vector_2.jpg" }, "score": 0.11, "ann_score": 8.324234999961 } ], "total_return_count": 2, "real_text_query": "根据这个问题,找到能回答这个问题的相应文本或图片:向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "token_usage": { "doubao-embedding-vision__250328": { "prompt_tokens":1335, "completion_tokens":0, "image_tokens":1231, "total_tokens":1335 }, "doubao-seed-rerank__251028": { "prompt_tokens":1335, "completion_tokens":0, "image_tokens":1231, "total_tokens":1335 } } } }
{ "collection_name": collection_name, "index_name": index_name, "limit": 3, "output_fields": ["id", "name", "dense_text_vector", "sparse_text_vector", "tensor_text_vector"], "text": "sky is very blue", "instruction": { "auto_fill": false }, "tensor_rerank" : { "input_limit" : 50, }, "advance": { "dense_weight": 0.7 } }
req http status code: 200 req result: { "code": "Success", "message": "The API call was executed successfully.", "request_id": "02176373667508300000000000000000000ffff0a00730abcf2fa", "result": { "data": [ { "id": 85, "fields": { "dense_text_vector": "OUmJbeyyyplieGsPHTft", "id": 85, "name": "FxkdlaxJEe", "sparse_text_vector": "ImUZkmTZLxXVLJEwEIDr", "tensor_text_vector": "KIEdrgNtIjKmAPdgoNdS" }, "score": 225083.109375, "ann_score": 0.18097847700119019 }, { "id": 40, "fields": { "dense_text_vector": "BvUISeyzoEBxduVUPfhO", "id": 40, "name": "hItTJqQtbJ", "sparse_text_vector": "NlNAvNyOJDXZFHiJLyeD", "tensor_text_vector": "IIVuNrxYInoebjVGTLCf" }, "score": 224653.296875, "ann_score": 0.18653953075408936 }, { "id": 90, "fields": { "dense_text_vector": "EGEoGsKBLexTzLXfcFAz", "id": 90, "name": "jLwxYLXUzv", "sparse_text_vector": "KAgXCPHqBQYyXUlpTKkk", "tensor_text_vector": "PggVnXHcaNucUPSWnSRy" }, "score": 224428.125, "ann_score": 0.21451199054718018 } ], "total_return_count": 3, "real_text_query": "sky is very blue", "token_usage": { "doubao-embedding-vision__250615": { "prompt_tokens": 29, "completion_tokens": 0, "image_tokens": 0, "total_tokens": 29 } } } }
""" pip3 install volcengine """ import os from volcengine.auth.SignerV4 import SignerV4 from volcengine.Credentials import Credentials from volcengine.base.Request import Request import requests, json class ClientForDataApi: def __init__(self, ak, sk, host): self.ak = ak self.sk = sk self.host = host def prepare_request(self, method, path, params=None, data=None): r = Request() r.set_shema("https") r.set_method(method) r.set_connection_timeout(10) r.set_socket_timeout(10) mheaders = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Host': self.host, } r.set_headers(mheaders) if params: r.set_query(params) r.set_host(self.host) r.set_path(path) if data is not None: r.set_body(json.dumps(data)) credentials = Credentials(self.ak, self.sk, 'vikingdb', 'cn-beijing') SignerV4.sign(r, credentials) return r def do_req(self, req_method, req_path, req_params, req_body): req = self.prepare_request(method=req_method, path=req_path, params=req_params, data=req_body) return requests.request(method=req.method, url="http://{}{}".format(self.host, req.path), headers=req.headers, data=req.body, timeout=10000) if __name__ == '__main__': client = ClientForDataApi( ak = "*",#替换为您的ak sk = "*",#替换为您的sk host = "api-vikingdb.vikingdb.cn-beijing.volces.com",#替换为您所在的域名 ) req_method = "POST" req_params = None req_path = "/api/vikingdb/data/search/multi_modal" req_body = { "collection_name": "test_coll_with_vectorize", "index_name": "idx_1", "text": "向量是指在数学中具有一定大小和方向的量,文本、图片、音视频等非结构化数据", "instruction": { "auto_fill": true }, "output_fields": [ "f_text" ], "limit": 2 } result = client.do_req(req_method=req_method, req_path=req_path, req_params=req_params, req_body=req_body) print("req http status code: ", result.status_code) print("req result: \n", result.text)