Christopher Krah 8c101f49b9 fix(python): give tied scores the same rank in hybrid rank normalization (#5253)
Refs #4857, which expected tied FTS matches to count as the best FTS
result in both normalize modes. #4858 fixed the zero-range case and left
the tie-breaking in `_rank` open. With `normalize="rank"`, `_rank`
numbers equal scores in argsort order. Of two matches with the same BM25
score, argsort order alone picks the one that gets the lowest rank and
normalizes to 0, the value `LinearCombinationReranker` gives a document
without the keyword:

```python
rows = [{"text": "zebra apple", "vector": [5.0, 5.0]},
        {"text": "zebra grape", "vector": [5.0, 5.1]},
        {"text": "cherry plum", "vector": [0.0, 0.0]}]
# both zebra rows: _score 0.4700036
(tbl.search(query_type="hybrid").vector([0.0, 0.0]).text("zebra")
    .rerank(LinearCombinationReranker(weight=0.3), normalize="rank"))
# fdc8041, 0.42.0b38: zebra grape 0.70, cherry plum 0.30, zebra apple 0.15
# this change:        zebra apple 0.85, zebra grape 0.70, cherry plum 0.30
# normalize="score" already gives the second order
```

Equal scores now share the average of their ranks, as
`scipy.stats.rankdata` does by default. Without ties the ranks are
unchanged, and RRF and MRR do not read them. This also covers equal
vector distances. An untied lowest FTS hit still normalizes to the fill
value, and this PR leaves that as it is.

```
$ cd python && pytest python/tests/test_hybrid_query.py -q   # fdc8041 + 0.42.0b38 native module
30 passed, 1 skipped in 1.48s
# query.py reverted, tests kept: 2 failed (test_hybrid_tied_fts_matches_share_fts_weight[rank], test_rank_gives_tied_scores_the_same_rank)
$ ruff format --check . && ruff check .   # ruff 0.9.9, as CI pins
198 files already formatted
All checks passed!
$ pytest python/tests -m "not slow and not s3_test" -q -n 4   # fresh data/ dir each side
# fdc8041:     11 failed, 4474 passed, 375 skipped, 3 errors
# this change: 12 failed, 4476 passed, 375 skipped, 3 errors
# same 11 on both sides (namespace and stable-row-id tests, missing extras); the 12th, test_table.py::test_merge_insert, passed alone 3 times and in test_table.py -n 4
$ pytest --doctest-modules python/lancedb/query.py -q
23 passed
$ pyright   # 1.1.395: 5 errors in __init__.py and schema.py, the same at fdc8041; query.py is outside the include list
```

@Xuanwo, I picked the average over the best rank of the group, because
the average treats both directions the same. If you want tied FTS
matches to all get the top rank, I will change one line.

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
2026-11-30 20:11:51 +08:00
2023-03-17 18:15:19 -07:00
2025-03-10 09:01:23 -07:00

Reverie LanceDB Website Blog Discord Twitter LinkedIn

LanceDB

The Multimodal Lakehouse for AI

How to Install ✦ Detailed Documentation ✦ Tutorials and Recipes ✦ Contributors

The ultimate multimodal data platform for AI/ML applications.

LanceDB is designed for fast, scalable, and production-ready vector search. It is built on top of the Lance columnar format. You can store, index, and search over petabytes of multimodal data and vectors with ease. LanceDB is a central location where developers can build, train and analyze their AI workloads.


Demo: Multimodal Search by Keyword, Vector or with SQL

LanceDB Multimodal Search

Star LanceDB to get updates!

⭐ Click here ⭐ to see how fast we're growing!

Key Features:

  • Fast Vector Search: Search billions of vectors in milliseconds with state-of-the-art indexing.
  • Comprehensive Search: Support for vector similarity search, full-text search and SQL.
  • Multimodal Support: Store, query and filter vectors, metadata and multimodal data (text, images, videos, point clouds, and more).
  • Advanced Features: Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure. GPU support in building vector index.

Products:

  • LanceDB Embedded (open source): 100% open source, runs in your application's process; your data can live on local disk or in object storage. No vendor lock-in.
  • LanceDB Enterprise: Production-scale distributed search, indexing, and maintenance. Plus, complete data sovereignty and security.

Ecosystem:

  • Columnar Storage: Built on the Lance columnar format for efficient storage and analytics.
  • Seamless Integration: Python, Node.js, Rust, and REST APIs for easy integration. Native Python and Javascript/Typescript support.
  • Rich Ecosystem: Integrations with LangChain 🦜️🔗, LlamaIndex 🦙, Apache-Arrow, Pandas, Polars, DuckDB and more on the way.

How to Install:

Follow the Quickstart doc to set up LanceDB locally.

API & SDK: We also support Python, Typescript and Rust SDKs

Interface Documentation
Python SDK https://lancedb.github.io/lancedb/python/python/
Typescript SDK https://lancedb.github.io/lancedb/js/globals/
Rust SDK https://docs.rs/lancedb/latest/lancedb/index.html
REST API https://docs.lancedb.com/api-reference/rest

Join Us and Contribute

We welcome contributions from everyone! Whether you're a developer, researcher, or just someone who wants to help out.

If you have any suggestions or feature requests, please feel free to open an issue on GitHub or discuss it on our Discord server.

Check out the GitHub Issues if you would like to work on the features that are planned for the future. If you have any suggestions or feature requests, please feel free to open an issue on GitHub.

Contributors

Stay in Touch With Us


Website Blog Discord Twitter LinkedIn

License

See LICENSE for the project license.

S
Description
Developer-friendly OSS embedded retrieval library for multimodal AI. Search More; Manage Less.
Readme Apache-2.0
128 MiB
Languages
Rust 53.9%
Python 35.8%
TypeScript 9.4%
Java 0.6%
Shell 0.2%