-
Notifications
You must be signed in to change notification settings - Fork 138
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
Fix sort sparse vectors #442
Conversation
✅ Deploy Preview for poetic-froyo-8baba7 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -401,7 +401,7 @@ def search( | |||
scores = calculate_context_scores(query_vector, vectors[: len(self.payload)], distance) | |||
elif isinstance(query_vector, SparseVector): | |||
# sparse vector query must be sorted by indices for dot product to work with persisted vectors | |||
sort(query_vector) | |||
query_vector = sort_sparse_vector(query_vector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's embarrassing, I guess I thought this was a sort in place 😵💫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈
if is_sorted(vector): | ||
return vector | ||
|
||
sorted_indices = np.argsort(vector.indices) | ||
return SparseVector( | ||
indices=vector.indices[sorted_indices], | ||
values=vector.values[sorted_indices], | ||
indices=[vector.indices[i] for i in sorted_indices], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector.indices
and vector.values
are built-in python lists
This kind of lists does not support indexing by array of indices
To take elements from an array by several indices, this array should support such an operation (e.g. np.array)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
* fix: fix sparse vector sorting * fix: fix sparse vector sort
#439