Skip to content

Native BM25 full-text scoring (TF/IDF + length normalization, field boosts, explain) #4687

Description

@lvca

Summary

ArcadeDB's FULL_TEXT index currently ranks results with a simple term-coordination (match-count) model, not BM25. This proposes adding native BM25 (TF/IDF + document-length normalization) scoring to the full-text search path, so lexical relevance matches what users expect from Lucene/Elasticsearch/Solr/CrateDB.

Raised in discussion #4664 (enterprise hybrid-retrieval evaluation: vector + BM25/full-text + graph traversal for government/legal documents).

Current behavior

Lucene is used by ArcadeDB only for analyzers/tokenizers/stemmers and query-syntax parsing - not for the inverted-index storage or its scoring engine.

In LSMTreeFullTextIndex.get() the score for a record starts at 1 and is incremented by 1 for every matching query term:

// Accumulate score for this RID based on number of matching query terms
final AtomicInteger score = scoreMap.get(rid);
if (score == null)
  scoreMap.put(rid, new AtomicInteger(1));
else
  score.incrementAndGet();

This means:

  • No term frequency (TF) within a document
  • No inverse document frequency (IDF)
  • No document-length normalization
  • No field boosts in the main scoring path
  • No score explanation / explain API

So a document mentioning a rare, highly-discriminative term once ranks the same as (or below) a document that trivially matches more common query terms. This is fine for boolean filtering but inadequate for relevance-ranked retrieval.

Note: BM25-style scoring with IDF (Robertson-Sparck-Jones) does already exist in the LSM_SPARSE_VECTOR path (BlockMax-WAND DAAT), but it requires the user to generate sparse vectors externally. There is no native "index text -> BM25 ranking" in the full-text path.

Proposed work

  1. BM25 similarity for FULL_TEXT / SEARCH_INDEX(...)

    • Maintain the needed statistics: per-term document frequency (IDF), per-document term frequency (TF), per-document/field length and average length for normalization.
    • Implement the standard BM25 formula with configurable k1 (default 1.2) and b (default 0.75).
    • Make it the default ranking model (with a compatibility switch to fall back to the legacy match-count score).
  2. Field boosts applied to the scoring (per-field weight in multi-field full-text indexes).

  3. Score explanation - optional explain output describing how a score was computed (term contributions, IDF/TF/norm factors).

  4. Configuration via index metadata (alongside the existing analyzer/defaultOperator/allowLeadingWildcard options): similarity model (BM25 | CLASSIC), k1, b, per-field boosts.

  5. (Stretch) Auto text -> sparse-vector / unified hybrid index: index text and expose it directly to vector.sparseNeighbors / vector.fuse without external sparse-vector generation, so BM25 lexical + dense vector + graph traversal fuse in a single query path.

Why

  • Closes the most-requested gap for accuracy-first hybrid retrieval (RAG, legal/government search).
  • Brings full-text ranking in line with Lucene/Elasticsearch/Solr/CrateDB expectations.
  • Composes cleanly with the existing vector.fuse(...) (RRF/DBSF/LINEAR) hybrid pipeline and in-database graph traversal.

Acceptance criteria

  • BM25 scoring available and default for full-text queries, with documented k1/b and a switch back to the classic model.
  • Field boosts honored in scoring.
  • Optional score explanation output.
  • Regression tests covering TF, IDF, length-normalization, field boosts, and backward-compatible classic mode.
  • Documentation updated (full-text indexing + hybrid retrieval pages).

References

  • Discussion: Any plan for BM25 and inverted index like lucene for Full text search? #4664
  • Code: engine/src/main/java/com/arcadedb/index/fulltext/LSMTreeFullTextIndex.java, FullTextQueryExecutor.java, engine/src/main/java/com/arcadedb/schema/FullTextIndexMetadata.java
  • Existing IDF reference implementation: engine/src/main/java/com/arcadedb/index/sparsevector/PaginatedSparseVectorEngine.java (Robertson-Sparck-Jones IDF + BlockMax-WAND)

Activity

  1. self-assigned this
    on Jun 21, 2026
  2. added this to the 26.7.1 milestone on Jun 21, 2026
  3. added theissue type on Jun 21, 2026
  4. added 9 commits that reference this issue on Jun 22, 2026
  5. 16 remaining items

  6. added 10 commits that reference this issue on Jun 23, 2026
  7. lvca commented on Jun 24, 2026

    @lvca
    MemberAuthor

    Implemented, docs updated ;-)

  8. lvca commented on Jun 24, 2026

    @lvca
    MemberAuthor

    Native BM25 full-text scoring has landed (implemented in #4695, merged) and the documentation is updated.

    What's in

    • Okapi BM25 ranking (TF + IDF + document-length normalization) for FULL_TEXT indexes, replacing the legacy term-coordination (match-count) model. BM25 is the default for newly created indexes; existing indexes keep CLASSIC until rebuilt, so upgrades are non-breaking on ranking.
    • Tunable parameters bm25_k1 / bm25_b, and per-field boosts (<field>_boost) for multi-property indexes.
    • Query-time caret boosts (term^N, field:term^N, group boosts), Lucene-style.
    • EXPLAIN / PROFILE now surface the scoring breakdown (similarity, k1/b, corpus stats, per-term df/idf/boost).
    • Java builder: withBM25(k1, b), withFieldBoost(field, boost), withSimilarity(...).
    • Hybrid retrieval: SEARCH_INDEX is a first-class leg of vector.fuse, so BM25 keyword relevance fuses with dense + sparse vectors (RRF) in one server-side query - the use case from Any plan for BM25 and inverted index like lucene for Full text search? #4664.
    • Plus fixes found along the way: a pre-existing full-text compaction posting-drop bug, full-text metadata persistence on restart, a content property name colliding with the parser default field, and REBUILD INDEX * WITH ... silently dropping the first setting.

    Note

    One behavior change for existing CLASSIC indexes: $score is now a float (was an Integer match count). Read it as a Number. See the release/upgrade notes for details.

    Examples

    Create a BM25 index (default) and rank with $score:

    CREATE INDEX ON Article (content) FULL_TEXT;
    
    SELECT title, $score FROM Article
    WHERE SEARCH_INDEX('Article[content]', 'java database') = true
    ORDER BY $score DESC;

    Boost a single word with the Lucene caret (^) - here "java" counts 3x more than "database":

    SELECT title, $score FROM Article
    WHERE SEARCH_INDEX('Article[content]', 'java^3 database') = true
    ORDER BY $score DESC;

    Tune parameters and add a per-field boost on a multi-property index:

    CREATE INDEX ON Article (title, body) FULL_TEXT
      METADATA { "similarity": "BM25", "bm25_k1": 1.2, "bm25_b": 0.75, "title_boost": 3.0 };
    
    -- field-qualified + caret boost: weight a title match 5x
    SELECT title, $score FROM Article
    WHERE SEARCH_INDEX('Article[title,body]', '+database title:java^5') = true
    ORDER BY $score DESC;

    Inspect the scoring with EXPLAIN:

    EXPLAIN SELECT title, $score FROM Article
    WHERE SEARCH_INDEX('Article[content]', 'java database') = true;

    Hybrid retrieval - fuse BM25 + dense + sparse with RRF (the #4664 pattern):

    SELECT title, score FROM (
      SELECT expand(`vector.fuse`(
          `vector.neighbors`('Case[dense]', :denseVec, 100),
          `vector.sparseNeighbors`('Case[tokens,weights]', :qIdx, :qVal, 100),
          (SELECT @rid, $score FROM Case WHERE SEARCH_INDEX('Case[content]', :keywords) = true),
          { fusion: 'RRF', k: 60 }
      ))
    ) ORDER BY score DESC LIMIT 10;

    To switch an existing index to BM25, rebuild it (REBUILD INDEX \Article[content]`); to repair/pre-warm the corpus counters without a full reindex, use REBUILD INDEX WITH statsOnly = true`.

    Thanks @sreekanthedayar for the detailed use case that drove this.

  9. sreekanthedayar commented on Jun 24, 2026

    @sreekanthedayar

    Well appreciated for this quick implementation. Need to build an adapter for ArcadeDB and test .

  10. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementfeatureperformance

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions