OpenAI

知识库

OpenAI SDK 知识库操作与兼容差异。

官方 openai Python SDK 可直接使用知识库、文件和批次操作。两个地址访问同一份数据。

https://api.deepraxis.ai/openai/v1

快速开始:官方 Python SDK

当前差异

搜索按块返回,同一文件可能出现多次;max_num_results 计算块数。rewrite_query 为 true 时先用小模型改写查询(按模型用量计费,失败时回退原查询),改写所用模型只能在原生 API 的 models 中设置,兼容接口传 models 返回 400。搜索 has_more 恒为 false、next_page 恒为 null。description 接受后丢弃。expand=files 与 expand[]=files 为 Praxis 扩展;未知值忽略。

删除知识库后保留 7 天,读取仍可返回 200 completed,但写入和搜索返回 409。恢复、失败重试、分段、事件和混合搜索权重请使用原生 API;兼容接口不返回 praxis、chunk_id、page 或 span。usage_bytes 为抽取文本块的字节数。未知请求字段当前会被忽略。

原生 API · 错误码

方法路径操作
POST/openai/v1/vector_stores创建知识库
GET/openai/v1/vector_stores列出知识库
GET/openai/v1/vector_stores/{vector_store_id}读取知识库
POST/openai/v1/vector_stores/{vector_store_id}更新知识库
DELETE/openai/v1/vector_stores/{vector_store_id}删除知识库
POST/openai/v1/vector_stores/{vector_store_id}/search搜索知识库
POST/openai/v1/vector_stores/{vector_store_id}/files添加文件
GET/openai/v1/vector_stores/{vector_store_id}/files列出文件
GET/openai/v1/vector_stores/{vector_store_id}/files/{file_id}读取文件
POST/openai/v1/vector_stores/{vector_store_id}/files/{file_id}更新文件属性
DELETE/openai/v1/vector_stores/{vector_store_id}/files/{file_id}移除文件
GET/openai/v1/vector_stores/{vector_store_id}/files/{file_id}/content读取抽取内容
POST/openai/v1/vector_stores/{vector_store_id}/file_batches创建文件批次
GET/openai/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}读取文件批次
POST/openai/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel取消文件批次
GET/openai/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}/files列出批次文件

创建知识库

POST /openai/v1/vector_stores

创建知识库。可用 file_ids 添加已有 File 并异步入库;后续调用使用返回的 id。最小请求体:{"name":"Refund policies"}。

请求体

字段类型说明
namestring可选; 省略时为空字符串;不接受 null。; 最长字符数: 256; 默认: ""
metadataobject / null可选; 知识库自定义字符串元数据;省略或 null 得到空对象。; 默认: {}
expires_afterobject / null可选; 从最近活动计算的过期策略;省略或 null 表示不自动过期。; 默认: null
expires_after (1).anchor"last_active_at"必填; last_active_at 表示从最近活动时间开始计算过期。
expires_after (1).daysinteger必填; 自最近活动起的天数;添加文件和搜索会刷新活动时间。; 最小: 1; 最大: 365
file_idsstring[]可选; 要加入的已有文件 ID;每库最多 10,000 个文件。
chunking_strategyobject / object可选; auto 等同于每段 800 token、重叠 400 token。; 默认: {"type":"auto"}
chunking_strategy (1).type"auto"必填; auto 使用默认静态分段:800 个估算 token,重叠 400 个。
chunking_strategy (2).type"static"必填; static 表示使用显式分段大小与重叠设置。
chunking_strategy (2).staticobject必填; 以估算 token 数表示的分段大小与重叠限制。
chunking_strategy (2).static.max_chunk_size_tokensinteger必填; 每段的估算 token 数。; 最小: 100; 最大: 4096
chunking_strategy (2).static.chunk_overlap_tokensinteger必填; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
descriptionstring可选; 不生效: 接受后丢弃,不保存也不返回;当前不校验类型。

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores" \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"name\":\"Refund policies\"}"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store"必有; 对象标记;vector_store 表示知识库。
namestring必有; 知识库显示名称;空字符串表示未设置名称。; 最长字符数: 256
status"in_progress" / "completed" / "expired"必有; in_progress 表示仍有文件入库中;completed 表示没有入库中的文件,不保证全部成功;expired 表示过期策略已生效。
usage_bytesinteger必有; 已完成源文件的字节数之和。; 最小: 0
file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。
last_active_atinteger / null必有; 最近创建、添加文件或搜索的 Unix 秒时间戳;不可用时为 null。
expires_afterobject / null必有; 从最近活动开始计算的过期策略;null 表示不自动过期。
expires_after (1).anchor"last_active_at"必有; last_active_at 表示从最近活动时间开始计算过期。
expires_after (1).daysinteger必有; 自最近活动起的天数;添加文件和搜索会刷新活动时间。; 最小: 1; 最大: 365
expires_atinteger / null必有; 预计过期的 Unix 秒时间戳;未设置过期策略时为 null。
metadataobject必有; 最多 16 个键;键最多 64 字符;字符串值最多 512 字符。; 最多键数: 16; 键最多 64 字符; 值: string

错误码与错误对象

列出知识库

GET /openai/v1/vector_stores

列出调用方可见的知识库,默认最新在前。将 last_id 作为 after 读取下一页,例如 ?limit=20。

参数

名称位置与类型说明
afterquery: string上一页的 ID 游标。 最短字符数: 1
beforequery: string返回此 ID 之前的条目。 最短字符数: 1
limitquery: integer每页条数。 最小: 1; 最大: 100; 默认: 20
orderquery: "asc" / "desc"知识库和文件默认按创建时间降序;分段默认按序号升序。 默认: "desc"

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
object"list"必有; 对象标记;list 表示游标分页集合。
dataobject[]必有; 按请求顺序返回的当前页条目。
data[].idstring必有; 资源 ID。; 最短字符数: 1
data[].object"vector_store"必有; 对象标记;vector_store 表示知识库。
data[].namestring必有; 知识库显示名称;空字符串表示未设置名称。; 最长字符数: 256
data[].status"in_progress" / "completed" / "expired"必有; in_progress 表示仍有文件入库中;completed 表示没有入库中的文件,不保证全部成功;expired 表示过期策略已生效。
data[].usage_bytesinteger必有; 已完成源文件的字节数之和。; 最小: 0
data[].file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
data[].file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
data[].file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
data[].file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
data[].file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
data[].file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
data[].created_atinteger必有; Unix 时间戳,单位秒。
data[].last_active_atinteger / null必有; 最近创建、添加文件或搜索的 Unix 秒时间戳;不可用时为 null。
data[].expires_afterobject / null必有; 从最近活动开始计算的过期策略;null 表示不自动过期。
data[].expires_after (1).anchor"last_active_at"必有; last_active_at 表示从最近活动时间开始计算过期。
data[].expires_after (1).daysinteger必有; 自最近活动起的天数;添加文件和搜索会刷新活动时间。; 最小: 1; 最大: 365
data[].expires_atinteger / null必有; 预计过期的 Unix 秒时间戳;未设置过期策略时为 null。
data[].metadataobject必有; 最多 16 个键;键最多 64 字符;字符串值最多 512 字符。; 最多键数: 16; 键最多 64 字符; 值: string
first_idstring / null必有; 本页首项的 ID;空页为 null。
last_idstring / null必有; 本页末项的 ID,可作为 after 继续查询;空页为 null。
has_moreboolean必有; 当前游标范围内,本页之后是否还有条目。

错误码与错误对象

读取知识库

GET /openai/v1/vector_stores/{vector_store_id}

使用创建或列表返回的 id 读取知识库。添加 ?expand=files 可同时返回附件首页。已删除的库返回 404。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
expandquery: "files"[]两个地址均支持的 Praxis 扩展:files 附带文件首页;未知值忽略。
expand[]query: "files"[]两个地址均支持的 Praxis 扩展:files 附带文件首页;未知值忽略。

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
(1).idstring必有; 资源 ID。; 最短字符数: 1
(1).object"vector_store"必有; 对象标记;vector_store 表示知识库。
(1).namestring必有; 知识库显示名称;空字符串表示未设置名称。; 最长字符数: 256
(1).status"in_progress" / "completed" / "expired"必有; in_progress 表示仍有文件入库中;completed 表示没有入库中的文件,不保证全部成功;expired 表示过期策略已生效。
(1).usage_bytesinteger必有; 已完成源文件的字节数之和。; 最小: 0
(1).file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
(1).file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
(1).file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
(1).file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
(1).file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
(1).file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
(1).created_atinteger必有; Unix 时间戳,单位秒。
(1).last_active_atinteger / null必有; 最近创建、添加文件或搜索的 Unix 秒时间戳;不可用时为 null。
(1).expires_afterobject / null必有; 从最近活动开始计算的过期策略;null 表示不自动过期。
(1).expires_after (1).anchor"last_active_at"必有; last_active_at 表示从最近活动时间开始计算过期。
(1).expires_after (1).daysinteger必有; 自最近活动起的天数;添加文件和搜索会刷新活动时间。; 最小: 1; 最大: 365
(1).expires_atinteger / null必有; 预计过期的 Unix 秒时间戳;未设置过期策略时为 null。
(1).metadataobject必有; 最多 16 个键;键最多 64 字符;字符串值最多 512 字符。; 最多键数: 16; 键最多 64 字符; 值: string
(2).filesobject可选; 仅在 expand=files 时返回文件首页。
(2).files.object"list"必有; 对象标记;list 表示游标分页集合。
(2).files.dataobject[]必有; 按请求顺序返回的当前页条目。
(2).files.data[].idstring必有; 与源文件相同的 ID。; 最短字符数: 1
(2).files.data[].object"vector_store.file"必有; 对象标记;vector_store.file 表示知识库中的附件。
(2).files.data[].vector_store_idstring必有; 资源 ID。; 最短字符数: 1
(2).files.data[].status"in_progress" / "completed" / "cancelled" / "failed"必有; in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。
(2).files.data[].last_errorobject / null必有; 入库失败详情;未失败、成功完成或重新入库时为 null。
(2).files.data[].last_error (1).code"server_error" / "unsupported_file" / "invalid_file"必有; unsupported_file 表示不支持的文件类型;invalid_file 表示加密、空文件或超过解析 token 上限;server_error 表示其它入库失败或超过截止时间。
(2).files.data[].last_error (1).messagestring必有; 与 code 对应的入库失败说明。
(2).files.data[].usage_bytesinteger必有; 完成后计入源文件字节数;处理中、失败或已取消时为零。; 最小: 0
(2).files.data[].created_atinteger必有; Unix 时间戳,单位秒。
(2).files.data[].chunking_strategyobject / object必有; 此附件已保存的分段策略;auto 输入返回为具体 static 设置。
(2).files.data[].chunking_strategy (1).type"static"必有; static 表示使用显式分段大小与重叠设置。
(2).files.data[].chunking_strategy (1).staticobject必有; 以估算 token 数表示的分段大小与重叠限制。
(2).files.data[].chunking_strategy (1).static.max_chunk_size_tokensinteger必有; 每段的估算 token 数。; 最小: 100; 最大: 4096
(2).files.data[].chunking_strategy (1).static.chunk_overlap_tokensinteger必有; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
(2).files.data[].chunking_strategy (2).type"other"必有
(2).files.data[].attributesobject / null必有; 用于搜索筛选的文件属性;null 表示未设置。
(2).files.first_idstring / null必有; 本页首项的 ID;空页为 null。
(2).files.last_idstring / null必有; 本页末项的 ID,可作为 after 继续查询;空页为 null。
(2).files.has_moreboolean必有; 当前游标范围内,本页之后是否还有条目。

错误码与错误对象

更新知识库

POST /openai/v1/vector_stores/{vector_store_id}

使用返回的 id 修改活跃知识库。省略的字段不变;metadata 替换整个对象。请求体示例:{"name":"Refund policies"}。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1

请求体

字段类型说明
namestring / null可选; null 将名称清空为空字符串;省略的字段不变。
metadataobject / null可选; 替换全部元数据;null 清空为一个空对象。
expires_afterobject / null可选; null 取消自动过期。
expires_after (1).anchor"last_active_at"必填; last_active_at 表示从最近活动时间开始计算过期。
expires_after (1).daysinteger必填; 自最近活动起的天数;添加文件和搜索会刷新活动时间。; 最小: 1; 最大: 365

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"name\":\"Support policies\"}"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store"必有; 对象标记;vector_store 表示知识库。
namestring必有; 知识库显示名称;空字符串表示未设置名称。; 最长字符数: 256
status"in_progress" / "completed" / "expired"必有; in_progress 表示仍有文件入库中;completed 表示没有入库中的文件,不保证全部成功;expired 表示过期策略已生效。
usage_bytesinteger必有; 已完成源文件的字节数之和。; 最小: 0
file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。
last_active_atinteger / null必有; 最近创建、添加文件或搜索的 Unix 秒时间戳;不可用时为 null。
expires_afterobject / null必有; 从最近活动开始计算的过期策略;null 表示不自动过期。
expires_after (1).anchor"last_active_at"必有; last_active_at 表示从最近活动时间开始计算过期。
expires_after (1).daysinteger必有; 自最近活动起的天数;添加文件和搜索会刷新活动时间。; 最小: 1; 最大: 365
expires_atinteger / null必有; 预计过期的 Unix 秒时间戳;未设置过期策略时为 null。
metadataobject必有; 最多 16 个键;键最多 64 字符;字符串值最多 512 字符。; 最多键数: 16; 键最多 64 字符; 值: string

错误码与错误对象

删除知识库

DELETE /openai/v1/vector_stores/{vector_store_id}

删除后读取和重复 DELETE 返回 404 not_found_error,列表不含已删除库;自有面可在 7 天内恢复。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1

请求示例

curl -X DELETE "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store.deleted"必有; 对象标记;vector_store.deleted 表示此操作回执。
deletedtrue必有; 确认兼容面的知识库删除;后续访问返回未找到。

错误码与错误对象

搜索知识库

POST /openai/v1/vector_stores/{vector_store_id}/search

每文件一条,content 为按分数降序的命中块;max_num_results 计文件,从最多 50 个召回分段聚合。has_more 表示文件结果截断,next_page 仍为 null。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1

请求体

字段类型说明
querystring / string[]必填; 非空白文本;多个查询以换行连接后共同搜索。
filtersobject / object / object可选; 按类型严格匹配文件属性;根条件以下最多嵌套 20 层。
filters (1).type"eq" / "ne" / "gt" / "gte" / "lt" / "lte"必填; eq 等于,ne 不等于,gt 大于,gte 大于等于,lt 小于,lte 小于等于;属性必须存在且值类型一致。
filters (1).keystring必填; 要比较的文件属性原始键名,标点也是键名的一部分。; 最短字符数: 1
filters (1).valuestring / number / boolean必填; 不进行类型转换的比较值。
filters (2).type"in" / "nin"必填; in 匹配数组中的值;nin 匹配不在数组中的值。属性不存在时均不匹配。
filters (2).keystring必填; 要比较的文件属性原始键名,标点也是键名的一部分。; 最短字符数: 1
filters (2).valuestring / number[]必填; 不进行类型转换的字符串或数值成员列表。
filters (3).type"and" / "or"必填; and 要求所有子条件匹配;or 要求至少一个子条件匹配。
filters (3).filtersobject / object / object[]必填; 按选定 and/or 运算符组合的非空子条件列表。; 最少条数: 1
filters (3).filters[]object / object / object递归使用同一筛选结构,嵌套上限 20 层。
max_num_resultsinteger可选; 从最多 50 个召回分段聚合后,最多返回的不同文件数。; 最小: 1; 最大: 50; 默认: 10
rewrite_queryboolean可选; 支持: 为 true 时,先用该库 query_rewrite 角色的模型把每条查询改写为简洁的检索查询;检索使用改写结果,search_query 返回改写后的查询。每次改写是一次小模型调用,按模型用量计费。改写失败、超时(5 秒)或为空时,该条查询回退为原文,搜索照常完成。省略或为 false 时不调用模型。
next_pagestring可选; 不生效: 搜索不支持翻页;提供游标不生效。
ranking_optionsobject可选; 控制结果排序与纳入结果的最低分数。
ranking_options.ranker"none" / "auto" / "default-2024-11-15"可选; 只有 default-2024-11-15 请求重排;none、auto 和省略时使用初始排序。尚未单独实测重排效果。
ranking_options.score_thresholdnumber可选; 最低分数;分数不是相关性概率。尚未单独实测阈值效果。; 最小: 0; 最大: 1; 默认: 0
ranking_options.hybrid_searchobject可选; 不支持: 在 /openai/v1 返回 400 INVALID_PARAMS;设置权重请使用 /knowledge/v1。; Praxis 扩展
ranking_options.hybrid_search.embedding_weightnumber必填; 语义检索相对权重;零表示禁用语义检索。; 最小: 0; 默认: 0.7
ranking_options.hybrid_search.text_weightnumber必填; 关键词检索相对权重;零表示禁用关键词检索。; 最小: 0; 默认: 0.3
praxisobject可选; 不生效: 兼容响应会删除 praxis,包括搜索解释。
praxis.explainboolean可选; 请求生成解释;兼容响应不返回这些解释。

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/search" \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"query\":\"When will I receive my refund?\",\"max_num_results\":5}"

响应

HTTP 200

字段类型说明
object"vector_store.search_results.page"必有; 对象标记;vector_store.search_results.page 表示搜索结果页。
search_querystring[]必有; 实际用于检索的查询,与输入一一对应;rewrite_query 为 true 时为改写后的查询,否则原样返回。
dataobject[]必有; 每个文件返回一条;content 包含该文件命中的分段。
data[].file_idstring必有; 资源 ID。; 最短字符数: 1
data[].filenamestring必有; 命中文件的源文件名。
data[].scorenumber必有; 该文件命中分段的最高分数。; 最小: 0; 最大: 1
data[].attributesobject / null必有; 用于筛选的当前文件属性;未设置时为 null。
data[].contentobject[]必有; 按分段分数降序排列的命中分段。
data[].content[].type"text"必有; text 表示提取出的文本分段。
data[].content[].textstring必有; 命中分段的提取文本,可能与相邻分段重叠。
has_moreboolean必有; 过滤后的文件数超过 max_num_results 时为 true;next_page 仍为 null。; 支持:
next_pagenull必有; 不生效: 恒为 null,没有下一页搜索结果。

错误码与错误对象

添加文件

POST /openai/v1/vector_stores/{vector_store_id}/files

异步处理。重复加入同一文件返回已有记录,不应用新的属性或分段策略。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1

请求体

字段类型说明
file_idstring必填; 上传文件返回的已有源 File ID;文件必须对调用方可见。; 最短字符数: 1
attributesobject / null可选; 新附件的搜索筛选属性;省略或 null 表示不设置。重复加入已有文件不改变属性。
chunking_strategyobject / object可选; auto 等同于每段 800 token、重叠 400 token。; 默认: {"type":"auto"}
chunking_strategy (1).type"auto"必填; auto 使用默认静态分段:800 个估算 token,重叠 400 个。
chunking_strategy (2).type"static"必填; static 表示使用显式分段大小与重叠设置。
chunking_strategy (2).staticobject必填; 以估算 token 数表示的分段大小与重叠限制。
chunking_strategy (2).static.max_chunk_size_tokensinteger必填; 每段的估算 token 数。; 最小: 100; 最大: 4096
chunking_strategy (2).static.chunk_overlap_tokensinteger必填; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/files" \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"file_id\":\"${FILE_ID}\"}"

响应

HTTP 200

字段类型说明
idstring必有; 与源文件相同的 ID。; 最短字符数: 1
object"vector_store.file"必有; 对象标记;vector_store.file 表示知识库中的附件。
vector_store_idstring必有; 资源 ID。; 最短字符数: 1
status"in_progress" / "completed" / "cancelled" / "failed"必有; in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。
last_errorobject / null必有; 入库失败详情;未失败、成功完成或重新入库时为 null。
last_error (1).code"server_error" / "unsupported_file" / "invalid_file"必有; unsupported_file 表示不支持的文件类型;invalid_file 表示加密、空文件或超过解析 token 上限;server_error 表示其它入库失败或超过截止时间。
last_error (1).messagestring必有; 与 code 对应的入库失败说明。
usage_bytesinteger必有; 完成后计入源文件字节数;处理中、失败或已取消时为零。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。
chunking_strategyobject / object必有; 此附件已保存的分段策略;auto 输入返回为具体 static 设置。
chunking_strategy (1).type"static"必有; static 表示使用显式分段大小与重叠设置。
chunking_strategy (1).staticobject必有; 以估算 token 数表示的分段大小与重叠限制。
chunking_strategy (1).static.max_chunk_size_tokensinteger必有; 每段的估算 token 数。; 最小: 100; 最大: 4096
chunking_strategy (1).static.chunk_overlap_tokensinteger必有; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
chunking_strategy (2).type"other"必有
attributesobject / null必有; 用于搜索筛选的文件属性;null 表示未设置。

错误码与错误对象

列出文件

GET /openai/v1/vector_stores/{vector_store_id}/files

列出附件及入库状态,默认最新附件在前。使用 last_id 作为 after 继续查询;?filter=failed 筛选可重新入库的失败文件。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
afterquery: string上一页的 ID 游标。 最短字符数: 1
beforequery: string返回此 ID 之前的条目。 最短字符数: 1
limitquery: integer每页条数。 最小: 1; 最大: 100; 默认: 20
orderquery: "asc" / "desc"知识库和文件默认按创建时间降序;分段默认按序号升序。 默认: "desc"
filterquery: "in_progress" / "completed" / "failed" / "cancelled"in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。省略时包含全部状态。

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/files" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
object"list"必有; 对象标记;list 表示游标分页集合。
dataobject[]必有; 按请求顺序返回的当前页条目。
data[].idstring必有; 与源文件相同的 ID。; 最短字符数: 1
data[].object"vector_store.file"必有; 对象标记;vector_store.file 表示知识库中的附件。
data[].vector_store_idstring必有; 资源 ID。; 最短字符数: 1
data[].status"in_progress" / "completed" / "cancelled" / "failed"必有; in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。
data[].last_errorobject / null必有; 入库失败详情;未失败、成功完成或重新入库时为 null。
data[].last_error (1).code"server_error" / "unsupported_file" / "invalid_file"必有; unsupported_file 表示不支持的文件类型;invalid_file 表示加密、空文件或超过解析 token 上限;server_error 表示其它入库失败或超过截止时间。
data[].last_error (1).messagestring必有; 与 code 对应的入库失败说明。
data[].usage_bytesinteger必有; 完成后计入源文件字节数;处理中、失败或已取消时为零。; 最小: 0
data[].created_atinteger必有; Unix 时间戳,单位秒。
data[].chunking_strategyobject / object必有; 此附件已保存的分段策略;auto 输入返回为具体 static 设置。
data[].chunking_strategy (1).type"static"必有; static 表示使用显式分段大小与重叠设置。
data[].chunking_strategy (1).staticobject必有; 以估算 token 数表示的分段大小与重叠限制。
data[].chunking_strategy (1).static.max_chunk_size_tokensinteger必有; 每段的估算 token 数。; 最小: 100; 最大: 4096
data[].chunking_strategy (1).static.chunk_overlap_tokensinteger必有; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
data[].chunking_strategy (2).type"other"必有
data[].attributesobject / null必有; 用于搜索筛选的文件属性;null 表示未设置。
first_idstring / null必有; 本页首项的 ID;空页为 null。
last_idstring / null必有; 本页末项的 ID,可作为 after 继续查询;空页为 null。
has_moreboolean必有; 当前游标范围内,本页之后是否还有条目。

错误码与错误对象

读取文件

GET /openai/v1/vector_stores/{vector_store_id}/files/{file_id}

使用添加附件或附件列表返回的 id 读取文件。可轮询此操作,直到 status 离开 in_progress 后确认入库结果。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
file_idpath: string必填;添加附件或附件列表返回的源 File ID。 最短字符数: 1

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/files/${FILE_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
idstring必有; 与源文件相同的 ID。; 最短字符数: 1
object"vector_store.file"必有; 对象标记;vector_store.file 表示知识库中的附件。
vector_store_idstring必有; 资源 ID。; 最短字符数: 1
status"in_progress" / "completed" / "cancelled" / "failed"必有; in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。
last_errorobject / null必有; 入库失败详情;未失败、成功完成或重新入库时为 null。
last_error (1).code"server_error" / "unsupported_file" / "invalid_file"必有; unsupported_file 表示不支持的文件类型;invalid_file 表示加密、空文件或超过解析 token 上限;server_error 表示其它入库失败或超过截止时间。
last_error (1).messagestring必有; 与 code 对应的入库失败说明。
usage_bytesinteger必有; 完成后计入源文件字节数;处理中、失败或已取消时为零。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。
chunking_strategyobject / object必有; 此附件已保存的分段策略;auto 输入返回为具体 static 设置。
chunking_strategy (1).type"static"必有; static 表示使用显式分段大小与重叠设置。
chunking_strategy (1).staticobject必有; 以估算 token 数表示的分段大小与重叠限制。
chunking_strategy (1).static.max_chunk_size_tokensinteger必有; 每段的估算 token 数。; 最小: 100; 最大: 4096
chunking_strategy (1).static.chunk_overlap_tokensinteger必有; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
chunking_strategy (2).type"other"必有
attributesobject / null必有; 用于搜索筛选的文件属性;null 表示未设置。

错误码与错误对象

更新文件属性

POST /openai/v1/vector_stores/{vector_store_id}/files/{file_id}

替换已有附件的搜索筛选属性,不重新入库。使用附件 id。请求体示例:{"attributes":{"category":"refund"}};null 清空属性。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
file_idpath: string必填;添加附件或附件列表返回的源 File ID。 最短字符数: 1

请求体

字段类型说明
attributesobject / null可选; 替换全部搜索筛选属性;null 清空属性。

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/files/${FILE_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"attributes\":{\"category\":\"refund\"}}"

响应

HTTP 200

字段类型说明
idstring必有; 与源文件相同的 ID。; 最短字符数: 1
object"vector_store.file"必有; 对象标记;vector_store.file 表示知识库中的附件。
vector_store_idstring必有; 资源 ID。; 最短字符数: 1
status"in_progress" / "completed" / "cancelled" / "failed"必有; in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。
last_errorobject / null必有; 入库失败详情;未失败、成功完成或重新入库时为 null。
last_error (1).code"server_error" / "unsupported_file" / "invalid_file"必有; unsupported_file 表示不支持的文件类型;invalid_file 表示加密、空文件或超过解析 token 上限;server_error 表示其它入库失败或超过截止时间。
last_error (1).messagestring必有; 与 code 对应的入库失败说明。
usage_bytesinteger必有; 完成后计入源文件字节数;处理中、失败或已取消时为零。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。
chunking_strategyobject / object必有; 此附件已保存的分段策略;auto 输入返回为具体 static 设置。
chunking_strategy (1).type"static"必有; static 表示使用显式分段大小与重叠设置。
chunking_strategy (1).staticobject必有; 以估算 token 数表示的分段大小与重叠限制。
chunking_strategy (1).static.max_chunk_size_tokensinteger必有; 每段的估算 token 数。; 最小: 100; 最大: 4096
chunking_strategy (1).static.chunk_overlap_tokensinteger必有; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
chunking_strategy (2).type"other"必有
attributesobject / null必有; 用于搜索筛选的文件属性;null 表示未设置。

错误码与错误对象

移除文件

DELETE /openai/v1/vector_stores/{vector_store_id}/files/{file_id}

返回后立即不再搜索到该文件;不会删除源文件。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
file_idpath: string必填;添加附件或附件列表返回的源 File ID。 最短字符数: 1

请求示例

curl -X DELETE "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/files/${FILE_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store.file.deleted"必有; 对象标记;vector_store.file.deleted 表示此操作回执。
deletedtrue必有; 确认已从此知识库移出;源 File 未删除。

错误码与错误对象

读取抽取内容

GET /openai/v1/vector_stores/{vector_store_id}/files/{file_id}/content

抽取文本按分段返回,可能重叠。图片内容可能是生成的描述,并非逐字 OCR。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
file_idpath: string必填;添加附件或附件列表返回的源 File ID。 最短字符数: 1

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/files/${FILE_ID}/content" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
object"vector_store.file_content.page"必有; 对象标记;vector_store.file_content.page 表示提取的文件内容。
dataobject[]必有; 按分段序号排列的全部现存文本分段;相邻分段可能重叠。
data[].type"text"必有; text 表示提取出的文本分段。
data[].textstring必有; 此分段的提取文本;可能与相邻分段重叠。
has_morefalse必有; 恒为 false;此响应返回全部现存分段。
next_pagenull必有; 恒为 null;提取内容不分页。

错误码与错误对象

创建文件批次

POST /openai/v1/vector_stores/{vector_store_id}/file_batches

批量添加已有 File 并异步入库。file_ids 与 files 必须且只能提供一个;files 支持逐文件设置。已有附件直接复用。使用返回的批次 id 查询进度。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1

请求体

file_ids 与 files 必须且只能提供一个。已有文件直接复用,不修改属性或分段策略。

字段类型说明
(1).file_idsstring[]必填; 使用共同属性和分段设置的已有 File ID 列表。file_ids 与 files 二选一。; 最少条数: 1; 最多条数: 500
(1).attributesobject / null可选; 用于每个新附件的搜索筛选属性;省略或 null 表示不设置。
(1).chunking_strategyobject / object可选; auto 等同于每段 800 token、重叠 400 token。; 默认: {"type":"auto"}
(1).chunking_strategy (1).type"auto"必填; auto 使用默认静态分段:800 个估算 token,重叠 400 个。
(1).chunking_strategy (2).type"static"必填; static 表示使用显式分段大小与重叠设置。
(1).chunking_strategy (2).staticobject必填; 以估算 token 数表示的分段大小与重叠限制。
(1).chunking_strategy (2).static.max_chunk_size_tokensinteger必填; 每段的估算 token 数。; 最小: 100; 最大: 4096
(1).chunking_strategy (2).static.chunk_overlap_tokensinteger必填; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
(2).filesobject[]必填; 分别指定属性和分段设置的附件列表;忽略顶层 attributes 与 chunking_strategy。; 最少条数: 1; 最多条数: 500
(2).files[].file_idstring必填; 上传文件返回的已有源 File ID;文件必须对调用方可见。; 最短字符数: 1
(2).files[].attributesobject可选; 用于搜索筛选的文件属性。最多 16 个键,键最多 64 字符,字符串值最多 512 字符。; 最多键数: 16; 键最多 64 字符; 值: string / number / boolean
(2).files[].chunking_strategyobject / object可选; auto 等同于每段 800 token、重叠 400 token。; 默认: {"type":"auto"}
(2).files[].chunking_strategy (1).type"auto"必填; auto 使用默认静态分段:800 个估算 token,重叠 400 个。
(2).files[].chunking_strategy (2).type"static"必填; static 表示使用显式分段大小与重叠设置。
(2).files[].chunking_strategy (2).staticobject必填; 以估算 token 数表示的分段大小与重叠限制。
(2).files[].chunking_strategy (2).static.max_chunk_size_tokensinteger必填; 每段的估算 token 数。; 最小: 100; 最大: 4096
(2).files[].chunking_strategy (2).static.chunk_overlap_tokensinteger必填; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
(2).attributesJSON可选; 不生效: 使用 files 时不生效。
(2).chunking_strategyJSON可选; 不生效: 使用 files 时不生效。

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/file_batches" \
  -H "Authorization: Bearer $PRAXIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"file_ids\":[\"${FILE_ID}\"]}"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store.files_batch"必有; 对象标记;vector_store.files_batch 表示批量附件。
vector_store_idstring必有; 资源 ID。; 最短字符数: 1
status"in_progress" / "completed" / "cancelled" / "failed"必有; cancelled 表示批次已取消;否则 in_progress 表示仍有成员入库中,failed 表示入库结束且有失败成员,completed 表示无入库中或失败成员。取消终态批次不会改变它。
file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。

错误码与错误对象

读取文件批次

GET /openai/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}

读取此知识库中创建的批次,包括当前状态和文件计数。使用创建批次返回的 id 监测入库结果。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
batch_idpath: string必填;此知识库创建批次时返回的文件批次 ID。 最短字符数: 1

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/file_batches/${BATCH_ID}" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store.files_batch"必有; 对象标记;vector_store.files_batch 表示批量附件。
vector_store_idstring必有; 资源 ID。; 最短字符数: 1
status"in_progress" / "completed" / "cancelled" / "failed"必有; cancelled 表示批次已取消;否则 in_progress 表示仍有成员入库中,failed 表示入库结束且有失败成员,completed 表示无入库中或失败成员。取消终态批次不会改变它。
file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。

错误码与错误对象

取消文件批次

POST /openai/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel

只取消处理中的批次和文件。已完成、失败或已取消的批次原样返回(200,幂等),计数不变。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
batch_idpath: string必填;此知识库创建批次时返回的文件批次 ID。 最短字符数: 1

请求示例

curl -X POST "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/file_batches/${BATCH_ID}/cancel" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
idstring必有; 资源 ID。; 最短字符数: 1
object"vector_store.files_batch"必有; 对象标记;vector_store.files_batch 表示批量附件。
vector_store_idstring必有; 资源 ID。; 最短字符数: 1
status"in_progress" / "completed" / "cancelled" / "failed"必有; cancelled 表示批次已取消;否则 in_progress 表示仍有成员入库中,failed 表示入库结束且有失败成员,completed 表示无入库中或失败成员。取消终态批次不会改变它。
file_countsobject必有; 仍属于该库或批次的附件数量,按入库状态分组。
file_counts.in_progressinteger必有; 等待或正在入库的文件数。; 最小: 0
file_counts.completedinteger必有; 已完成入库的文件数。; 最小: 0
file_counts.failedinteger必有; 入库失败的文件数。; 最小: 0
file_counts.cancelledinteger必有; 因批次取消而停止入库的文件数。; 最小: 0
file_counts.totalinteger必有; 全部入库状态的附件总数。; 最小: 0
created_atinteger必有; Unix 时间戳,单位秒。

错误码与错误对象

列出批次文件

GET /openai/v1/vector_stores/{vector_store_id}/file_batches/{batch_id}/files

列出指定批次仍在库中的附件,默认最新附件在前。使用批次创建返回的 id;?filter=failed 查看失败文件,last_id 可作为下一页 after。

参数

名称位置与类型说明
vector_store_idpath: string必填;创建或列表返回的知识库 ID;不要使用显示名称。 最短字符数: 1
batch_idpath: string必填;此知识库创建批次时返回的文件批次 ID。 最短字符数: 1
afterquery: string上一页的 ID 游标。 最短字符数: 1
beforequery: string返回此 ID 之前的条目。 最短字符数: 1
limitquery: integer每页条数。 最小: 1; 最大: 100; 默认: 20
orderquery: "asc" / "desc"知识库和文件默认按创建时间降序;分段默认按序号升序。 默认: "desc"
filterquery: "in_progress" / "completed" / "failed" / "cancelled"in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。省略时包含全部状态。

请求示例

curl -X GET "https://api.deepraxis.ai/openai/v1/vector_stores/${VECTOR_STORE_ID}/file_batches/${BATCH_ID}/files" \
  -H "Authorization: Bearer $PRAXIS_API_KEY"

响应

HTTP 200

字段类型说明
object"list"必有; 对象标记;list 表示游标分页集合。
dataobject[]必有; 按请求顺序返回的当前页条目。
data[].idstring必有; 与源文件相同的 ID。; 最短字符数: 1
data[].object"vector_store.file"必有; 对象标记;vector_store.file 表示知识库中的附件。
data[].vector_store_idstring必有; 资源 ID。; 最短字符数: 1
data[].status"in_progress" / "completed" / "cancelled" / "failed"必有; in_progress 表示等待或正在入库;completed 表示可检索;failed 表示入库失败;cancelled 表示批次取消已停止入库。
data[].last_errorobject / null必有; 入库失败详情;未失败、成功完成或重新入库时为 null。
data[].last_error (1).code"server_error" / "unsupported_file" / "invalid_file"必有; unsupported_file 表示不支持的文件类型;invalid_file 表示加密、空文件或超过解析 token 上限;server_error 表示其它入库失败或超过截止时间。
data[].last_error (1).messagestring必有; 与 code 对应的入库失败说明。
data[].usage_bytesinteger必有; 完成后计入源文件字节数;处理中、失败或已取消时为零。; 最小: 0
data[].created_atinteger必有; Unix 时间戳,单位秒。
data[].chunking_strategyobject / object必有; 此附件已保存的分段策略;auto 输入返回为具体 static 设置。
data[].chunking_strategy (1).type"static"必有; static 表示使用显式分段大小与重叠设置。
data[].chunking_strategy (1).staticobject必有; 以估算 token 数表示的分段大小与重叠限制。
data[].chunking_strategy (1).static.max_chunk_size_tokensinteger必有; 每段的估算 token 数。; 最小: 100; 最大: 4096
data[].chunking_strategy (1).static.chunk_overlap_tokensinteger必有; 不得超过 max_chunk_size_tokens 的一半。; 最小: 0; 最大: 2048
data[].chunking_strategy (2).type"other"必有
data[].attributesobject / null必有; 用于搜索筛选的文件属性;null 表示未设置。
first_idstring / null必有; 本页首项的 ID;空页为 null。
last_idstring / null必有; 本页末项的 ID,可作为 after 继续查询;空页为 null。
has_moreboolean必有; 当前游标范围内,本页之后是否还有条目。

错误码与错误对象

导出

本页内容