矢量存储
试用版

矢量存储用于存储文件以供file_search工具。source

相关指南: 文件搜索source

创建矢量存储
试用版

POST https://api.openai.com/v1/vector_stores

创建 vector store。source

请求正文

矢量存储应使用的文件 ID 列表。适用于以下工具file_search可以访问文件。source

向量存储的名称。source

向量存储的过期策略。source

用于对文件进行分块的分块策略。如果未设置,将使用auto策略。仅适用于file_ids非空。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

返回

示例请求
1
2
3
4
5
6
7
curl https://api.openai.com/v1/vector_stores \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
  -d '{
    "name": "Support FAQ"
  }'
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
  "id": "vs_abc123",
  "object": "vector_store",
  "created_at": 1699061776,
  "name": "Support FAQ",
  "bytes": 139920,
  "file_counts": {
    "in_progress": 0,
    "completed": 3,
    "failed": 0,
    "cancelled": 0,
    "total": 3
  }
}

列出向量存储
试用版

获取 https://api.openai.com/v1/vector_stores

返回向量存储的列表。source

查询参数

要返回的对象数量限制。Limit 的范围可以介于 1 和 100 之间,默认值为 20。source

created_at对象的时间戳。asc对于升序和desc以降序排列。source

用于分页的游标。after是定义您在列表中的位置的对象 ID。例如,如果您发出列表请求并收到 100 个对象,以 obj_foo 结尾,则您的后续调用可以包含 after=obj_foo 以便获取列表的下一页。source

用于分页的游标。before是定义您在列表中的位置的对象 ID。例如,如果您发出一个列表请求并收到 100 个对象,以 obj_foo 开头,则您的后续调用可以包含 before=obj_foo 以便获取列表的上一页。source

返回

矢量存储对象的列表。source

示例请求
1
2
3
4
curl https://api.openai.com/v1/vector_stores \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
  "object": "list",
  "data": [
    {
      "id": "vs_abc123",
      "object": "vector_store",
      "created_at": 1699061776,
      "name": "Support FAQ",
      "bytes": 139920,
      "file_counts": {
        "in_progress": 0,
        "completed": 3,
        "failed": 0,
        "cancelled": 0,
        "total": 3
      }
    },
    {
      "id": "vs_abc456",
      "object": "vector_store",
      "created_at": 1699061776,
      "name": "Support FAQ v2",
      "bytes": 139920,
      "file_counts": {
        "in_progress": 0,
        "completed": 3,
        "failed": 0,
        "cancelled": 0,
        "total": 3
      }
    }
  ],
  "first_id": "vs_abc123",
  "last_id": "vs_abc456",
  "has_more": false
}

检索向量存储
试用版

获取 https://api.openai.com/v1/vector_stores/{vector_store_id}

检索 vector store。source

路径参数

要检索的向量存储的 ID。source

返回

与指定 ID 匹配的 vector store 对象。source

示例请求
1
2
3
4
curl https://api.openai.com/v1/vector_stores/vs_abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
响应
1
2
3
4
5
{
  "id": "vs_abc123",
  "object": "vector_store",
  "created_at": 1699061776
}

修改向量存储
试用版

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

修改向量存储。source

路径参数

要修改的向量存储的 ID。source

请求正文

向量存储的名称。source

向量存储的过期策略。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

返回

修改后的 vector store 对象。source

示例请求
1
2
3
4
5
6
7
curl https://api.openai.com/v1/vector_stores/vs_abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2"
  -d '{
    "name": "Support FAQ"
  }'
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
  "id": "vs_abc123",
  "object": "vector_store",
  "created_at": 1699061776,
  "name": "Support FAQ",
  "bytes": 139920,
  "file_counts": {
    "in_progress": 0,
    "completed": 3,
    "failed": 0,
    "cancelled": 0,
    "total": 3
  }
}

删除 vector store
试用版

删除 https://api.openai.com/v1/vector_stores/{vector_store_id}

删除 vector store。source

路径参数

要删除的向量存储的 ID。source

返回

删除状态source

示例请求
1
2
3
4
5
curl https://api.openai.com/v1/vector_stores/vs_abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "OpenAI-Beta: assistants=v2" \
  -X DELETE
响应
1
2
3
4
5
{
  id: "vs_abc123",
  object: "vector_store.deleted",
  deleted: true
}

向量存储对象
试用版

向量存储是已处理文件的集合,可供file_search工具。source

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

对象类型,始终为vector_store.source

创建向量存储时的 Unix 时间戳(以秒为单位)。source

向量存储的名称。source

矢量存储中文件使用的总字节数。source

向量存储的状态,可以是expired,in_progresscompleted.状态为completed指示向量存储已准备就绪。source

向量存储的过期策略。source

向量存储过期的 Unix 时间戳(以秒为单位)。source

向量存储上次处于活动状态时的 Unix 时间戳(以秒为单位)。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

OBJECT 向量存储对象
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "id": "vs_123",
  "object": "vector_store",
  "created_at": 1698107661,
  "usage_bytes": 123456,
  "last_active_at": 1698107661,
  "name": "my_vector_store",
  "status": "completed",
  "file_counts": {
    "in_progress": 0,
    "completed": 100,
    "cancelled": 0,
    "failed": 0,
    "total": 100
  },
  "metadata": {},
  "last_used_at": 1698107661
}