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

Fix null numeric filter conditions #164

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

bsbodden
Copy link
Collaborator

Ensures that the Num class correctly handles 0 as a valid value. This PR modifies the __str__ method to check if the value is None explicitly instead of using a condition that treats 0 as false.

Context:

Q: Is there a way possible to set the filter to a num 0. Below is the client query,
filter_conditions: FilterExpression = ((Tag("doc_base_id") == doc_base.id) &
                        (Tag("file_id") == file_id) &
                        (Num("chunk_number") == chunk_num))
When I instantiate the query with a non-zero chunk_number, the generated query looks as expected and the result only contains the requested chunk:
[doc_base.id](http://doc_base.id/)
'AIGuildDemo'
file_id
'e9ffbac9ff6f67cc'
chunk_num
1
str(filter_conditions)
'((@doc_base_id:{AIGuildDemo} @file_id:{e9ffbac9ff6f67cc}) @chunk_number:[1 1])'
However, when I set chunk_num to 0, chunk_number gets left out of the query entirely, and the result of the query is all chunks with that doc_base_id and file_id:
[doc_base.id](http://doc_base.id/)
'AIGuildDemo'
file_id
'e9ffbac9ff6f67cc'
chunk_num
0
str(filter_conditions)
'(@doc_base_id:{AIGuildDemo} @file_id:{e9ffbac9ff6f67cc})'
Based on a look through redisvl documentation, it seems that this issue might be related to this feature where passing “None” will drop the filter
Is there way way to use redisvl to filter entries where chunk_number is 0?

Copy link
Collaborator

@tylerhutcherson tylerhutcherson left a comment

Choose a reason for hiding this comment

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

Great fix. LGTM

@tylerhutcherson tylerhutcherson added the bug Something isn't working label Jun 18, 2024
@tylerhutcherson tylerhutcherson changed the title Fix Num filter should handle 0 value Fix null numeric filter conditions Jun 18, 2024
@tylerhutcherson tylerhutcherson merged commit 1505f5d into main Jun 18, 2024
20 checks passed
@tylerhutcherson tylerhutcherson deleted the bsb/fix_num_filter_to_handle_0 branch June 18, 2024 17:11
@bsbodden bsbodden self-assigned this Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants