Repository navigation
fix(solr): match ints and floats alike in numeric filters - #4173
akshit-khandelwal47 wants to merge 1 commit into
Conversation
An int and a float of the same metadata key are stored in different fields (meta_l_<key> and meta_d_<key>), but a filter only queried the field matching the type of its own value. With ratings [3, 4, 4.5, 5.0], `rating >= 4` returned only 4. Numeric equality, range and `in` filters now query both fields. plong rejects a fractional term, so a fractional bound is compared against the int field as the nearest whole number the range admits, inclusively (`> 4.5` becomes `>= 5`). A fractional equality value only targets the float field, since no int can equal it. Fixes deepset-ai#4083 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage report (solr)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
Hi @akshit-khandelwal47, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
The CLA check hasn't run on this PR, so there is nothing for me to sign yet. When I tried to sign at cla-assistant.io on 2026-10-29 it returned "Bad credentials", and other PRs opened since Oct 28 (#4171 here, deepset-ai/haystack#13481 to #13483) have no |
Related Issues
Proposed Changes:
An int and a float of the same metadata key are stored in different fields (
meta_l_<key>andmeta_d_<key>), and a filter only queried the field matching the type of its own value. Mixed int/float metadata, which is what JSON gives you, lost documents on every numeric operator.Numeric
==,!=, ranges,inandnot innow query both fields:rating == 5becomes(meta_l_rating:5 OR meta_d_rating:5). A fractional value such as4.5only targetsmeta_d_, since no int can equal it.plongrejects a fractional bound, so for ranges the int field is compared with the nearest whole number the range still admits, inclusively:> 4.5becomesmeta_l_rating:[5 TO *]on the int side,< 4.5becomes[* TO 4].id,content, strings, bools and non-finite floats keep the existing single-field clauses.How did you test it?
test_numeric_filters_match_ints_and_floats_alikewrites ratings[-1.5, -1, 3, 4, 4.5, 5, 5.0]and checks 13 filters againstInMemoryDocumentStoreon the same documents. 12 of them fail onmain.5.0),inwith mixed values, and theinfcase.hatch run test:allagainst Solr 10.0.0 from the integration's compose setup: 543 passed, 4 skipped.hatch run fmt-checkandhatch run test:typespass.Notes for the reviewer
List-valued metadata is not changed here.
[4, 4.5]is stored as JSON because the element types differ, and== [4, 5]against a stored[4.0, 5.0]still does not match. It is the same class of problem on a different code path, so I left it out of this PR. Happy to open a separate issue for it.AI disclosure: I used Claude Code to help write this change and its tests. I reviewed every line and ran the tests above myself.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:.