/api/v1/content/reindex 接口用于对已经存储在 OpenViking 中的现有内容,重新构建语义产物和/或向量索引。这是一个运维维护接口,适用于 embedding 模型更换、向量库重刷、修复索引不一致等场景。
完成 API 鉴权说明 页面的 API Key 获取后,可调用本接口重建索引。
URI | /api/v1/content/reindex | 统一资源标识符 |
|---|---|---|
请求方法 | POST | 客户端请求类型 |
请求头 | Content-Type: application/json | 请求消息类型 |
Authorization: Bearer | Bearer Token 鉴权(与 X-Api-Key 二选一) |
参数 | 类型 | 必选 | 默认值 | 备注 |
|---|---|---|---|---|
uri | string | 是 | -- | 要重新索引的 Viking URI |
mode | string | 否 |
| 重建模式 |
wait | bool | 否 |
| 是否等待任务完成 |
支持的 URI 范围:
URI | 说明 |
|---|---|
| 全局 |
| 用户命名空间 |
| 特定用户 |
| Agent 命名空间 |
| 特定 Agent |
| 资源 |
| 特定资源路径 |
| 用户记忆 |
| Agent 记忆 |
| Agent 技能 |
| 特定技能 |
reindex不支持viking://session/...。
模式说明:
vectors_only:基于当前仍可恢复的源数据重建向量库记录,不会重写 .abstract.md 和 .overview.md。semantic_and_vectors:先重新生成语义产物,再基于新的语义结果重建向量。对于 resource 和 skill,会刷新目录/文件语义产物,包括 .abstract.md 和 .overview.md。对于 memory,会重建当前已持久化 memory 子树的语义和向量,但不会回放历史记忆抽取顺序。语义刷新和向量重建由 reindex executor 串行编排。语义刷新阶段不会再额外向后台 embedding queue 投递自己的向量化任务;向量由 reindex 阶段统一重建,因此 wait=true 表示等待 reindex 操作本身完成。字段 | 参数说明 |
|---|---|
status | 请求状态,成功为 |
result | 成功时返回的数据对象 |
result.status | 同步完成时为 |
result.uri | 解析路径变量后的请求 URI |
result.mode | 实际执行的 reindex 模式 |
result.object_type | 推断出的目标类型,例如 |
result.scanned_records | 被检查的记录或语义源数量 |
result.rebuilt_records | 成功重建的向量记录数量 |
result.unsupported_records | 因没有可用向量来源而跳过的记录数量 |
result.failed_records | 重建失败的记录数量 |
result.duration_ms | 同步执行耗时,单位毫秒 |
result.warnings | 可恢复的单条记录级 warning |
result.task_id | 后台任务 ID,仅 |
time | 请求耗时(秒) |
error | 失败时返回的错误对象 |
error.code | 错误码字符串,常见值见下表 |
error.message | 可读的错误描述 |
常见错误码:
error.code | 说明 |
|---|---|
UNAUTHENTICATED | 缺少 API Key 或 API Key 无效 |
PERMISSION_DENIED | 权限不足(需要 root/admin 权限) |
INVALID_ARGUMENT | 无效参数 |
INVALID_URI | 无效的 Viking URI 格式 |
CONFLICT | 同一 URI 和 owner 已有正在运行的 reindex 任务 |
curl -X POST https://xxx/api/v1/content/reindex \ -H "X-Api-Key: your-api-key" \ -H "X-OpenViking-Account: default" \ -H "Content-Type: application/json" \ -d '{ "uri": "viking://resources", "mode": "vectors_only", "wait": true }'
执行成功返回:
HTTP/1.1 200 OK Content-Type: application/json { "status": "ok", "result": { "uri": "viking://resources", "mode": "vectors_only", "status": "completed", "object_type": "resource", "scanned_records": 120, "rebuilt_records": 118, "unsupported_records": 2, "failed_records": 0, "duration_ms": 1284, "warnings": [] }, "time": 0.1 }
curl -X POST https://xxx/api/v1/content/reindex \ -H "X-Api-Key: your-api-key" \ -H "X-OpenViking-Account: default" \ -H "Content-Type: application/json" \ -d '{ "uri": "viking://agent/default/skills", "mode": "semantic_and_vectors", "wait": false }'
执行成功返回:
HTTP/1.1 200 OK Content-Type: application/json { "status": "ok", "result": { "uri": "viking://agent/default/skills", "mode": "semantic_and_vectors", "object_type": "skill", "status": "accepted", "task_id": "task_xxx" }, "time": 0.1 }
可使用返回的 task_id 查询后台任务:
curl -X GET https://xxx/api/v1/tasks/task_xxx \ -H "X-Api-Key: your-api-key" \ -H "X-OpenViking-Account: default"
Reindex 后台任务的 task_type 为 admin_reindex,resource_id 等于请求中的 uri,也可以这样列出:
GET /api/v1/tasks?task_type=admin_reindex&resource_id=viking://resources
任务记录保存在内存中,可能过期,也会在服务重启后丢失。
viking:// 发起 reindex 时,会向下分发到支持的顶层命名空间,并显式排除 session。viking://user 或 viking://agent/default,会继续传播到其支持的子内容类型。vectors_only。semantic_and_vectors。