PutVectorIndexFusion

更新时间:
复制 MD 格式

调用PutVectorIndexFusion接口在向量Bucket中创建Fusion模式的向量索引。

说明

Fusion Mode 目前处于邀测阶段,仅在印度尼西亚(雅加达)地域提供。Standard 模式向量索引的创建请参见 PutVectorIndex。

注意事项

  • Fusion 模式索引通过 Schema 定义各字段的类型与检索能力,支持向量检索、标量过滤、全文检索等多种检索能力。同一向量Bucket下可同时存在 Standard 模式与 Fusion 模式的索引。

  • 请求中包含服务端不支持的参数时会直接报错。

  • 创建操作只能全部成功或全部失败。

权限说明

阿里云账号默认拥有全部权限。阿里云账号下的RAM用户或RAM角色默认没有任何权限,需要阿里云账号或账号管理员通过RAM Policy概述或Bucket Policy授予操作权限。

API

Action

说明

PutVectorIndexFusion

oss:PutVectorIndexFusion

创建Fusion模式的向量索引。

请求语法

POST /?putVectorIndexFusion HTTP/1.1
Host: examplebucket-123***456.cn-hangzhou-internal.oss-vectors.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue
Content-type: application/json

{
   "indexName": "string",
   "mode": "fusion",
   "schemaConfiguration": {
      "fields": [
         {
            "name": "string",
            "type": "string"
         }
      ]
   }
}

请求头

此接口仅涉及公共请求头。更多信息,请参见公共HTTP头定义。

请求参数

名称

数据类型

是否必选

描述

示例值

indexName

字符串

是

索引名称,用户可自定义。

  • 在向量Bucket内全局唯一,长度 1~63 字符。

  • 只允许字母和数字,首字母必须以字母开头。

vectorindex1

mode

字符串

是

索引模式,创建Fusion模式索引时取值为 fusion。

fusion

schemaConfiguration

对象

是

Schema 配置的容器。服务端不支持的配置将直接报错。

-

fields

对象数组

是

Schema 字段配置。限制如下:

  • 总字段数不超过 100 个。

  • 向量字段数不超过 3 个。

  • 开启分词的字段数不超过 8 个。

  • 其它标量字段占用剩余配额。

  • 至少存在一个 type=vector 的字段。

父节点:schemaConfiguration

-

fields.name

字符串

是

字段名。

  • 单个索引内唯一,长度 1~63 字符。

  • 支持大小写字母、数字和下划线(_),首字母必须以字母开头。

父节点:fields

vector_1

fields.type

字符串

是

字段类型,取值:

  • vector:向量。

  • double:浮点数。

  • long:整数。

  • bool:布尔。

  • string:字符串,可开启分词以支持全文检索。

  • ip:网络协议地址。

  • geoPoint:位置点坐标信息,格式为“纬度,经度”,纬度在前、经度在后,纬度范围为 [-90,+90],经度范围为 [-180,+180]。例如 35.8,-45.91。

父节点:fields

vector

不同字段类型支持的参数

字段类型

名称

数据类型

默认值

描述

是否必选

vector

dataType

字符串

-

向量数据类型,用户不可选,取值:float32(浮点型)。

是

dimension

整型

-

向量维度,仅支持 1~4096 维。

是

distanceMetric

字符串

-

距离度量函数,取值:

  • euclidean:欧氏距离。

  • cosine:余弦距离。

  • ip:内积距离。

是

double

isArray

布尔值

false

是否为数组,数组最大支持 128 个元素。不支持 NaN、正负 Infinity 等值。

否

long

isArray

布尔值

false

是否为数组,数组最大支持 128 个元素。

否

ip

isArray

布尔值

false

是否为数组,数组最大支持 128 个元素。

否

string

isArray

布尔值

false

是否为数组,限制如下:

  • 数组最大支持 512 个元素。

  • 单个 string 元素最大 4 KB,数组所有元素整体最大 64 KB。

  • 该字段开启分词(text)能力时,不支持数组。

  • 该字段开启分区键(isPartitionKey)时,不支持数组。

否

isPartitionKey

布尔值

false

是否作为分区键。

  • 默认使用 hash(vector key) 寻址到对应分区进行写入;配置后使用 hash(partitionKey) 寻址到对应分区进行写入。

  • 仅支持将一个 string 类型字段设置为分区键。

否

exactMatch

布尔值

true

是否支持精确匹配(不分词)的查询能力。例如某字段 field_a 写入 "abcd123",则查询支持 field_a="abcd123" 的过滤能力。开启 exactMatch 后,单个 string 最大 4 KB。默认值与限制如下:

  • string 字段默认 exactMatch=true、text.enabled=false。

  • 当 isPartitionKey=true 时,exactMatch 必须为 true,且不允许开启 text 分词。

  • 当 text.enabled=true 时,exactMatch 必须显式指定 true 或 false。

  • text 与 exactMatch 至少开启一个。在无 isArray、isPartitionKey 功能时,两者允许同时开启。

否

text.enabled

布尔值

false

是否开启分词。开启分词后可支持全文检索算子。分词能力限制如下:

  • 开启分词后,单个 string 最大 64 KB;同时开启 exactMatch 时,单个 string 最大 4 KB。

  • 开启分词的 string 字段不支持数组。

text 为分词字段的父节点,其下可配置 analyzer、analyzerParameters 等参数。

否

text.analyzer

字符串

standard

分词器类型,取值:

  • standard(默认值,允许不填):标准分词器,英文按单词切分、中文按单字切分。

  • split:分隔符分词,用户可自定义分词效果。

否

分词器参数(text.analyzerParameters)

不同分词器支持的参数如下:

  • standard 分词器:

    • caseSensitive:是否大小写敏感。默认值 false,此时所有英文字母会转换为小写。如需保持大小写敏感,可设置为 true。

    • delimitWord:对于英文和数字连接在一起的单词,是否分割英文和数字。默认值 false,表示数字和英文不拆分。设置为 true 时,例如 “iphone6” 会被拆分成 “iphone” 和 “6”。

  • split 分词器:

    • caseSensitive:同 standard 分词器。

    • delimiter:自定义分隔符,必填,无默认值。可选值:空格字符(" ")、竖划线("|")、短横杠("-")、下划线("_")、英文逗号(",")。

响应头

此接口仅涉及公共响应头。更多信息,请参见公共HTTP头定义。

示例

说明

以下示例中的向量取值与维度仅用于示意结构,实际调用时向量长度必须与建表时声明的 dimension 严格一致,否则会报参数非法。

综合示例(全字段类型)

请求示例

POST /?putVectorIndexFusion HTTP/1.1
Host: examplebucket-123***456.cn-hangzhou-internal.oss-vectors.aliyuncs.com
Date: Thu, 17 Apr 2025 01:33:47 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218
Content-type: application/json

{
   "indexName": "vectorindex1",
   "mode": "fusion",
   "schemaConfiguration": {
      "fields": [
         {
            "name": "vector_1",
            "type": "vector",
            "dataType": "float32",
            "dimension": 1024,
            "distanceMetric": "euclidean"
         },
         {
            "name": "vector_2",
            "type": "vector",
            "dataType": "float32",
            "dimension": 512,
            "distanceMetric": "cosine"
         },
         {
            "name": "timestamps",
            "type": "long",
            "isArray": true
         },
         {
            "name": "price",
            "type": "double"
         },
         {
            "name": "ip",
            "type": "ip"
         },
         {
            "name": "location",
            "type": "geoPoint"
         },
         {
            "name": "tag",
            "type": "string"
         },
         {
            "name": "user_id",
            "type": "string",
            "isPartitionKey": true
         },
         {
            "name": "tags",
            "type": "string",
            "isArray": true
         },
         {
            "name": "title_1",
            "type": "string",
            "exactMatch": true,
            "text": {
               "enabled": true,
               "analyzer": "standard",
               "analyzerParameters": {
                  "caseSensitive": true,
                  "delimitWord": false
               }
            }
         },
         {
            "name": "title_2",
            "type": "string",
            "exactMatch": false,
            "text": {
               "enabled": true,
               "analyzer": "split",
               "analyzerParameters": {
                  "caseSensitive": true,
                  "delimiter": " "
               }
            }
         }
      ]
   }
}

返回示例

HTTP/1.1 200 OK
x-oss-request-id: 534B371674E88A4D8906****
Date: Thu, 17 Apr 2025 01:33:47 GMT
Connection: keep-alive
Server: AliyunOSS

最小 Schema:单向量字段

请求示例

POST /?putVectorIndexFusion HTTP/1.1
Host: examplebucket-123***456.cn-hangzhou-internal.oss-vectors.aliyuncs.com
Date: Thu, 17 Apr 2025 01:33:47 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218
Content-type: application/json

{
  "indexName": "docindex",
  "mode": "fusion",
  "schemaConfiguration": {
    "fields": [
      {
        "name": "content_vector",
        "type": "vector",
        "dataType": "float32",
        "dimension": 1024,
        "distanceMetric": "cosine"
      }
    ]
  }
}

多向量:图文视三路多模态

请求示例

POST /?putVectorIndexFusion HTTP/1.1
Host: examplebucket-123***456.cn-hangzhou-internal.oss-vectors.aliyuncs.com
Date: Thu, 17 Apr 2025 01:33:47 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218
Content-type: application/json

{
  "indexName": "multimodalindex",
  "mode": "fusion",
  "schemaConfiguration": {
    "fields": [
      {
        "name": "text_vector",
        "type": "vector",
        "dataType": "float32",
        "dimension": 1024,
        "distanceMetric": "cosine"
      },
      {
        "name": "image_vector",
        "type": "vector",
        "dataType": "float32",
        "dimension": 512,
        "distanceMetric": "euclidean"
      },
      {
        "name": "video_vector",
        "type": "vector",
        "dataType": "float32",
        "dimension": 256,
        "distanceMetric": "ip"
      },
      {
        "name": "title",
        "type": "string",
        "exactMatch": true,
        "text": {
          "enabled": true,
          "analyzer": "standard"
        }
      },
      {
        "name": "duration",
        "type": "long"
      }
    ]
  }
}

全文检索:standard 标准分词器

请求示例

POST /?putVectorIndexFusion HTTP/1.1
Host: examplebucket-123***456.cn-hangzhou-internal.oss-vectors.aliyuncs.com
Date: Thu, 17 Apr 2025 01:33:47 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218
Content-type: application/json

{
  "indexName": "kbindex",
  "mode": "fusion",
  "schemaConfiguration": {
    "fields": [
      {
        "name": "chunk_vector",
        "type": "vector",
        "dataType": "float32",
        "dimension": 1024,
        "distanceMetric": "cosine"
      },
      {
        "name": "title",
        "type": "string",
        "exactMatch": true,
        "text": {
          "enabled": true,
          "analyzer": "standard",
          "analyzerParameters": {
            "caseSensitive": false,
            "delimitWord": true
          }
        }
      },
      {
        "name": "body",
        "type": "string",
        "exactMatch": false,
        "text": {
          "enabled": true,
          "analyzer": "standard"
        }
      },
      {
        "name": "doc_id",
        "type": "string"
      },
      {
        "name": "year",
        "type": "long"
      },
      {
        "name": "status",
        "type": "string"
      },
      {
        "name": "updated_at",
        "type": "long"
      }
    ]
  }
}

分区键:多租户 RAG 知识库

请求示例

POST /?putVectorIndexFusion HTTP/1.1
Host: examplebucket-123***456.cn-hangzhou-internal.oss-vectors.aliyuncs.com
Date: Thu, 17 Apr 2025 01:33:47 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218
Content-type: application/json

{
  "indexName": "tenantkbindex",
  "mode": "fusion",
  "schemaConfiguration": {
    "fields": [
      {
        "name": "chunk_vector",
        "type": "vector",
        "dataType": "float32",
        "dimension": 1024,
        "distanceMetric": "cosine"
      },
      {
        "name": "tenant_id",
        "type": "string",
        "isPartitionKey": true
      },
      {
        "name": "doc_id",
        "type": "string"
      },
      {
        "name": "content",
        "type": "string",
        "exactMatch": false,
        "text": {
          "enabled": true,
          "analyzer": "standard"
        }
      },
      {
        "name": "updated_at",
        "type": "long"
      }
    ]
  }
}

错误码

错误码

HTTP状态码

描述

VectorIndexParameterInvalid

400

请求中提供的向量索引参数不合法。

MalformedJson

400

请求体中的 JSON 格式不符合规范。

VectorBucketIndexExceedLimit

400

创建的索引数量已达到上限。单个向量 Bucket 最多允许创建 100 个向量索引。

AccessDenied

403

返回该错误的可能原因如下:

  • 发起请求时没有传入用户验证信息。

  • 没有操作权限。

VectorBucketIndexAlreadyExist

409

指定的索引名称已存在,无法重复创建。