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

[ENH] add not contains filter to where clause #1469

Merged
merged 3 commits into from
Dec 6, 2023

Conversation

weiligu
Copy link
Contributor

@weiligu weiligu commented Dec 6, 2023

Description of changes

Summarize the changes made by this PR.

There are some formatting changes included

Test plan

  • test_filtering.py and test_metadata.py

Documentation Changes

will update [docs]user-guide
added an example to Where Filtering

Copy link

github-actions bot commented Dec 6, 2023

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 (Readbility, Modularity, Intuitiveness)

Copy link
Member

@beggers beggers left a comment

Choose a reason for hiding this comment

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

One nit from me -- this looks great (and lots of users have been asking for it)!

if "%" in expr or "_" in expr:
expr = expr.replace("%", ".").replace("_", ".")
return doc and re.search(expr, doc) is None
return doc and expr not in doc
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I don't love that we check doc and ... for this if-branch but not the above branch.

Could we instead do one of:

  • Do an if not doc check above so both branches benefit from it
  • Also do the doc and ... check in the key == "$contains" branch
  • Not do the check here (not possible if the typechecker is complaining)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add the check above the if-branch.
this check exists because SQLite 'not like' does not return rows for empty or NULL strings. In this case, both "contains" and "not_contains" will not return NULL or empty strings. We can also argue that "not_contains" should return all NULL and empty strings.

@@ -309,7 +317,7 @@ def test_boolean_metadata(api: ServerAPI) -> None:


def test_get_empty(api: ServerAPI) -> None:
"""Tests that calling get() with empty filters returns nothing"""
"""Tests that calling get() with empty filters returns Fhing"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Tests that calling get() with empty filters returns Fhing"""
"""Tests that calling get() with empty filters returns nothing"""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, will fix this

Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

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

We also have to update the documentation, can you link to a docs PR ?

@HammadB
Copy link
Collaborator

HammadB commented Dec 6, 2023

We will also have to add this to the js client - i think its typed - cc @jeffchuber

@tazarov
Copy link
Contributor

tazarov commented Dec 6, 2023

@weiligu, this looks great. Thank you. Do you mind also including an example of this the operator is used in either a new or one of the existing notebooks under https://github.com/chroma-core/chroma/blob/main/examples/basic_functionality/. Perhaps in where_filtering.ipynb

@weiligu weiligu enabled auto-merge (squash) December 6, 2023 17:44
@weiligu weiligu merged commit 88db738 into main Dec 6, 2023
94 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.

[Feature Request]: Add $notContains to where_document
4 participants