Skip to content

Migrate Hybrid Search Labs Notebook from RRF to Retrievers API (Elasticsearch 9.x) #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mridula-s109
Copy link
Contributor

Overview

This PR updates notebooks/search/02-hybrid-search.ipynb to use the new Retrievers API for hybrid search, replacing the deprecated rank={"rrf": {}} syntax with the modern retriever={"rrf": {...}} structure. The notebook is now fully compatible with Elasticsearch 9.x.

Key Changes

  • Replaced all usage of the legacy rank field with the new retriever field in search requests.
  • Updated hybrid search examples to use the rrf retriever, combining both BM25 and kNN retrievers in the new syntax.
  • Modified the pretty_response function and result parsing to use _score and positional rank, reflecting the new API response structure.
  • Cleaned up notebook outputs and execution counts for a clean diff.
  • Added explanatory markdown on the new retriever API and how ranking works in Elasticsearch 9.x.

Testing & Validation

  • Verified that hybrid search queries using the retriever API work as expected on Elasticsearch 9.1.0-SNAPSHOT.
  • Confirmed that kNN and standard retrievers are combined using RRF and results are displayed correctly.

Test Output


Screenshot 2025-05-27 at 16 28 29

@mridula-s109 mridula-s109 added the bug Something isn't working label May 27, 2025
Copy link

gitnotebooks bot commented May 27, 2025

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/elastic/elasticsearch-labs/pull/459

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mridula-s109 mridula-s109 requested a review from Copilot May 27, 2025 16:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the hybrid search notebook to Elasticsearch 9.x by replacing the deprecated rank syntax with the new Retrievers API.

  • Replaced legacy "rank" field with the "retriever" field in search requests.
  • Updated the pretty_response function to enumerate results and display both ranking position and _score.
  • Refined the search call structure to combine BM25 and kNN retrievers using the new API.
Comments suppressed due to low confidence (1)

notebooks/search/02-hybrid-search.ipynb:208

  • [nitpick] The variable name 'id' shadows Python's built-in function. Consider renaming it to 'document_id' to improve clarity.
            id = hit["_id"]

Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mridula-s109 mridula-s109 merged commit e8f446e into main May 29, 2025
2 of 7 checks passed
@mridula-s109 mridula-s109 deleted the SEARCH-991-migrate-hybrid-search-labs-notebook-from-rrf-to-retrievers branch May 29, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants