Skip to content

refactor: remove resource relation edges - #3956

Draft
sponge225 wants to merge 1 commit into
volcengine:mainfrom
sponge225:cleanup/relation-edge-removal-20260812
Draft

refactor: remove resource relation edges#3956
sponge225 wants to merge 1 commit into
volcengine:mainfrom
sponge225:cleanup/relation-edge-removal-20260812

Conversation

@sponge225

@sponge225 sponge225 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

本 PR 移除 OpenViking 中已废弃的 resource relation 边能力。

这套 relation 能力原本提供 /api/v1/relationsVikingFS.link/unlink/relations、CLI/SDK relation 命令,以及 session Phase2 中基于 usage_records 写入 .relations.json 的逻辑。但在正常聊天、检索、读取、commit 主链路中,relation 边并不参与检索召回、rerank、上下文组装或业务决策,检索返回中的 relations 也只是空占位。

因此本 PR 的目标不是“兼容旧 relation”,而是让当前系统表现为 resource relation 边从未作为正式能力存在过

  • 不再提供 relation API
  • 不再写入 .relations.json
  • 不再读取 relation 数据
  • 不再在检索结果、SDK 类型、CLI 命令或文档中暴露 relation 概念
  • 对旧库中可能残留的 .relations.json,通过 OVPack 迁移边界丢弃,而不是在主代码中保留兼容逻辑

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • 服务端能力清理

    • 删除 /api/v1/relations 路由注册与实现
    • 删除 RelationService
    • 删除 core service 中对 relation service 的聚合暴露
    • 删除 relation 相关 OpenAPI / Web Studio generated client 类型
  • VikingFS relation 实现清理

    • 删除 VikingFS.relations()
    • 删除 VikingFS.link()
    • 删除 VikingFS.unlink()
    • 删除 get_relation_table()get_relations()get_relations_with_content()
    • 删除 RelationEntry 数据结构
    • 删除 .relations.json 的读写实现
    • 更新 viking_fs 模块说明,只保留 abstract、overview、find、search 等语义检索能力
  • Session 后台流程清理

    • 删除 session Phase2 中根据 usage_records 写 relation 的逻辑
    • 保留 usage_recordsactive_count、telemetry、memory 等现有主链路行为的作用
    • 更新 Phase2 注释,从“extract memories, write relations, enqueue”改为“extract memories and enqueue semantic work”
  • 检索链路清理

    • 删除 HierarchicalRetriever 中的 MAX_RELATIONS
    • 删除检索结果构造里的 relations=[] 空占位
    • 删除 CLI retrieve 类型、SDK 类型、Web Studio retrieval 展示中对 relations 字段的依赖
    • 保持召回、rerank、score、search_tags 等现有检索语义不变
  • CLI / SDK / Integration 清理

    • 删除 Rust CLI relations 子命令、handler、help、错误提示和测试
    • 删除 Python SDK relation API
    • 删除 TypeScript SDK relation API 和类型
    • 删除 Go SDK relation API 和测试
    • 清理 LangChain integration、bot、examples、OpenClaw plugin 中的 relation 暴露或说明
  • OVPack 迁移边界处理

    • 保留主代码“relation 不存在”的语义,不在 WebDAV、restore vector 分类等主路径继续特殊兼容 .relations.json
    • 在 OVPack policy 中将 .relations.json 作为废弃产物排除
    • export_ovpack / backup_ovpack 导出时不写入 .relations.json
    • import_ovpack / restore_ovpack 读取已有包时,如果包内含 .relations.json,校验完整性后跳过写入
    • 这样旧库可以通过“OVPack 导出 -> 当前版本导入/恢复”的方式得到不包含 relation 产物的新数据树
  • 文档清理

    • 删除中英文 relation API 文档
    • 更新 filesystem、session、retrieval、content、WebDAV、storage、transaction、operation telemetry 等文档中 relation 相关描述
    • 更新 OVPack 文档,明确 .relations.json 是废弃产物,迁移时会被丢弃
    • 保留 memory graph / working memory link relation 等非 resource relation 概念,不混同清理
  • 测试更新

    • 删除 relation API、CLI、scenario 测试
    • 更新 retrieval、content write、telemetry、integration、WebDAV、SDK 测试预期
    • 新增 OVPack 对 .relations.json 的 export/import/restore 清理测试
    • 修正 content write 测试中与当前 memory metadata trailer、权限错误类型、overview/linkify 输出、异步刷新等待语义相关的断言

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

本地验证如下。

OVPack 迁移边界、restore 分类和 WebDAV 关键路径:

OPENVIKING_CONFIG_FILE=/tmp/openviking-test-stdout.conf \
OPENVIKING_CLI_CONFIG_FILE=/tmp/openviking-test-stdout.conf \
PYTEST_ADDOPTS='' \
uv run pytest tests/misc/test_ovpack_import_policy.py \
  tests/agfs/test_viking_fs_git.py::test_classify_restore_path \
  tests/server/test_api_webdav.py::test_webdav_propfind_hides_reserved_files_but_keeps_user_dotdirs \
  -q --tb=short --disable-warnings --no-header --no-cov

结果:

23 passed, 5 warnings

Content write 关键测试:

OPENVIKING_CONFIG_FILE=/tmp/openviking-test-stdout.conf \
OPENVIKING_CLI_CONFIG_FILE=/tmp/openviking-test-stdout.conf \
PYTEST_ADDOPTS='' \
uv run pytest tests/server/test_content_write_service.py \
  -q --tb=short --disable-warnings --no-header --no-cov

结果:

108 passed, 5 warnings

基础检查:

git diff --check

结果:通过。

python3 -m compileall \
  openviking/storage/ovpack/validation.py \
  openviking/storage/ovpack/operations.py \
  tests/misc/test_ovpack_import_policy.py \
  openviking/storage/internal_names.py \
  openviking/storage/viking_fs/_access.py

结果:通过。

补充扫描:

rg -n "relations\\.json" openviking tests docs/en/api/14-ovpack.md docs/zh/api/14-ovpack.md docs/en/guides/09-ovpack.md docs/zh/guides/09-ovpack.md

扫描结果仅剩:

  • OVPack policy
  • OVPack migration 文档
  • OVPack 测试构造与断言

这符合当前设计:主代码不再支持 relation,OVPack 迁移边界负责丢弃旧 .relations.json

Migration Example

如果旧 storage 中曾经产生过 .relations.json,可以通过 OVPack 完成一次“重新打包再导入”的迁移。迁移后,新 storage 中不会包含 .relations.json

1. 从旧 storage 导出 OVPack

export OPENVIKING_CONFIG_FILE=/path/to/old-ov.conf

ov export viking://resources /tmp/resources.ovpack --include-vectors
ov export viking://user /tmp/user.ovpack --include-vectors

2. 切到新版本代码,并准备新的空 storage

export OPENVIKING_CONFIG_FILE=/path/to/new-ov.conf

3. 导入到新 storage

ov import /tmp/resources.ovpack viking://
ov import /tmp/user.ovpack viking://

迁移结果

正常文件                      会迁移
.abstract.md / .overview.md   会迁移
向量快照                      使用 --include-vectors 时会迁移
.relations.json               会被 OVPack 过滤,不会进入新 storage

不迁移向量快照的方式

如果不希望复用旧向量快照,可以导出时不带 --include-vectors

ov export viking://resources /tmp/resources.ovpack
ov export viking://user /tmp/user.ovpack

这种方式会只迁移文件树,导入后由新版本重新构建向量索引。

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

这是一次 intentional breaking cleanup。

删除后不再支持以下能力:

  • /api/v1/relations
  • VikingFS.link / unlink / relations
  • CLI relations 命令
  • SDK relation API
  • 检索结果中的 relations 字段
  • session Phase2 自动写 .relations.json

普通聊天、检索、读取、session commit 不受影响,因为 relation 边原本不参与正常主链路。

对于历史数据:

  • 原地升级不会主动扫描和删除旧 .relations.json
  • 新版本不会再生成新的 .relations.json
  • 如果旧 storage 中存在 .relations.json,并希望得到完全清理后的数据树,可以使用 OVPack:
    1. 导出现有数据
    2. 用当前版本导入或恢复
    3. 新数据树中不会包含 .relations.json

uv.lock 的本地改动未提交。

@sponge225
sponge225 marked this pull request as draft August 12, 2026 08:30
@sponge225
sponge225 force-pushed the cleanup/relation-edge-removal-20260812 branch from 009c44a to d4dcda1 Compare August 12, 2026 09:35
@sponge225
sponge225 force-pushed the cleanup/relation-edge-removal-20260812 branch from d4dcda1 to fe50730 Compare August 12, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant