文档

预测查询

功能说明

预测查询是指用户将文本、图片通过向量检索版内置的向量化模型生成向量,并通过文本或图片进行检索的查询方式。

注:若您已有向量并直接将向量导入向量检索版实例中进行检索,请参考向量查询

URL

/vector-service/inference-query

  • 以上 URL 省略了请求Header参数及编码等因素。

  • 以上 URL 中省略了访问应用的 host 地址。

  • 以上URL 中拼接的所有查询参数,请查看下方“查询参数”的参数定义、使用方式及样例。

请求协议

HTTP

请求方式

POST

支持格式

JSON

签名机制

可用以下方法计算签名(authorization

参数

类型

描述

accessUserName

string

用户名,可在实例详情页>网络信息查看

accessPassWord

string

密码,可在实例详情页>网络信息修改

import com.aliyun.darabonba.encode.Encoder;
import com.aliyun.darabonbastring.Client;

public class GenerateAuthorization {
 public static void main(String[] args) throws Exception {
 String accessUserName = "username";
 String accessPassWord = "password";
 String realmStr = "" + accessUserName + ":" + accessPassWord + "";
 String authorization = Encoder.base64EncodeToString(Client.toBytes(realmStr, "UTF-8"));
 System.out.println(authorization);
 }
}

authorization正确返回格式:

cm9vdDp******mdhbA==

使用HTTP请求设置authorization参数需加上Basic前缀

示例:(在header中加入)

authorization: Basic cm9vdDp******mdhbA==

请求body参数

参数名称

描述

默认值

类型

是否必须

tableName

查询的表名

string

content

需要预测的数据

string

modal

向量化模型的值有2种

  • text:文本向量化就是以文搜文,图片向量化就是以文搜图

  • image:图片向量化就是以图搜图

string

namespace

查询向量的空间

""

string

topK

返回个数

100

int

includeVector

是否返回文档中的向量信息

false

bool

outputFields

需要返回值的字段列表

[]

list[string]

order

排序顺序, ASC:升序 DESC: 降序

ASC

string

searchParams

查询参数

""

string

filter

过滤表达式

""

string

scoreThreshold

分数过滤, 使用欧式距离时,只返回小于scoreThreshold的结果。使用内积时,只返回大于scoreThreshold的结果

默认不过滤

float

返回参数

字段名称

描述

类型

result

结果列表

list[Item]

totalCount

result中的个数

int

totalTime

引擎处理耗时,单位ms

float

errorCode

错误码,有错误时才有该字段

int

errorMsg

错误信息,有错误时才有该字段

string

  • item定义

字段名称

描述

类型

score

距离分

float

fields

字段名称和对应的值

map<string, FieldType>

vector

向量值

list[float]

id

主键值,类型为所定义的字段类型

FieldType

namespace

向量的名称空间,如果设置了namespace会返回该字段

string

示例

文本向量化检索

  • 请求body:

{
  "tableName": "gist",
	"content": "hello",
    "modal": "text",
  "topK": 3,
  "searchParams":"{\"qc.searcher.scan_ratio\":0.01}",
  "includeVector": true
}
  • 返回参数:

{
  "result":[
    {
      "id": 1,
      "score":1.0508723258972169,
      "vector": [0.1, 0.2, 0.3]
    },
    {
      "id": 2,
      "score":1.0329746007919312,
      "vector": [0.2, 0.2, 0.3]
    },
    {
      "id": 3,
      "score":0.980593204498291,
      "vector": [0.3, 0.2, 0.3]
    }
  ],
  "totalCount":3,
  "totalTime":2.943
}

图片向量化

以文搜图

  • 请求body:

{
  "tableName": "gist",
	"content": "自行车",
    "modal": "text",
  "topK": 3,
  "searchParams":"{\"qc.searcher.scan_ratio\":0.01}",
  "includeVector": true
}
  • 返回参数:

{
  "result":[
    {
      "id": 1,
      "score":1.0508723258972169,
      "vector": [0.1, 0.2, 0.3]
    },
    {
      "id": 2,
      "score":1.0329746007919312,
      "vector": [0.2, 0.2, 0.3]
    },
    {
      "id": 3,
      "score":0.980593204498291,
      "vector": [0.3, 0.2, 0.3]
    }
  ],
  "totalCount":3,
  "totalTime":2.943
}

以图搜图

  • 请求body:

{
  "tableName": "gist",
	"content": "base64编码的图片",
    "modal": "image",
  "topK": 3,
  "searchParams":"{\"qc.searcher.scan_ratio\":0.01}",
  "includeVector": true
}
  • 返回参数:

{
    "totalCount": 5,
    "result": [
        {
            "id": 5,
            "score": 1.103209137916565
        },
        {
            "id": 3,
            "score": 1.1278988122940064
        },
        {
            "id": 2,
            "score": 1.1326735019683838
        }
    ],
    "totalTime": 242.615
}

主体识别

  • 请求body:

未传入range:

{
 "tableName": "gist",
 "content": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQ",
 "modal": "image",
 "searchParams": "{\"crop\": true}",
 "topK": 3,
 "includeVector": true
}

"crop":true表示使用主体进行查询,未传入range则会调用主体识别模型

传入range:

{
 "tableName": "gist",
	"content": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQ",
 "modal": "image",
 "searchParams": "{\"crop\": true, \"range\": \"100,100,60,70\"}",
 "topK": 3,
 "includeVector": true
}

"crop":true, "range":"100,100,60,70"表示使用主体进行查询,range表示主体在图片中的区域,四个数分别表示主体区域左上角点的(x, y)坐标,宽度width,高度height。

  • 返回参数:

{
 "result":[
 {
 "id": 1,
 "score":1.0508723258972169,
 "vector": [0.1, 0.2, 0.3]
 }
 ],
 "__meta__": {
 "__range__": "100,100,60,70;",
 }
 "totalCount":1,
 "totalTime":2.943
}

  • 主体识别中modal=image时,返回参数中才会有__range__ 相关主体识别的内容返回

  • __range__表示主体在图片中的区域,四个数分别表示主体区域左上角点的(x, y)坐标,宽度width,高度height。

  • 如果模型识别出了多个主体,__range__按照模型打分从高到低排列每个主题,且默认返回第一个主体的向量查询结果。

  • 本页导读 (0)
文档反馈