向量存储文件

向量存储文件表示向量存储中的文件。

相关指南:文件搜索

创建向量存储文件

Beta

post https://api.openai.com/v1/vector_stores/{vector_store_id}/files

通过将一个文件附加到一个向量存储中来创建一个向量存储文件。

路径参数

参数类型必需描述
vector_store_idstring必需向量存储的ID,用于创建文件。

请求体

参数类型必需描述
file_idstring必需一个文件的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_idstring必需文件所属的向量存储的ID。

查询参数

参数类型必需默认值描述
limitinteger可选默认为20返回对象的数量限制。限制范围在1到100之间,默认为20。
orderstring可选默认为desc按对象的 created_at 时间戳排序。asc为升序,desc为降序。
afterstring可选用于分页的光标。after 是定义您在列表中位置的对象ID。例如,如果您发出一个列表请求并收到100个对象,以obj_foo结束,您可以在后续调用中包括 after=obj_foo 以获取列表的下一页。
beforestring可选用于分页的光标。before 是定义您在列表中位置的对象ID。例如,如果您发出一个列表请求并收到100个对象,以obj_foo结束,您可以在后续调用中包括 before=obj_foo 以获取列表的上一页。
filterstring可选按文件状态过滤。可选值为 in_progresscompletedfailedcancelled

返回值

一个向量存储文件对象的列表。

示例请求

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_idstring必需文件所属的向量存储的ID。
file_idstring必需被检索的文件的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_idstring必需文件所属的向量存储的ID。
file_idstring必需要删除的文件的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

向量存储文件对象表示附加到向量存储的文件列表。

属性

参数类型描述
idstring标识符,可以在API端点中引用。
objectstring对象类型,总是 vector_store.file
usage_bytesinteger向量存储的总使用字节数。注意,这可能与原始文件大小不同。
created_atinteger向量存储文件创建时的Unix时间戳(秒)。
vector_store_idstring附加了文件的向量存储的ID。
statusstring向量存储文件的状态,可以是 in_progresscompletedcancelledfailedcompleted 状态表示向量存储文件已准备好使用。
last_errorobject 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
}

Was this page helpful?