Skip to content

[bug] search-index 收缩保护导致已删除文档残留在检索结果中 #83

Description

@jeff-r2026

现象

buildIndex 有一个“防止把健康索引覆盖成过小索引”的守卫:当新索引条目数 < 旧索引的 50%(且旧索引 > 5 条)时,直接跳过写入

// src/utils/search-index.ts:554-559
const existingIndex = await loadIndex(targetPath);
if (existingIndex && existingIndex.entries.length > 5 && entries.length < existingIndex.entries.length * 0.5) {
  log.warn(`Index rebuild skipped: new index (${entries.length}) much smaller than existing (${existingIndex.entries.length})`);
  return elapsed;
}

问题

这个守卫无法区分“源目录损坏/读取失败”与“合法的大量删除”。在以下合法场景会导致已删除的文档继续被 recall 命中,直到用户手动删除 search-index.json

  • 团队一次性删除/归档了大量 learnings 或 docs;
  • scope 切换后源目录指向了一个更小的知识库;
  • teamai pull 重建索引时源已显著缩小。

建议

  • 增加 --force-reindex(或在 pull 显式重建时绕过该守卫);
  • 或将守卫判据从“仅条目数”改为“源目录文件列表/数量校验”,仅在源目录读取异常(0 文件但目录存在且非空)时才跳过;
  • 缩小索引时可写入一份 stale 黑名单以便审计。

严重程度:中高(导致检索返回已删除内容)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions