|
| 1 | +"""Test ShardedIndex search with single-row 2D batch input. |
| 2 | +
|
| 3 | +Regression test for GitHub issue #22: AxisError when merging results from |
| 4 | +both view shards and active shard with a (1, ndim) shaped query vector. |
| 5 | +""" |
| 6 | + |
| 7 | +import numpy as np |
| 8 | + |
| 9 | +from iscc_usearch.sharded import ShardedIndex |
| 10 | + |
| 11 | + |
| 12 | +def test_search_single_row_batch_with_merge(tmp_path): |
| 13 | + """Search with shape (1, ndim) when both view and active shards have data.""" |
| 14 | + ndim = 64 |
| 15 | + index = ShardedIndex(ndim=ndim, path=tmp_path, shard_size=4096) |
| 16 | + |
| 17 | + # Add vectors and save to create view shards |
| 18 | + vectors = np.random.rand(50, ndim).astype(np.float32) |
| 19 | + index.add(list(range(50)), vectors) |
| 20 | + index.save() |
| 21 | + |
| 22 | + # Add more to active shard so merge path is triggered |
| 23 | + extra = np.random.rand(10, ndim).astype(np.float32) |
| 24 | + index.add(list(range(50, 60)), extra) |
| 25 | + |
| 26 | + # Verify both view and active shards have data |
| 27 | + assert index._view_shards is not None and len(index._view_shards) > 0 |
| 28 | + assert index._active_shard is not None and len(index._active_shard) > 0 |
| 29 | + |
| 30 | + # Single-row 2D input — this triggers the bug |
| 31 | + query = np.random.rand(1, ndim).astype(np.float32) |
| 32 | + result = index.search(query, count=5) |
| 33 | + |
| 34 | + assert len(result.keys) <= 5 |
| 35 | + assert len(result.distances) <= 5 |
0 commit comments