Skip to content

Fix: hybrid lexical + semantic retrieval ordering - #348

Open
shivansh31414 wants to merge 1 commit into
activeloopai:mainfrom
shivansh31414:hybrid-retrieval-fix
Open

Fix: hybrid lexical + semantic retrieval ordering#348
shivansh31414 wants to merge 1 commit into
activeloopai:mainfrom
shivansh31414:hybrid-retrieval-fix

Conversation

@shivansh31414

@shivansh31414 shivansh31414 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

Fix stale documentation that described the hybrid retrieval strategy as using BM25 as a fallback. BM25 was evaluated and removed (PR-NOTES F4c) because its unbounded score scale (~1–3) overwhelms cosine similarity values (0–1) in a shared ORDER BY, causing semantic hits to be pushed out of the top-K entirely. Using it correctly would require rank-based fusion (RRF) or score normalisation, which adds complexity without clear benefit for the "find any session mentioning X" use case.

The actual hybrid strategy is a UNION ALL of:

  • Lexical LIKE/ILIKE substring rows, emitting a sentinel score of 1.0 (capped by HIVEMIND_HYBRID_LEXICAL_LIMIT, default 20)
  • Semantic cosine-similarity rows, emitting their real 0–1 score

Results are ordered by score descending, so exact keyword matches always lead the ranking while semantic concept matches fill in below. When embeddings are off, retrieval falls back to lexical LIKE/ILIKE only.

Files changed:

  • README.md — updated the feature bullet to describe the sentinel-score fusion and document why BM25 was dropped
  • src/embeddings/disable.ts — corrected the JSDoc comment from "BM25 / ILIKE matching" to "lexical LIKE/ILIKE matching" with the same rationale

Version Bump

To trigger a release, bump "version" in package.json before merging.

Change type Version bump Example
Bug fix patch (1.2.0 → 1.2.1) "version": "1.2.1"
New feature minor (1.2.0 → 1.3.0) "version": "1.3.0"
Breaking change major (1.2.0 → 2.0.0) "version": "2.0.0"

If you don't bump the version, no release will be created.

This is a documentation-only change — no release needed. No version bump required.

Test plan

  • Tests pass locally (npm test)
  • Relevant new tests added
  • Version bumped in package.json, or no release needed for this change ✓ (docs only)

Summary by CodeRabbit

  • Documentation
    • Updated search documentation to describe hybrid retrieval, combining keyword and semantic matches.
    • Clarified that keyword matches appear first, with semantic results filling in below when embeddings are enabled.
    • Documented lexical-only search behavior when embeddings are disabled.
    • Added context on why BM25 is not used for ranking.

Copilot AI lite review requested due to automatic review settings September 8, 2026 17:10
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: cc8aeb05-e8c3-4029-9a4f-c85544832740

📥 Commits

Reviewing files that changed from the base of the PR and between 5b455d3 and 3991d0d.

📒 Files selected for processing (2)
  • README.md
  • src/embeddings/disable.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The changes update search documentation to describe hybrid lexical and cosine retrieval, lexical-only fallback when embeddings are disabled, and the rejection of BM25 because its score scale does not combine directly with cosine scores.

Changes

Hybrid search documentation

Layer / File(s) Summary
Search behavior documentation
README.md, src/embeddings/disable.ts
The documentation describes LIKE/ILIKE matches, cosine-similarity results, score ordering, the lexical result limit, lexical-only fallback, and why BM25 is not used for shared score ordering.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 3991d

This change corrects hybrid-search documentation to describe the existing lexical and semantic retrieval behavior. It introduces no runtime behavior change or remaining merge-readiness risk.

Suggested reviewers: efenocchi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main documentation change: correcting hybrid lexical and semantic retrieval ordering.
Description check ✅ Passed The description includes the required Summary, Version Bump, and Test plan sections. It explains the documentation-only scope, states that no release is needed, and identifies the test impact.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated docs introduce a broken JSDoc sentence and an internal inconsistency in the BM25 rationale wording that should be corrected before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates repository documentation to accurately describe the current hybrid lexical + semantic retrieval strategy (sentinel-score UNION ALL of lexical LIKE/ILIKE rows plus semantic cosine-similarity rows) and clarifies why BM25 was evaluated but removed.

Changes:

  • Updated README feature bullet to describe sentinel-score fusion behavior and rationale for dropping BM25.
  • Corrected src/embeddings/disable.ts JSDoc to refer to lexical LIKE/ILIKE fallback (not “BM25 / ILIKE”).
File summaries
File Description
README.md Updates the hybrid retrieval description and BM25 rationale in the feature list.
src/embeddings/disable.ts Updates embeddings-disable JSDoc to reflect lexical fallback behavior and BM25 rationale.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread README.md
- 📥 **Captures** every session's prompts, tool calls, and responses as structured traces in Deeplake
- 🧠 **Codifies** patterns into reusable `SKILL.md` files, available to every agent on your team
- 🔍 **Searches** traces and skills with hybrid lexical + semantic retrieval (BM25 fallback when embeddings off)
- 🔍 **Searches** traces and skills with hybrid lexical + semantic retrieval: a `UNION ALL` of `LIKE`/`ILIKE` substring rows (sentinel score 1.0, capped by `HIVEMIND_HYBRID_LEXICAL_LIMIT`) and cosine-similarity rows (real 0–1 score), ordered by score — so exact keyword matches always lead while semantic hits fill in below. When embeddings are off, falls back to lexical `LIKE`/`ILIKE` only. (BM25 was evaluated but dropped: its unbounded score scale (~1–3) overwhelmed cosine in a shared `ORDER BY`, requiring rank-based fusion (RRF) or score normalisation to use safely.)
Comment thread src/embeddings/disable.ts
Comment on lines +26 to 29
* lexical `LIKE`/`ILIKE` matching on text columns (BM25 was evaluated but
* dropped — its score scale (~1..3) is incompatible with cosine in a single
* ORDER BY without RRF or normalisation; see grep-core.ts PR-NOTES F4c).
* readable.
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