---
title: "Same Query, Same Score: Consistent Ranking with StableTfl in Atlas Search"
description: "Paginated search in Atlas Search can show duplicate or skipped results across pages because BM25 scores drift between replicas due to changing corpus statistics. The usual workarounds like sticky routing or index snapshots require extra state and are cumbersome. The solution is StableTfl, a scoring function that uses only term frequency and document length, with term length as a proxy for rarity based on Zipf’s brevity law, eliminating corpus statistics and requiring no extra state. StableTfl is contributed to Apache Lucene and is available as a per-field similarity option in Atlas Search. Benchmarks on BEIR show StableTfl achieves 0.315 NDCG@10 compared to BM25’s 0.346, a 9% relative drop, making it suitable for paginated search, RAG pipelines, and multi-replica deployments where consistency matters more than peak relevance."
---

# Same Query, Same Score: Consistent Ranking with StableTfl in Atlas Search

[MongoDB](https://yomu.fyi/company/mongodb) · Sep 25, 2026

**Type:** Explainer

## Summary

Paginated search in Atlas Search can show duplicate or skipped results across pages because BM25 scores drift between replicas due to changing corpus statistics. The usual workarounds like sticky routing or index snapshots require extra state and are cumbersome. The solution is StableTfl, a scoring function that uses only term frequency and document length, with term length as a proxy for rarity based on Zipf’s brevity law, eliminating corpus statistics and requiring no extra state. StableTfl is contributed to Apache Lucene and is available as a per-field similarity option in Atlas Search. Benchmarks on BEIR show StableTfl achieves 0.315 NDCG@10 compared to BM25’s 0.346, a 9% relative drop, making it suitable for paginated search, RAG pipelines, and multi-replica deployments where consistency matters more than peak relevance.

## Context

Paginated search in Atlas Search can produce duplicate or skipped results across pages because BM25 scores depend on corpus statistics that vary between replicas and over time. Standard mitigations like sticky routing or index snapshots require extra state and are cumbersome.

## Approach / What changed

StableTfl scores documents using only term frequency and document length, with term length as a proxy for rarity via a probabilistic model. It precomputes term rarity for all 256 possible document length encodings, making scoring efficient. It is available as a per-field similarity option in Atlas Search and has been contributed to Apache Lucene.

## Takeaways

- StableTfl eliminates corpus statistics from scoring, using only term frequency and document length, with term length as a proxy for rarity, ensuring consistent scores across replicas.
- Benchmarks on BEIR show StableTfl achieves 0.315 NDCG@10 compared to BM25’s 0.346, a 9% relative drop in relevance, but provides deterministic ranking.
- StableTfl is suitable for paginated search, RAG pipelines, and multi-replica deployments where consistency is critical, while BM25 remains the default for raw relevance.

## FAQ

### How does StableTfl estimate term rarity without corpus statistics?

It uses term length as a proxy, based on Zipf's brevity law, where longer terms are rarer. It models the probability that a document contains a term of a given length using a probabilistic formula.

### What is the relevance cost of using StableTfl compared to BM25?

On BEIR, StableTfl achieves 0.315 NDCG@10 vs BM25's 0.346, a 9% relative drop, but provides consistent ranking across replicas.

### How is StableTfl implemented efficiently in Lucene?

Term rarity is precomputed for all 256 possible document length encodings, so scoring reduces to an array lookup, one multiplication, and one division, avoiding transcendental functions.

**Tags:** [Apache Lucene](https://yomu.fyi/topic/apache-lucene), [BM25](https://yomu.fyi/topic/bm25), [MongoDB Atlas](https://yomu.fyi/topic/mongodb-atlas), [Search](https://yomu.fyi/topic/search)

- Source: [MongoDB](https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search)
- Source URL: https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search
- Ingested by Yomu: 2026-09-25T18:00:13.968Z

[Read original post](https://www.mongodb.com/company/blog/engineering/same-query-same-score-consistent-ranking-with-stabletfl-atlas-search)
