Skip to content

fix(search): infer support query domain from SUPPORT_TAGS#59

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
hobostay:fix/infer-query-domain-support
Jun 28, 2026
Merged

fix(search): infer support query domain from SUPPORT_TAGS#59
jeff-r2026 merged 1 commit into
Tencent:mainfrom
hobostay:fix/infer-query-domain-support

Conversation

@hobostay

Copy link
Copy Markdown
Contributor

Summary

inferQueryDomain (in src/utils/search-index.ts) only scores TECHNICAL_TAGS and OPS_TAGS — it never looks at SUPPORT_TAGS. As a result any query made of support tokens (faq, onboarding, guide, user, …) is classified as neutral.

This is both a ranking bug and an internal inconsistency:

  • Under DOMAIN_WEIGHT.neutral, support entries get weight 0.3 while neutral entries get 0.85. So a genuine support question ranks a matching support document below an unrelated neutral document — the opposite of the intended ranking.
  • It is asymmetric with inferDomain (lines ~167–183), which scores all three tag sets, and contradicts inferQueryDomain's own doc comment: "Uses the same tag sets used for document domain inference so the two sides of the matching are symmetric."

Fix

Score SUPPORT_TAGS as well, mirroring inferDomain:

function inferQueryDomain(queryTokens: string[]): KnowledgeDomain {
  let techScore = 0, opsScore = 0, supportScore = 0;
  for (const t of queryTokens) {
    if (TECHNICAL_TAGS.has(t)) techScore++;
    if (OPS_TAGS.has(t)) opsScore++;
    if (SUPPORT_TAGS.has(t)) supportScore++;
  }
  const maxScore = Math.max(techScore, opsScore, supportScore);
  if (maxScore === 0) return 'neutral';
  if (techScore === maxScore) return 'technical';   // tie-break: technical > ops > support
  if (opsScore === maxScore) return 'ops';
  return 'support';
}

Test

Added a regression test (search-domain-weighting.test.ts) that builds a real index with two identical-score entries — one domain: support, one domain: neutral — and queries with support tokens. It asserts the support entry outranks the neutral one.

  • Before fix: fails — support entry scores 2.4, neutral 6.8 (support penalized ×0.3 under the mis-inferred neutral query domain).
  • After fix: passes — query domain is support, support entry outranks neutral.

npm test → 1440 passed; tsc --noEmit → clean.

inferQueryDomain only scored TECHNICAL_TAGS and OPS_TAGS, so any query
made of support tokens (faq/onboarding/guide/user/…) was classified as
'neutral'. Under DOMAIN_WEIGHT.neutral, support entries get a 0.3 weight
while neutral entries get 0.85 — so a genuine support question ranked a
matching support doc *below* an unrelated neutral doc, the opposite of
the intended ranking.

This is also asymmetric with inferDomain (which scores all three tag
sets) and contradicts inferQueryDomain's own doc comment ("uses the same
tag sets … so the two sides of the matching are symmetric").

Score SUPPORT_TAGS too, with the same technical > ops > support
tie-breaking as inferDomain. Added a regression test that builds a real
index and asserts a support-domain query ranks the support entry above
an equal-raw-score neutral entry (fails before the fix: 2.4 vs 6.8).

Co-Authored-By: Claude <noreply@anthropic.com>
@jeff-r2026 jeff-r2026 merged commit 8330b5b into Tencent:main Jun 28, 2026
6 checks passed
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