OpenAI 创建向量存储文件批次接口

2026-11-10 18:20 更新

创建向量存储文件批次

post /vector_stores/{vector_store_id}/file_batches

创建向量存储文件批次。

路径参数

  • vector_store_id: string:此请求涉及的向量存储 ID。

请求体参数

媒体类型为 application/json。

  • attributes: optional map[string or number or boolean] or null

可附加到对象的一组16个键值对,可用于以结构化格式保存额外信息,并通过API或控制台查询对象。键为最长64个字符的字符串;值可以是最长512个字符的字符串、布尔值或数字。

  • string(最长 512 个字符)

  • number

  • boolean

  • chunking_strategy: optional FileChunkingStrategyParam

用于对文件分块的策略。未设置时使用auto策略。

  • AutoFileChunkingStrategyParam object { type }

默认策略。目前使用max_chunk_size_tokens为800、chunk_overlap_tokens为400的设置。

  • type: "auto"

固定为auto。

  • "auto"

  • StaticFileChunkingStrategyObjectParam object { static, type }

通过设置块大小和重叠量,自定义分块策略。

  • static: StaticFileChunkingStrategy

  • chunk_overlap_tokens: integer

相邻块之间重叠的词元数,默认值为400。

注意,重叠量不能超过max_chunk_size_tokens的一半。

  • max_chunk_size_tokens: integer(范围为 100 至 4096)

每个块的最大词元数,默认值为800,最小值为100,最大值为4096。

  • type: "static"

固定为static。

  • "static"

  • file_ids: optional array of string(1 至 2000 项)

向量存储应使用的File ID列表,适用于file_search等可访问文件的工具。如果提供attributes或chunking_strategy,则应用于批次中的所有文件。每批最多2000个文件。建议在摄取多个文件时使用此端点,以降低对每个向量存储的写请求压力。与files互斥。

  • files: optional array of object { file_id, attributes, chunking_strategy }(1 至 2000 项)

对象列表,每个对象包含file_id及可选的attributes或chunking_strategy。需要为特定文件覆盖元数据时使用。全局attributes或chunking_strategy将被忽略,必须为每个文件分别指定。每批最多2000个文件。建议在摄取多个文件时使用此端点,以降低对每个向量存储的写请求压力。与file_ids互斥。

  • file_id: string

向量存储应使用的File ID,适用于file_search等可访问文件的工具。摄取多个文件时,建议使用file_batches,以尽量减少对每个向量存储的写请求。

  • attributes: optional map[string or number or boolean] or null

可附加到对象的一组16个键值对,可用于以结构化格式保存额外信息,并通过API或控制台查询对象。键为最长64个字符的字符串;值可以是最长512个字符的字符串、布尔值或数字。

  • string(最长 512 个字符)

  • number

  • boolean

  • chunking_strategy: optional FileChunkingStrategyParam

用于对文件分块的策略。未设置时使用auto策略。

返回值

  • VectorStoreFileBatch object { id, created_at, file_counts, 3 more }

附加到向量存储的一批文件。

  • id: string

标识符,可在API端点中引用。

  • created_at: integer(Unix 时间戳)

向量存储文件批次创建时的Unix时间戳,单位为秒。

  • file_counts: object { cancelled, completed, failed, 2 more }

  • cancelled: integer

已取消的文件数量。

  • completed: integer

已处理的文件数量。

  • failed: integer

处理失败的文件数量。

  • in_progress: integer

正在处理的文件数量。

  • total: integer

文件总数。

  • object: "vector_store.file_batch"

对象类型,固定为vector_store.file_batch。

  • "vector_store.file_batch"

  • status: "in_progress" or "completed" or "cancelled" or "failed"

向量存储文件批次的状态,可为in_progress、completed、cancelled或failed。

  • "in_progress"

  • "completed"

  • "cancelled"

  • "failed"

  • vector_store_id: string

File所附加到的向量存储的ID。

示例

## [中文] 发送POST请求;将示例API凭证及资源标识替换为应用使用的值。
curl https://api.openai.com/v1/vector_stores/$VECTOR_STORE_ID/file_batches \
    -H 'Content-Type: application/json' \
    -H 'OpenAI-Beta: assistants=v2' \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -d '{
          "file_ids": [
            "string"
          ]
        }'

响应

中文说明:以下为原文配置、命令或事件示例,字段名、枚举、标识符及数值保留。

{
  "id": "id",
  "created_at": 0,
  "file_counts": {
    "cancelled": 0,
    "completed": 0,
    "failed": 0,
    "in_progress": 0,
    "total": 0
  },
  "object": "vector_store.file_batch",
  "status": "in_progress",
  "vector_store_id": "vector_store_id"
}

示例

## [中文] 发送POST请求;将示例API凭证及资源标识替换为应用使用的值。
curl https://api.openai.com/v1/vector_stores/vs_abc123/file_batches \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-Type: application/json \
    -H "OpenAI-Beta: assistants=v2" \
    -d '{
      "files": [
        {
          "file_id": "file-abc123",
          "attributes": {"category": "finance"}
        },
        {
          "file_id": "file-abc456",
          "chunking_strategy": {
            "type": "static",
            "max_chunk_size_tokens": 1200,
            "chunk_overlap_tokens": 200
          }
        }
      ]
    }'

响应

中文说明:以下为原文配置、命令或事件示例,字段名、枚举、标识符及数值保留。

{
  "id": "vsfb_abc123",
  "object": "vector_store.file_batch",
  "created_at": 1699061776,
  "vector_store_id": "vs_abc123",
  "status": "in_progress",
  "file_counts": {
    "in_progress": 1,
    "completed": 1,
    "failed": 0,
    "cancelled": 0,
    "total": 0
  }
}
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号