Skip to content

Add rank option to elasticsearch_dsl.search.Search #1692

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

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

miguelgrinberg
Copy link
Collaborator

This PR adds the rank option, to enable the use of the RRF algorithm to combine multiple sets of search results. Not sure if we want this published, given that rank is in technical preview at this point, but since I have implemented it for my own use I'm sharing the changes here.

@pquentin
Copy link
Member

pquentin commented Jan 2, 2024

I like this and will want it when knn is merged. Maybe we should keep it undocumented since it's in technical preview?

@miguelgrinberg miguelgrinberg force-pushed the rank-option branch 2 times, most recently from 776bfd0 to 212e830 Compare January 3, 2024 15:22
@miguelgrinberg
Copy link
Collaborator Author

@pquentin This is now ready. I left the docstring docs, including a note about RRF being in preview.

Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM. I was able to use this in the "Hybrid Search using RRF" notebook:

import json
from elasticsearch_dsl import Search

s = Search(using=client, index="book_index")
s = s[:5]
s = s.query("match", summary="python programming")
s = s.knn(
    field="title_vector",
    # generate embedding for query so it can be compared to `title_vector`
    query_vector=model.encode("python programming").tolist(),
    k=5,
    num_candidates=10,
)
s = s.rank(rrf={})

r = s.execute()
pretty_response(r)

@pquentin pquentin added the backport 8.x Backport to 8.x label Jan 5, 2024
@pquentin pquentin merged commit 5422cf0 into elastic:main Jan 5, 2024
github-actions bot pushed a commit that referenced this pull request Jan 5, 2024
pquentin pushed a commit that referenced this pull request Jan 5, 2024
…`` (#1692) (#1694)

(cherry picked from commit 5422cf0)

Co-authored-by: Miguel Grinberg <[email protected]>
@miguelgrinberg miguelgrinberg deleted the rank-option branch January 5, 2024 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.x Backport to 8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants