(预览)使用 Amazon S3 向量引擎实现高级搜索功能 - Amazon OpenSearch Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

(预览)使用 Amazon S3 向量引擎实现高级搜索功能

重要

Amazon S3 Vectors 与 OpenSearch Service 的集成目前为预览版,可能随时发生变化。

Amazon OpenSearch Service 支持将 Amazon S3 用作向量索引的向量引擎。此功能可将向量数据卸载至 Amazon S3,同时以低成本维持亚秒级的向量搜索功能。

借助此功能,OpenSearch 可将向量嵌入存储在 Amazon S3 向量索引中,同时将其他文档字段保留在 OpenSearch 集群的存储中。此架构具有以下优势:

  • 持久性:写入 S3 Vectors 的数据存储在 S3 上,以实现 11 个 9 的数据持久性。

  • 可扩展性:将大型向量数据集卸载至 S3,无需占用集群存储空间。

  • 成本效益:优化向量密集型工作负载的存储成本。

OpenSearch 对使用 S3 向量索引有以下要求:

  • OpenSearch 版本 2.19 或更高版本

  • OpenSearch 优化型实例

  • OpenSearch 版本的最新补丁版本

启用 S3 Vectors

创建新域或更新现有域时,可在高级功能部分中选择启用 S3 Vectors 作为引擎选项。当使用 S3 Vectors 作为引擎时,此设置允许 OpenSearch 创建 S3 向量存储桶。启用此选项后,OpenSearch 会通过以下方式为域配置 S3 Vectors:

  1. 在使用域配置的 Amazon KMS 密钥上创建两个新授权:

    • 授予 S3 Vectors 后台索引任务解密权限

    • 授予 OpenSearch 创建 S3 向量存储桶的 GenerateDataKey 权限

  2. 将 OpenSearch 域使用的 KMS 密钥配置为 CMK,用于对所有向量索引数据进行静态加密。

使用 S3 向量引擎创建索引

配置域后,可在索引映射中使用 s3vector 作为后端向量引擎,创建一个或多个包含字段的 k-NN 索引。您可以根据具体使用案例,配置不同引擎类型的向量字段。

重要

创建索引期间,仅能使用 s3vector 引擎映射字段定义。创建索引后,您无法使用 s3vector 引擎添加或更新映射。

以下是创建 S3 向量引擎索引的一些示例。

示例:使用 S3 向量引擎创建 k-NN 索引

PUT my-first-s3vector-index { "settings": { "index": { "knn": true } }, "mappings": { "properties": { "my_vector_1": { "type": "knn_vector", "dimension": 2, "space_type": "l2", "method": { "engine": "s3vector" } }, "price": { "type": "float" } } } }

示例:同时使用 S3 向量和 FAISS 引擎创建 k-NN 索引

此示例强调可在同一个索引中使用多个向量引擎这一事实。

PUT my-vector-index { "settings": { "index": { "knn": true } }, "mappings": { "properties": { "my_vector_1": { "type": "knn_vector", "dimension": 2, "space_type": "l2", "method": { "engine": "s3vector" } }, "price": { "type": "float" }, "my_vector_2": { "type": "knn_vector", "dimension": 2, "space_type": "cosine", "method": { "name": "hnsw", "engine": "faiss", "parameters": { "ef_construction": 128, "m": 24 } } } } } }

不支持的示例:创建索引后添加 S3 向量引擎

以下方法不受支持且会失败。

PUT my-first-s3vector-index { "settings": { "index": { "knn": true } } } PUT my-first-s3vector-index/_mapping { "properties": { "my_vector_1": { "type": "knn_vector", "dimension": 2, "space_type": "l2", "method": { "engine": "s3vector" } }, "price": { "type": "float" } } }

功能限制

在索引中使用 s3vector 引擎之前,请考虑以下限制:

s3vector 引擎不支持相关功能和行为
功能 行为

拆分/缩减/克隆索引

这些 API 与 knn_vector 字段中已配置 s3vector 引擎的索引一起使用时会失败。

快照

使用 s3vector 引擎的索引不支持快照。对于托管域:

  • 自动快照仅包括未使用 s3vector 引擎的索引。

  • s3vector 索引的手动快照请求失败。

注意

虽然快照不支持进行时间点恢复,但 s3vector 引擎和 OpenSearch 优化型实例可提供 11 个 9 的持久性。

UltraWarm 层

已配置 s3vector 引擎的索引无法迁移到 UltraWarm 层。

跨集群复制

已配置 s3vector 引擎的索引不支持跨集群复制。

意外删除保护

由于使用 s3vector 引擎的索引不支持快照,因此意外删除保护不可用。仍可恢复域中的其他索引。

径向搜索

使用 s3vector 引擎的字段不支持使用径向搜索的查询。

索引文档

使用 S3 向量引擎创建索引后,您可以使用标准 _bulk API 提取文档。OpenSearch 使用 s3vector 引擎自动将 knn_vector 字段的向量数据实时卸载到 S3 向量索引。属于其他字段或使用不同引擎的 knn_vector 字段的数据,将由 OpenSearch 在其自身的存储层中进行持久化存储。

对于所有已确认的批量请求,OpenSearch 保证所有数据(向量和非向量数据)均具有持久性。如果请求收到否定确认,则无法保证该批量请求中文档的持久性。应当重试此类请求。

批量索引示例

POST _bulk { "index": { "_index": "my-first-s3vector-index", "_id": "1" } } { "my_vector_1": [1.5, 2.5], "price": 12.2 } { "index": { "_index": "my-first-s3vector-index", "_id": "2" } } { "my_vector_1": [2.5, 3.5], "price": 7.1 } { "index": { "_index": "my-first-s3vector-index", "_id": "3" } } { "my_vector_1": [3.5, 4.5], "price": 12.9 } { "index": { "_index": "my-first-s3vector-index", "_id": "4" } } { "my_vector_1": [5.5, 6.5], "price": 1.2 } { "index": { "_index": "my-first-s3vector-index", "_id": "5" } } { "my_vector_1": [4.5, 5.5], "price": 3.7 }

搜索文档

您可以使用标准 _search API 搜索索引,以执行文本、k-NN 或混合查询。对于已配置 s3vector 引擎的 knn_vector 字段的查询,OpenSearch 会自动将查询卸载到相应的 S3 向量索引。

注意

使用 s3vector 引擎时,刷新语义仅适用于未使用 s3vector 引擎的字段。然后,卸载到 s3vector 的向量数据将在文档成功索引后立即可见。

示例搜索查询

GET my-first-s3vector-index/_search { "size": 2, "query": { "knn": { "my_vector_1": { "vector": [2.5, 3.5], "k": 2 } } } }

支持的映射参数

使用 s3vector 引擎时,knn_vector 字段在映射中支持以下参数。

向量字段参数
参数 必需 描述 支持的值
type 显示在文档中的字段类型。 knn_vector
dimension 要提取到索引中每个向量的维度。 >0,<=4096
space_type 用于计算向量间距离的向量空间。 l2, cosinesimil
method.engine 用于索引和搜索的近似 k-NN 引擎。 s3vector
method.name 最近邻方法 ""
重要

使用 s3vector 引擎不支持嵌套 knn_vector 字段类型

计量和计费

公布计量之前,此功能不会计费。

禁用 s3vector 引擎

禁用 s3vector 引擎之前,删除当前正在使用该引擎的所有索引。否则,任何禁用引擎的尝试都会失败。

另请注意,启用或禁用 s3vector 引擎会触发域上的蓝绿部署

要禁用 s3vector 引擎,请编辑域配置,并设置 S3VectorsEngine.Enabled: false