Skip to content
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

add get_top_k_cosine_similarity method to get max top k score and index #5059

Merged
merged 4 commits into from
May 22, 2023

Conversation

hwaking
Copy link
Contributor

@hwaking hwaking commented May 21, 2023

Row-wise cosine similarity between two equal-width matrices and return the max top_k score and index, the score all greater than threshold_score. @vowelparrot @dev2049 @hwchase17

it's useful when we want to get the top k score and index after similarity compute. just like the following example:

input example

x = [[1, 2, 3, 4], [1, 2, 2, 2]]
y = [[1, 2, 3, 5], [1, 2, 9, 5], [2, 2, 3, 5]]
index_score_list = get_top_k_cosine_similarity(x, y, top_k=2, threshold_score=0.94)
print('index_score_list:', index_score_list)

output result

index_score_list: [[(0, 0.9939990885479664), (2, 0.9860132971832692)], [(2, 0.9415130835240085)]]

hwaking and others added 3 commits May 21, 2023 22:32
Row-wise cosine similarity between two equal-width matrices and return the max top_k score and index, the score all greater than threshold_score
@dev2049 dev2049 added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label May 22, 2023
@dev2049 dev2049 merged commit e57ebf3 into langchain-ai:master May 22, 2023
12 checks passed
@danielchalef danielchalef mentioned this pull request Jun 5, 2023
This was referenced Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm PR looks good. Use to confirm that a PR is ready for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants