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

[BUG] Test that query result shapes are correct in invariants #2807

Merged

Conversation

drewkim
Copy link
Contributor

@drewkim drewkim commented Sep 16, 2024

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • Discovered that there is an issue with PersistentLocalHnswSegment where query_vectors can return results with lengths different than n_results. This PR implements a test both displays and catches this issue.
    • Fixes off by one issue in hnsw/BF merge logic in both single node and distributed

Test plan

How are these changes tested?

  • Added a test for the breaking case that fails on main, fix shows test passes
  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@@ -261,10 +259,14 @@ def ann_accuracy(
include=["embeddings", "documents", "metadatas", "distances"], # type: ignore[list-item]
)

_query_results_are_correct_shape(query_results, n_results)

# Assert fields are not None for type checking
Copy link
Collaborator

Choose a reason for hiding this comment

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

had to bring this back out for typechecker :(

query_results: types.QueryResult, n_results: int
) -> None:
for result_type in ["distances", "embeddings", "documents", "metadatas"]:
assert query_results[result_type] is not None # type: ignore[literal-required]
Copy link
Collaborator

Choose a reason for hiding this comment

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

pushed asserts down for debuggability

@@ -308,6 +309,55 @@ def test_persist_embeddings_state(
) # type: ignore


def test_delete_less_than_k(
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo: rename and clean up

@drewkim
Copy link
Contributor Author

drewkim commented Sep 17, 2024

LGTM! Counting is the hardest problem...

@@ -205,7 +205,7 @@ fn merge_results(
let mut brute_force_index = 0;

// TODO: This doesn't have to clone the user IDs, but it's easier for now
while (result_user_ids.len() <= k)
Copy link
Contributor

Choose a reason for hiding this comment

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

eww

Copy link
Contributor

@sanketkedia sanketkedia left a comment

Choose a reason for hiding this comment

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

Merge logic in both local and distributed look fine

@HammadB HammadB merged commit d17472e into main Sep 17, 2024
69 checks passed
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.

4 participants