向量存储文件
向量存储文件表示向量存储中的文件。
相关指南:文件搜索
创建向量存储文件
Beta
post https://api.openai.com/v1/vector_stores/{vector_store_id}/files
路径参数
| 参数 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| vector_store_id | string | 必需 | 向量存储的ID,用于创建文件。 | 
请求体
| 参数 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| file_id | string | 必需 | 一个文件的ID,向量存储应该使用该文件。适用于可以访问文件的工具,如 file_search。 | 
返回值
一个向量存储文件对象。
示例请求
curl https://api.openai.com/v1/vector_stores/vs_abc123/files \
    -H "Authorization: Bearer $OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -H "OpenAI-Beta: assistants=v2" \
    -d '{
      "file_id": "file-abc123"
    }'
响应
{
  "id": "file-abc123",
  "object": "vector_store.file",
  "created_at": 1699061776,
  "usage_bytes": 1234,
  "vector_store_id": "vs_abcd",
  "status": "completed",
  "last_error": null
}
列出向量存储文件
Beta
get https://api.openai.com/v1/vector_stores/{vector_store_id}/files
返回向量存储文件的列表。
路径参数
| 参数 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| vector_store_id | string | 必需 | 文件所属的向量存储的ID。 | 
查询参数
| 参数 | 类型 | 必需 | 默认值 | 描述 | 
|---|---|---|---|---|
| limit | integer | 可选 | 默认为20 | 返回对象的数量限制。限制范围在1到100之间,默认为20。 | 
| order | string | 可选 | 默认为 desc | 按对象的 created_at时间戳排序。asc为升序,desc为降序。 | 
| after | string | 可选 | 无 | 用于分页的光标。 after是定义您在列表中位置的对象ID。例如,如果您发出一个列表请求并收到100个对象,以obj_foo结束,您可以在后续调用中包括after=obj_foo以获取列表的下一页。 | 
| before | string | 可选 | 无 | 用于分页的光标。 before是定义您在列表中位置的对象ID。例如,如果您发出一个列表请求并收到100个对象,以obj_foo结束,您可以在后续调用中包括before=obj_foo以获取列表的上一页。 | 
| filter | string | 可选 | 无 | 按文件状态过滤。可选值为 in_progress、completed、failed、cancelled。 | 
返回值
一个向量存储文件对象的列表。
示例请求
curl https://api.openai.com/v1/vector_stores/vs_abc123/files \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
响应
{
  "object": "list",
  "data": [
    {
      "id": "file-abc123",
      "object": "vector_store.file",
      "created_at": 1699061776,
      "vector_store_id": "vs_abc123"
    },
    {
      "id": "file-abc456",
      "object": "vector_store.file",
      "created_at": 1699061776,
      "vector_store_id": "vs_abc123"
    }
  ],
  "first_id": "file-abc123",
  "last_id": "file-abc456",
  "has_more": false
}
检索向量存储文件
Beta
get https://api.openai.com/v1/vector_stores/{vector_store_id}/files/{file_id}
检索一个向量存储文件。
路径参数
| 参数 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| vector_store_id | string | 必需 | 文件所属的向量存储的ID。 | 
| file_id | string | 必需 | 被检索的文件的ID。 | 
返回值
一个向量存储文件对象。
示例请求
curl https://api.openai.com/v1/vector_stores/vs_abc123/files/file-abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
响应
{
  "id": "file-abc123",
  "object": "vector_store.file",
  "created_at": 1699061776,
  "vector_store_id": "vs_abcd",
  "status": "completed",
  "last_error": null
}
删除向量存储文件
Beta
delete https://api.openai.com/v1/vector_stores/{vector_store_id}/files/{file_id}
删除一个向量存储文件。这将从向量存储中移除文件,但文件本身不会被删除。要删除文件,请使用删除文件端点。
路径参数
| 参数 | 类型 | 必需 | 描述 | 
|---|---|---|---|
| vector_store_id | string | 必需 | 文件所属的向量存储的ID。 | 
| file_id | string | 必需 | 要删除的文件的ID。 | 
返回值
删除状态
示例请求
curl https://api.openai.com/v1/vector_stores/vs_abc123/files/file-abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2" \
  -X DELETE
响应
{
  "id": "file-abc123",
  "object": "vector_store.file.deleted",
  "deleted": true
}
向量存储文件对象
Beta
向量存储文件对象表示附加到向量存储的文件列表。
属性
| 参数 | 类型 | 描述 | 
|---|---|---|
| id | string | 标识符,可以在API端点中引用。 | 
| object | string | 对象类型,总是 vector_store.file。 | 
| usage_bytes | integer | 向量存储的总使用字节数。注意,这可能与原始文件大小不同。 | 
| created_at | integer | 向量存储文件创建时的Unix时间戳(秒)。 | 
| vector_store_id | string | 附加了文件的向量存储的ID。 | 
| status | string | 向量存储文件的状态,可以是 in_progress、completed、cancelled或failed。completed状态表示向量存储文件已准备好使用。 | 
| last_error | object or null | 与此向量存储文件关联的最后一个错误。如果没有错误,将为 null。 | 
示例
{
  "id": "file-abc123",
  "object": "vector_store.file",
  "usage_bytes": 1234,
  "created_at": 1698107661,
  "vector_store_id": "vs_abc123",
  "status": "completed",
  "last_error": null
}