infiniflow / infiniflow/infinity
[Bug]: HTTP SDK match_sparse crashes when sparse_data is a dict (AttributeError: 'dict' object has no attribute 'to_dict')
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 445
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 7
Description
## Problem
`match_sparse` is declared to accept `SparseVector | dict`:
```python
def match_sparse(self, vector_column_name: str, sparse_data: SparseVector | dict, ...)
```
and both other SDKs honor that - the embedded SDK has an explicit `case dict()` arm and the thrift SDK handles dicts in `make_match_sparse_expr`. But the HTTP client crashes before sending anything:
```python
table.output(["c1"]).match_sparse("c2", {0: 1.0, 20: 2.0}, "ip", 3)
# AttributeError: 'dict' object has no attribute 'to_dict'
```
## Root cause
`python/infinity_sdk/infinity/infinity_http.py`, `table_http_result.match_sparse()`:
```python
"query_vector": sparse_data.to_dict(), # assumes SparseVector unconditionally
```
## Fix
Convert a `SparseVector` with `to_dict()` and pass a `dict` through as-is (the server parses `query_vector` as an `{index: value}` JSON object, which is exactly what a plain dict serializes to). Empty dicts and other types raise a clear `InfinityException` instead of an `AttributeError`.
## Testing
- Reproduced on current main (eca7266): dict input raised `AttributeError`; after the fix the same dict builds a `query_vector` payload identical in shape to the one `SparseVector.to_dict()` produces, `SparseVector` input is unchanged, and a list / empty dict raise `InfinityException`.
- Added regression test `test_sparse_knn_with_dict` in `python/test_pysdk/test_knn.py`, mirroring `test_sparse_knn` with a dict argument and the same expected result.
- Full pysdk suite not run locally; it needs a running server.
Contributor guide
Research direction
Start in python/infinity_sdk/infinity/infinity_http.py at table_http_result.match_sparse(), then inspect python/test_pysdk/test_knn.py and the existing test_sparse_knn case. Verify dict and SparseVector inputs produce the expected query_vector payload, while a list and empty dict raise InfinityException; run the focused test if a server is available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100