Skip to content

Bug: RRF weights in hybridQuery prioritize lex expansions over original vector in common path #591

@tada-zako

Description

@tada-zako

Summary

hybridQuery currently assigns 2x RRF weight by list position (i < 2) rather than by query intent/type.
In the common path (when expansion includes lex), this gives 2x to:

  • original FTS
  • first lex FTS

instead of the intended:

  • original FTS
  • original vec

Description

Current Behavior

In src/store.ts (hybridQuery, Step 4):

const weights = rankedLists.map((_, i) => i < 2 ? 2.0 : 1.0);

Push order before Step 4 is typically:

  1. initialFts (original FTS)
  2. lex FTS results (from expansion, Step 3a)
  3. original vec results (Step 3b)
  4. expanded vec / hyde

If any lex expansion exists, it occupies index 1, receiving the 2.0x weight, while the original vector query (the primary semantic signal) is pushed to index 2+ and receives only 1.0x.

Expected Behavior

2x weight should apply to lists whose queryType === "original" (i.e., original FTS + original vec), and expansion-derived lists should stay at 1x.

Proposed Fix

Use rankedListMeta (already built in parallel with rankedLists) to assign semantic weights:

const weights = rankedListMeta.map(meta =>
  meta.queryType === "original" ? 2.0 : 1.0
);

Questions

  1. Does this alignment with the original design intent make sense to the maintainers?
  2. I have a local fix ready. Should I target the main branch or a specific development branch for the PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions