Skip to content

完善 RAG、Skill 与 Memory 契约测试并修复边界问题 - #25

Open
KeyCOrigin wants to merge 3 commits into
OpenDCAI:mainfrom
KeyCOrigin:develop
Open

KeyCOrigin wants to merge 3 commits into
OpenDCAI:mainfrom
KeyCOrigin:develop

Conversation

@KeyCOrigin

Copy link
Copy Markdown

变更概述

本次变更只关注 RAG、Skill 和 Memory 的工程契约,不评测 LLM 的回答质量、事实性或语义召回效果。

测试使用确定性的 Fake Embedding、内存向量库和 Mock Model,验证系统是否按照预定流程完成解析、索引、检索、上下文组装、Skill 加载和 Memory 存取。

RAG 变更

新增确定性契约测试

  • 文档解析:

    • 中文、Emoji 和特殊文件名;
    • 正文、来源和解析块保留;
    • 空内容和不支持格式边界。
  • Chunk:

    • 短文本;
    • 恰好达到 chunk_size;
    • 超长文本;
    • 无标点文本;
    • overlap 边界;
    • 非法 chunk_size 和 chunk_overlap。
  • 索引:

    • 文档解析、Chunk、Embedding、向量库写入的完整连接;
    • source、chunk ordinal 和 origin metadata 保留;
    • Embedding 数量和维度契约。
  • Retriever:

    • 确定性向量排序;
    • top_k;
    • metadata 过滤;
    • 空结果;
    • 空查询和非法 top_k。
  • 向量库:

    • 插入;
    • 更新覆盖;
    • 删除;
    • metadata 和 workspace 隔离。
  • Prompt 与证据:

    • 工具结果进入下一轮模型上下文;
    • evidence 中的 chunk_id 与检索结果一致;
    • 检索内容不会在上下文传递过程中丢失。

RAG 代码修复

  • KBService.search(top_k=0) 不再错误回退到默认 top_k。
  • SimpleRetriever 和 HybridRetriever 拒绝 top_k<=0。
  • SimpleRetriever 和 HybridRetriever 拒绝空查询。
  • _split_text() 对非法 chunk_size 和 chunk_overlap 明确报错。

Skill 变更

边界测试

  • 空查询;
  • 非正数和布尔型 top_k;
  • manifest Embedding 数量不匹配;
  • Embedding 维度错误;
  • 空向量;
  • NaN、Inf 和布尔向量坐标;
  • Skill 名称、描述、正文和关键字类型错误;
  • 重复 Skill 且 overwrite=false。

Skill 代码修复

  • Skill 建立向量索引前增加 Embedding 数量、维度和数值合法性校验。
  • Embedding 校验失败时不会先清空现有 Skill 索引。
  • Skill 查询参数和 upsert 参数统一进行显式校验。
  • 非法输入返回明确的 CapabilityError。

Memory 变更

边界测试

  • top_k 为 0、负数和布尔值;
  • per_scope 使用负数、非法 scope 和非法类型;
  • kinds 使用不支持的 Memory 类型;
  • global、profile、session scope 字段混用;
  • metadata 不是对象;
  • metadata 无法 JSON 序列化;
  • Embedding 维度错误;
  • NaN、Inf 和布尔坐标;
    聚焦测试:

RAG 相关测试:35 passed
Skill/Memory 相关测试:47 passed

风险与范围

  • 没有调用真实 LLM 来判断回答质量。
  • 没有把 Embedding 语义相似度作为通过标准。
  • 真实外部服务只适合作为单独冒烟测试,本 PR 的核心验证使用 Fake/Mock,保证结果确定、可重复。

@haolpku haolpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two correctness blockers.

  1. RuntimeFactory caches independent runtimes by (profile, surface-set). A graph-only runtime can be cached by datamind_graph_query, while datamind_use_folder writes through a separate kb+graph runtime. The graph-only NetworkX store then remains stale indefinitely. Please share services per profile or invalidate/reload sibling cache entries after writes, with a cross-route regression.

  2. The lock-file stale recovery has no ownership token. If operation A exceeds one hour, B may unlink A's lock and acquire a new one; when A finishes, A unlinks B's lock, allowing C to enter concurrently. Use an OS advisory lock or an owner token verified on release, and test stale-lock takeover ownership.

This PR also changes MCP runtime caching, tool registration, cross-process locking, resource lifecycle, rollback, and Chroma errors beyond the RAG/Skill/Memory test scope described in the body. Please document or split those changes before merging.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants