Skip to content

fix(search): isolate IDF statistics by domain - #902

Merged
jeff-r2026 merged 4 commits into
Tencent:mainfrom
ydflow:fix/search-idf-domain-isolation
Oct 1, 2026
Merged

jeff-r2026 merged 4 commits into
Tencent:mainfrom
ydflow:fix/search-idf-domain-isolation

Conversation

@ydflow

@ydflow ydflow commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • Compute search document frequency and corpus size within each knowledge domain, so unrelated ops/support entries cannot shift a technical result's score.
  • Use the matching domain's baseline when filtering and normalizing each recall result.
  • Keep all per-index candidates until the domain-normalized merged ranking is computed, so a relevant hit cannot be discarded by the raw top-five cutoff.
  • Bump the search index schema and rebuild indexes without complete per-domain statistics.

Verification

  • npm run typecheck — passed
  • npm run lint — passed on the original PR head
  • npm run build — passed
  • Focused search and recall unit tests — 118 passed on the follow-up head
  • npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/search-idf-domain-isolation.test.ts — 2 passed on the follow-up head, using the built CLI
  • The new regression fixture has five ops hits with raw score 6.8 (below their 7.6 relevance threshold) ahead of a technical hit with raw score 6.0 (above its 4.0 threshold). Before the fix, recall --check api returned NOT_RELEVANT score=6.8 threshold=7.6; after the fix, the real CLI returns RELEVANT with the technical title.
  • The existing real CLI E2E rebuilt a v6 fixture to the current index schema and returned RELEVANT; the generated index kept timeout DF at 1 for technical entries and 12 for ops entries.

The full unit suite was attempted locally on the original PR head but did not complete cleanly on Windows: unrelated path-separator and symlink-permission assertions, shell-selection mismatches, and subprocess timeouts occurred. The focused tests and real CLI E2E for this change pass.

@jeff-r2026 jeff-r2026 self-assigned this Sep 29, 2026
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] Normalize domain-specific scores before applying the per-index top-five cutoff — src/utils/search-index.ts:930. Scores now use different corpus sizes but search() still sorts and truncates raw scores before recall() normalizes them. For example, one technical api hit can score 6 and be relevant, while five title-only ops hits in a large ops corpus score above 6 but remain below their domain relevance threshold; those five discard the technical hit, causing recall --check api to incorrectly return IRRELEVANT.

Testing

  • The PR description includes a representative real-CLI E2E record, so its documented testing satisfies the repository requirement.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] Normalize before applying the per-index result limit — src/recall.ts:595. search(query, index) still truncates to five results using raw scores; the normalized sort at src/recall.ts:646 cannot recover discarded candidates. Five high-raw-score but domain-irrelevant ops hits can therefore hide a lower-raw-score, domain-relevant technical hit, causing recall --check to return NOT_RELEVANT. The earlier blocking finding remains unresolved.

Testing

  • The PR description includes a representative real-CLI E2E record, so its documented testing is sufficient.

@github-actions

Copy link
Copy Markdown

Review

  • No findings.
  • The earlier [P1 blocking] cutoff issue is resolved: recall now retains all per-index candidates before domain-normalized sorting at src/recall.ts:596 and src/recall.ts:649.

Testing

  • The PR description includes focused tests and a representative real-CLI E2E record, satisfying the repository’s testing requirements.

@jeff-r2026
jeff-r2026 merged commit 7e6ebae into Tencent:main Oct 1, 2026
13 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
* fix(search): isolate IDF statistics by domain

* test(search): make ranking fixtures cross-platform

* fix(recall): normalize all search candidates before limiting

---------

Co-authored-by: ydflow <[email protected]>
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