Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions crates/ov_cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ fn compact_request_body(body: &mut Value) {
}

fn add_resource_tag_fields(body: &mut Value, tags: &[String], tag_mode: &str) {
if tags.is_empty() {
if tags.is_empty() && tag_mode != "clear" {
return;
}
let obj = body
.as_object_mut()
.expect("add_resource request body must be an object");
obj.insert("tags".to_string(), serde_json::json!(tags));
if !tags.is_empty() {
obj.insert("tags".to_string(), serde_json::json!(tags));
}
obj.insert("tag_mode".to_string(), serde_json::json!(tag_mode));
}

Expand Down Expand Up @@ -482,13 +484,7 @@ impl HttpClient {
if !recursive {
body["recursive"] = serde_json::json!(false);
}
if !tags.is_empty() {
let obj = body
.as_object_mut()
.expect("reindex request body must be an object");
obj.insert("tags".to_string(), serde_json::json!(tags));
obj.insert("tag_mode".to_string(), serde_json::json!(tag_mode));
}
add_resource_tag_fields(&mut body, &tags, tag_mode);
self.post("/api/v1/content/reindex", &body).await
}

Expand Down Expand Up @@ -2127,6 +2123,17 @@ mod tests {
assert!(!obj.contains_key("tag_mode"));
}

#[test]
fn add_resource_tag_fields_sends_clear_without_tags() {
let mut body = json!({"path": "https://example.com/demo.md"});

super::add_resource_tag_fields(&mut body, &[], "clear");

let obj = body.as_object().unwrap();
assert!(!obj.contains_key("tags"));
assert_eq!(body["tag_mode"], json!("clear"));
}

#[test]
fn timeout_config_calculation() {
let config = TimeoutConfig::new(60, 2.0);
Expand Down
59 changes: 53 additions & 6 deletions crates/ov_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ enum Commands {
/// Comma-separated k=v retrieval tags to apply after import
#[arg(long = "tags", value_delimiter = ',', value_name = "k=v", help_heading = "Common options")]
tags: Vec<String>,
/// Tag update mode when --tags is provided
/// Tag update mode; clear does not require --tags
#[arg(
long = "tag-mode",
default_value = "replace",
value_parser = ["replace", "append"],
value_parser = ["replace", "append", "clear"],
help_heading = "Common options"
)]
tag_mode: String,
Expand Down Expand Up @@ -746,8 +746,8 @@ enum Commands {
/// Comma-separated k=v retrieval tags to write with the content
#[arg(long = "tags", value_delimiter = ',')]
tags: Vec<String>,
/// Tag update mode when --tags is provided
#[arg(long = "tag-mode", default_value = "replace", value_parser = ["replace", "append"])]
/// Tag update mode; clear does not require --tags
#[arg(long = "tag-mode", default_value = "replace", value_parser = ["replace", "append", "clear"])]
tag_mode: String,
},
/// [Data] Update explicit retrieval tags metadata for a file or directory
Expand Down Expand Up @@ -1260,11 +1260,11 @@ enum Commands {
/// Comma-separated k=v retrieval tags for rebuilt vector records
#[arg(long = "tags", value_delimiter = ',', value_name = "k=v", help_heading = "Common options")]
tags: Vec<String>,
/// Tag update mode when --tags is provided
/// Tag update mode; clear does not require --tags
#[arg(
long = "tag-mode",
default_value = "replace",
value_parser = ["replace", "append"],
value_parser = ["replace", "append", "clear"],
help_heading = "Common options"
)]
tag_mode: String,
Expand Down Expand Up @@ -4746,6 +4746,53 @@ mod tests {
}
}

#[test]
fn cli_parses_clear_tag_mode_without_tags() {
let add = Cli::try_parse_from([
"ov",
"add-resource",
"./README.md",
"--tag-mode",
"clear",
])
.expect("add-resource clear mode should parse");
match add.command {
Commands::AddResource { tags, tag_mode, .. } => {
assert!(tags.is_empty());
assert_eq!(tag_mode, "clear");
}
_ => panic!("expected add-resource command"),
}

let write = Cli::try_parse_from([
"ov",
"write",
"viking://resources/demo.md",
"--content",
"content",
"--tag-mode",
"clear",
])
.expect("write clear mode should parse");
assert!(matches!(
write.command,
Commands::Write { tag_mode, tags, .. } if tag_mode == "clear" && tags.is_empty()
));

let reindex = Cli::try_parse_from([
"ov",
"reindex",
"viking://resources/demo",
"--tag-mode",
"clear",
])
.expect("reindex clear mode should parse");
assert!(matches!(
reindex.command,
Commands::Reindex { tag_mode, tags, .. } if tag_mode == "clear" && tags.is_empty()
));
}

#[test]
fn cli_parses_skills_command_group() {
let list = Cli::try_parse_from(["ov", "skills", "list", "--limit", "25"])
Expand Down
2 changes: 2 additions & 0 deletions docs/en/api/02-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ This endpoint is the core entry point for resource management. It supports vario
| watch_interval | float | No | 0 | Scheduled update interval (minutes). >0 creates a new Watch for a re-readable source, subject to target ownership rules; uploaded `temp_file_id` snapshots cannot be watched. <=0 creates no Watch: native imports with explicit `to` pause a single accessible task (409 if ambiguous), while Connector imports leave Watches untouched. Explicit `to` wins, otherwise the Watch binds to the imported `root_uri`. |
| is_active | bool | No | True | Initial Watch scheduling state. `false` requires `watch_interval > 0` and either `to` or `parent`. `parent` is supported for native Feishu URL and Git imports; Connector imports still require an exact `to`. The initial import still runs once and the Watch remains paused afterward |
| processing_mode | string | No | `semantic_and_vectors` | Post-ingest processing mode. `semantic_and_vectors` is the normal flow: generate semantic artifacts (`.abstract.md`, `.overview.md`) and vectors. `vectors_only` skips semantic understanding/VLM summarization and only vectorizes current resource files |
| tags | string[] | No | None | Explicit `k=v` retrieval tags written with generated vector records. An empty list with `replace` does not change existing tags |
| tag_mode | string | No | `replace` | Tag write mode: `replace`, `append`, or `clear`; `clear` removes existing tags without requiring `tags` and ignores supplied tag values |
| telemetry | TelemetryRequest | No | False | Whether to return telemetry data |

**Additional Notes**:
Expand Down
16 changes: 10 additions & 6 deletions docs/en/api/12-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Write a file and automatically refresh related semantics and vectors.
| wait | bool | No | `false` | Wait for background semantic/vector refresh |
| timeout | float | No | `null` | Timeout in seconds when `wait=true` |
| tags | string[] | No | Unset | Explicit retrieval tags for the written file, for example `["team=search", "env=prod"]` |
| tag_mode | string | No | `replace` | Tag update mode when `tags` is supplied: `replace` overwrites tags; `append` merges tags by key |
| tag_mode | string | No | `replace` | Tag update mode: `replace` overwrites tags, `append` merges by key, and `clear` removes existing tags without requiring `tags` |

**Notes**

Expand All @@ -233,7 +233,7 @@ Write a file and automatically refresh related semantics and vectors.
- File content is updated before the API returns. `wait` only controls whether the call waits for semantic/vector refresh to finish.
- The public API no longer accepts `regenerate_semantics` or `revectorize`; write automatically schedules related semantic and vector processing.
- Parent L0/L1 refreshes for resource writes are best-effort: a parent lock conflict skips that directory refresh while preserving the file write and its own summary/vector work. Skipping L0/L1 persistence also skips directory vector updates; a later refresh is not guaranteed. Locks on the written file itself still raise conflicts. Contention detected before enqueueing returns `semantic_status: "skipped"`; skips during background execution are logged, and `wait=true` does not guarantee updated parent summaries.
- When `tags` is supplied, tags are included in the file's first vector upsert rather than updated after processing. Omitting `tags` preserves existing tags; explicit `tags: []` with `tag_mode: "replace"` clears them.
- When non-empty `tags` are supplied, tags are included in the file's first vector upsert rather than updated after processing. Omitting `tags`, or using `tags: []` with `tag_mode: "replace"`, preserves existing tags. Use `tag_mode: "clear"` to remove all existing tags; `clear` ignores any supplied tag values.


**Python SDK**
Expand Down Expand Up @@ -601,8 +601,8 @@ This API operates on existing `viking://...` content. It does not import new fil
| wait | bool | No | `true` | Whether to wait for completion |
| dry_run | bool | No | `false` | Only valid with `mode="prune_orphans"`; report orphan vector records without deleting them |
| recursive | bool | No | `true` | Whether to process descendants recursively; `false` applies only to `semantic_and_vectors` on a `resource`, `memory`, or `skill` directory |
| tags | list[str] | No | `null` | Write tags to every successfully rebuilt vector record. Omit to preserve existing tags; an empty list with `replace` clears them |
| tag_mode | str | No | `replace` | Tag write mode: `replace` or `append` |
| tags | list[str] | No | `null` | Write tags to every successfully rebuilt vector record. Omitting tags, or passing an empty list with `replace`, preserves existing tags |
| tag_mode | str | No | `replace` | Tag write mode: `replace`, `append`, or `clear`; `clear` removes existing tags without requiring `tags` |

The HTTP request body rejects unknown fields. `uri` may use OpenViking path variables accepted by other content APIs; it is resolved before validation.

Expand Down Expand Up @@ -635,7 +635,7 @@ For a `resource` or `memory` directory, `recursive=false` regenerates only the t

For `prune_orphans`, source existence is checked against the filesystem. If an entire directory is missing, vector records for files and semantic sidecars below that directory, such as `.abstract.md` and `.overview.md`, are pruned together. `dry_run` is rejected for other modes.

When `tags` is provided, tags are included in the same upsert as each vector record produced by reindex; reindex does not call `set_tags` afterwards. Directory and namespace reindex operations apply tags to successfully rebuilt directory L0/L1 and leaf L2 records. `replace` overwrites existing tags, while `append` merges by key. When `tags` is omitted, `tag_mode` is ignored and existing tags remain unchanged. `prune_orphans` produces no vectors and ignores both fields.
When non-empty `tags` are provided, tags are included in the same upsert as each vector record produced by reindex; reindex does not call `set_tags` afterwards. Directory and namespace reindex operations apply tags to successfully rebuilt directory L0/L1 and leaf L2 records. `replace` overwrites existing tags, while `append` merges by key. `replace` with an empty tag list is a no-op. `clear` removes existing tags and does not require `tags`; if values are supplied with `clear`, they are ignored. `prune_orphans` produces no vectors and ignores both fields.

Subtree reindex is not transactional. Records skipped because no semantic source is available, or records whose embedding fails, do not receive the new tags.

Expand Down Expand Up @@ -738,7 +738,11 @@ openviking reindex viking://resources --mode vectors_only \
--tags team=search,env=prod --tag-mode replace
```

The CLI sends tag fields only when non-empty `--tags` is provided. Use HTTP or an SDK to clear tags with `tags: []`.
Use `--tag-mode clear` without `--tags` to clear existing tags:

```bash
openviking reindex viking://resources --mode vectors_only --tag-mode clear
```

```bash
openviking reindex viking://user/default/skills --mode semantic_and_vectors --wait false
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/api/02-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ URL/文件 Parser TreeBuilder AGFS Summarizer/Vector
| is_active | bool | 否 | True | Watch 初始调度状态。设为 `false` 时要求 `watch_interval > 0`,并在 `to`、`parent` 中二选一。`parent` 支持原生飞书 URL 和 Git 导入;Connector 仍要求精确的 `to`。首次导入仍执行一次,随后保持暂停 |
| processing_mode | string | 否 | `semantic_and_vectors` | 入库后的处理模式。`semantic_and_vectors` 是默认流程:生成语义产物(`.abstract.md`、`.overview.md`)并生成向量。`vectors_only` 跳过语义理解/VLM 总结,只对当前资源文件生成向量 |
| tags | string[] | 否 | None | 导入时写入向量检索记录的显式检索标签,格式必须是 `k=v`,例如 `["team=search", "env=test"]`。搜索接口可用同名 `tags` 参数过滤召回 |
| tag_mode | string | 否 | `"replace"` | `tags` 的写入模式,可选 `replace` 或 `append`。导入新资源时会随本次生成的每条向量记录写入;不会在完成后额外调用 `set_tags`,响应也不返回 `tags_result` |
| tag_mode | string | 否 | `"replace"` | 标签写入模式:`replace` 覆盖、`append` 按 key 合并、`clear` 清空。`clear` 不要求传 `tags`;`replace` 配合空数组不会修改已有标签。导入时标签会随本次生成的每条向量记录写入;不会在完成后额外调用 `set_tags`,响应也不返回 `tags_result` |
| telemetry | TelemetryRequest | 否 | False | 是否返回遥测数据 |

**补充说明**:
Expand Down
16 changes: 10 additions & 6 deletions docs/zh/api/12-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ openviking read viking://resources/docs/api.md
| wait | bool | 否 | `false` | 是否等待后台语义/向量刷新完成 |
| timeout | float | 否 | `null` | 当 `wait=true` 时的超时时间(秒) |
| tags | string[] | 否 | 未设置 | 写入文件的显式检索标签,例如 `["team=search", "env=prod"]` |
| tag_mode | string | 否 | `replace` | 提供 `tags` 时的更新方式:`replace` 覆盖标签,`append` 按 key 合并标签 |
| tag_mode | string | 否 | `replace` | 标签更新方式:`replace` 覆盖、`append` 按 key 合并、`clear` 清空已有标签且不要求传 `tags` |

**说明**

Expand All @@ -233,7 +233,7 @@ openviking read viking://resources/docs/api.md
- 文件内容会在 API 返回前完成更新;`wait` 只控制是否等待语义/向量刷新完成。
- 公共 API 已不再接受 `regenerate_semantics` 或 `revectorize`;写入后会自动调度相关语义与向量处理。
- 资源写入附带的父目录 L0/L1 刷新采用尽力更新:父目录锁冲突时跳过本次目录刷新,保留原文写入及文件自身的摘要、向量处理。跳过 L0/L1 写回时也跳过目录向量更新,不保证自动补刷;原文文件本身的锁冲突仍报错。提交任务前发现冲突时返回 `semantic_status: "skipped"`;后台运行期间的跳过记录在日志中,`wait=true` 也不保证父目录摘要更新。
- 提供 `tags` 时,标签会在该文件首次向量 upsert 时写入,而非在处理完成后再单独更新。省略 `tags` 不改变已有标签;显式 `tags: []` 配合 `tag_mode: "replace"` 可清空标签。
- 提供非空 `tags` 时,标签会在该文件首次向量 upsert 时写入,而非在处理完成后再单独更新。省略 `tags`,或显式传 `tags: []` 配合 `tag_mode: "replace"`,都不会修改已有标签。使用 `tag_mode: "clear"` 可清空全部已有标签,且 `clear` 会忽略同时传入的标签值。


**Python SDK**
Expand Down Expand Up @@ -601,8 +601,8 @@ ov set-tags viking://resources/project/ \
| wait | bool | 否 | `true` | 是否等待任务完成 |
| dry_run | bool | 否 | `false` | 仅适用于 `mode="prune_orphans"`;只报告 orphan 向量记录,不实际删除 |
| recursive | bool | 否 | `true` | 是否递归处理下级内容;`false` 仅对 `resource`、`memory` 或 `skill` 目录的 `semantic_and_vectors` 生效 |
| tags | list[str] | 否 | `null` | 写入本次成功重建的全部向量记录。省略时保留已有 tags;空数组配合 `replace` 可清空 |
| tag_mode | str | 否 | `replace` | `tags` 的写入模式:`replace` 或 `append` |
| tags | list[str] | 否 | `null` | 写入本次成功重建的全部向量记录。省略或空数组配合 `replace` 时保留已有 tags |
| tag_mode | str | 否 | `replace` | 标签写入模式:`replace`、`append` 或 `clear`;`clear` 不要求传 `tags` 并清空已有标签 |

HTTP 请求体不接受未知字段。`uri` 可以使用其他 content API 支持的 OpenViking 路径变量,服务端会先解析再校验。

Expand Down Expand Up @@ -635,7 +635,7 @@ session 子树会被跳过。

对于 `prune_orphans`,源文件是否存在以当前文件系统为准。如果整个目录已经不存在,该目录下的正文文件向量和语义 sidecar 向量(例如 `.abstract.md`、`.overview.md`)会一起清理。`dry_run` 用在其他模式时会被拒绝。

传入 `tags` 时,标签会随 reindex 生成的向量记录在同一次 upsert 中写入,不会在完成后额外调用 `set_tags`。目录或 namespace reindex 会把标签应用到本次成功重建的目录 L0/L1 和叶子 L2 记录。`replace` 覆盖已有标签,`append` 按 key 合并;省略 `tags` 时不校验 `tag_mode` 且不修改已有标签。`prune_orphans` 不生成向量,因此会忽略 `tags` 和 `tag_mode`。
传入非空 `tags` 时,标签会随 reindex 生成的向量记录在同一次 upsert 中写入,不会在完成后额外调用 `set_tags`。目录或 namespace reindex 会把标签应用到本次成功重建的目录 L0/L1 和叶子 L2 记录。`replace` 覆盖已有标签,`append` 按 key 合并;`replace` 配合空数组时不修改已有标签。`clear` 不要求传 `tags`,会清空已有标签;即使同时传入标签值也会忽略。`prune_orphans` 不生成向量,因此会忽略 `tags` 和 `tag_mode`。

子树 reindex 不是事务性操作。如果部分记录因缺少语义来源或 embedding 失败而未重建,只有成功写入的记录会更新标签。

Expand Down Expand Up @@ -738,7 +738,11 @@ openviking reindex viking://resources --mode vectors_only \
--tags team=search,env=prod --tag-mode replace
```

CLI 仅在 `--tags` 非空时发送标签字段;如需用 `tags: []` 清空标签,请使用 HTTP 或 SDK。
使用 `--tag-mode clear` 且无需传 `--tags` 即可清空已有标签:

```bash
openviking reindex viking://resources --mode vectors_only --tag-mode clear
```

```bash
openviking reindex viking://user/default/skills --mode semantic_and_vectors --wait false
Expand Down
14 changes: 9 additions & 5 deletions openviking/connector/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,15 @@ async def submit(
account_id=ctx.account_id,
)
extra_params = None
if tags is not None:
extra_params = {
"tags": normalize_search_tags(tags),
"tag_mode": tag_mode,
}
if tag_mode == "clear":
extra_params = {"tag_mode": tag_mode}
elif tags is not None:
normalized_tags = normalize_search_tags(tags)
if normalized_tags:
extra_params = {
"tags": normalized_tags,
"tag_mode": tag_mode,
}

task_tracker = get_task_tracker()
task = await task_tracker.create(
Expand Down
3 changes: 2 additions & 1 deletion openviking/server/mcp_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,8 @@ async def add_resource(
``add_type`` is set. Leaving both empty derives the directory and the name
from the source and handles collisions like ``parent``.
tags: Optional explicit k=v retrieval tags to apply after ingestion.
tag_mode: Tag update mode, "replace" or "append". Defaults to "replace".
tag_mode: Tag update mode: "replace", "append", or "clear". Clear removes
existing tags without requiring ``tags``. Defaults to "replace".
args: Parser-specific options, e.g. {"auth_config": {"token": "..."}}
for native HTTPS Git imports and watches, {"feishu_access_token": "..."}
for Feishu imports, {"site": true} for whole-site ingestion, or
Expand Down
Loading
Loading