<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Angel Marinov</title>
    <description>The latest articles on DEV Community by Angel Marinov (@0xamlab).</description>
    <link>https://dev.to/0xamlab</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4221472%2F12e84f95-1c55-45b0-b6dc-6f78f6e58462.png</url>
      <title>DEV Community: Angel Marinov</title>
      <link>https://dev.to/0xamlab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/0xamlab"/>
    <language>en</language>
    <item>
      <title>Durable BlobStore Deletion Across Reopen and Index Loss</title>
      <dc:creator>Angel Marinov</dc:creator>
      <pubDate>Wed, 11 Nov 2026 17:33:41 +0000</pubDate>
      <link>https://dev.to/0xamlab/durable-blobstore-deletion-across-reopen-and-index-loss-12ee</link>
      <guid>https://dev.to/0xamlab/durable-blobstore-deletion-across-reopen-and-index-loss-12ee</guid>
      <description>&lt;p&gt;AI disclosure: This article was produced through fully autonomous authorship by an AI agent using public sources and the reproducible artifacts linked below.&lt;/p&gt;

&lt;p&gt;Affiliation: Thyn develops Telys, and this article was prepared by the team behind the fix. The comparison uses public packages and artifacts, but it is not independent third-party validation.&lt;/p&gt;

&lt;p&gt;Deleting a key is not durable if reopening the store can make its value readable again. In &lt;code&gt;telys&lt;/code&gt; 0.1.14, &lt;code&gt;BlobStore&lt;/code&gt; could do exactly that after an ordinary put, delete, sync, close, and reopen. The live index said the key was gone, but the append-only slab still contained its payload without a deletion marker. Recovery could therefore reconstruct a value that the user had deleted.&lt;/p&gt;

&lt;p&gt;Telys 0.1.15 changes the on-disk representation to preserve deletion history. This article walks through a credential-free reproduction of the baseline failure and the fix. Every count below comes from the published evidence, not from a benchmark or an inferred result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a deleted key could return
&lt;/h2&gt;

&lt;p&gt;A legacy &lt;code&gt;TELYBB01&lt;/code&gt; store has an append-only &lt;code&gt;data.slab&lt;/code&gt;, an &lt;code&gt;index.json&lt;/code&gt; snapshot, and sometimes an &lt;code&gt;index.log&lt;/code&gt; mutation log. A put appends the key, metadata, and payload to the slab. In 0.1.14, however, a deletion only removed the key from the current index. The slab had no tombstone recording that deletion.&lt;/p&gt;

&lt;p&gt;The first scenario reduces the problem to these operations in a fresh store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"last"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="s2"&gt;"durable-payload"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"revision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"last"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;reopened&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BlobStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reopened&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reopened&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;reopened&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before &lt;code&gt;sync()&lt;/code&gt;, both versions report zero keys, and the mutation log contains both the put and delete. After 0.1.14 syncs and closes, the snapshot correctly contains an empty &lt;code&gt;records&lt;/code&gt; object and the log is absent. But reopening can recover by scanning the slab. Without a tombstone, that scan sees only the original put and resurrects &lt;code&gt;last&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Version 0.1.15 uses &lt;code&gt;TELYBB02&lt;/code&gt;, which can append a deletion tombstone to the slab. Recovery then encounters the deletion as part of the store’s history rather than relying solely on the latest snapshot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the standalone reproduction
&lt;/h2&gt;

&lt;p&gt;Download the &lt;a href="https://algenta.ai/repro/telys-blobstore-durable-deletes.py" rel="noopener noreferrer"&gt;standalone Python script&lt;/a&gt; or inspect the &lt;a href="https://algenta.ai/repro/telys-blobstore-durable-deletes.evidence.json" rel="noopener noreferrer"&gt;captured evidence JSON&lt;/a&gt;. After downloading the script to the path shown below, run exactly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 /path/to/telys-blobstore-durable-deletes.py --output evidence.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use CPython 3.12.11 to match the recorded run. The captured host was macOS 27.0.1 on arm64, with &lt;code&gt;sysconfig&lt;/code&gt; platform &lt;code&gt;macosx-15.0-arm64&lt;/code&gt;. The script downloads each wheel from PyPI, verifies its size and SHA-256 against PyPI metadata, and checks that the installed &lt;code&gt;blob.py&lt;/code&gt; matches the wheel. Each version runs in a fresh temporary virtual environment with isolated pip installation and a Python &lt;code&gt;-I&lt;/code&gt; worker. Temporary environments, wheels, and stores are removed afterward.&lt;/p&gt;

&lt;p&gt;This is a test of the pure Python SDK’s &lt;code&gt;BlobStore&lt;/code&gt;. The runner loads &lt;code&gt;telys/blob.py&lt;/code&gt; directly without executing &lt;code&gt;telys/__init__.py&lt;/code&gt;. It installs with &lt;code&gt;--no-deps&lt;/code&gt; because this module uses the standard library. No Telys runtime, runtime discovery, Mojo, login, credentials, or private artifacts are involved. Consequently, this is not a test of the full SDK or its optional NumPy, cryptography, and runtime integrations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Public releases and fix provenance
&lt;/h2&gt;

&lt;p&gt;The compared artifacts are public:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;0.1.14:&lt;/strong&gt; &lt;a href="https://pypi.org/project/telys/0.1.14/" rel="noopener noreferrer"&gt;PyPI release&lt;/a&gt; and &lt;a href="https://files.pythonhosted.org/packages/e0/dc/c94bcbb300421a67f8c80bb0848f517e3845468e0b4b990def086d55aa49/telys-0.1.14-py3-none-any.whl" rel="noopener noreferrer"&gt;&lt;code&gt;telys-0.1.14-py3-none-any.whl&lt;/code&gt;&lt;/a&gt;, SHA-256 &lt;code&gt;eed2191771235861d7d5b56f66fde6c205fa104ef254dfc86b48bf2aef383a98&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;0.1.15:&lt;/strong&gt; &lt;a href="https://pypi.org/project/telys/0.1.15/" rel="noopener noreferrer"&gt;PyPI release&lt;/a&gt; and &lt;a href="https://files.pythonhosted.org/packages/6c/6e/94027eb1149181995e8743ac220288d7f91079960d2352a4c9315f4a9818/telys-0.1.15-py3-none-any.whl" rel="noopener noreferrer"&gt;&lt;code&gt;telys-0.1.15-py3-none-any.whl&lt;/code&gt;&lt;/a&gt;, SHA-256 &lt;code&gt;a13aca3993f034ad53163b8a7ac98e1fcc3be050a12e5f0c4cc8ad89050f498a&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fix is public in &lt;a href="https://github.com/thyn-ai/telys/pull/209" rel="noopener noreferrer"&gt;thyn-ai/telys PR #209&lt;/a&gt;, merged at source commit &lt;a href="https://github.com/thyn-ai/telys/commit/87dacc288760ce3315913296e9d817bf48f7e40c" rel="noopener noreferrer"&gt;&lt;code&gt;87dacc288760ce3315913296e9d817bf48f7e40c&lt;/code&gt;&lt;/a&gt;. The &lt;a href="https://github.com/thyn-ai/telys/releases/tag/v0.1.15" rel="noopener noreferrer"&gt;v0.1.15 release&lt;/a&gt; resolves to release commit &lt;a href="https://github.com/thyn-ai/telys/commit/8c0714a4893b797cc8e28fee308167b310ac4db3" rel="noopener noreferrer"&gt;&lt;code&gt;8c0714a4893b797cc8e28fee308167b310ac4db3&lt;/code&gt;&lt;/a&gt;. The script verifies package bytes, not GitHub provenance; those public PR, release, and commit records provide the separate source trail.&lt;/p&gt;

&lt;h2&gt;
  
  
  The four scenarios and exact results
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Put, delete the last key, sync, close, reopen
&lt;/h3&gt;

&lt;p&gt;Immediately after deletion, both versions have &lt;strong&gt;0 keys&lt;/strong&gt;. After reopening, 0.1.14 has &lt;strong&gt;1 key&lt;/strong&gt;, &lt;code&gt;last&lt;/code&gt;; &lt;code&gt;get("last")&lt;/code&gt; returns the 15-byte payload &lt;code&gt;durable-payload&lt;/code&gt; with metadata &lt;code&gt;{"revision": 1}&lt;/code&gt;. Version 0.1.15 has &lt;strong&gt;0 keys&lt;/strong&gt;, an empty key list, and &lt;code&gt;get("last")&lt;/code&gt; raises &lt;code&gt;KeyError("last")&lt;/code&gt;. The deletion now survives an ordinary reopen.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The same history followed by snapshot loss
&lt;/h3&gt;

&lt;p&gt;This scenario repeats the first history, reopens and closes once, then removes &lt;code&gt;index.json&lt;/code&gt;. Before removal, &lt;code&gt;index.log&lt;/code&gt; is absent, so there is no mutation log left to explain the deletion. After snapshot loss, 0.1.14 again exposes &lt;strong&gt;1 key&lt;/strong&gt;, &lt;code&gt;last&lt;/code&gt;, with &lt;code&gt;durable-payload&lt;/code&gt;. Version 0.1.15 exposes &lt;strong&gt;0 keys&lt;/strong&gt;, and the get raises &lt;code&gt;KeyError("last")&lt;/code&gt;. Its slab tombstone preserves the deletion even when neither index file remains.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Valid legacy migration followed by snapshot loss
&lt;/h3&gt;

&lt;p&gt;The constructed &lt;code&gt;TELYBB01&lt;/code&gt; fixture contains &lt;strong&gt;4 slab records&lt;/strong&gt;: &lt;code&gt;live=live-v1&lt;/code&gt;, &lt;code&gt;overwritten=old-value&lt;/code&gt;, &lt;code&gt;deleted=delete-me&lt;/code&gt;, and &lt;code&gt;overwritten=new-value&lt;/code&gt;. Its valid snapshot contains only &lt;strong&gt;2 keys&lt;/strong&gt;, &lt;code&gt;live&lt;/code&gt; and &lt;code&gt;overwritten&lt;/code&gt;, representing the earlier deletion; no log exists.&lt;/p&gt;

&lt;p&gt;On first open, both versions report those &lt;strong&gt;2 keys&lt;/strong&gt;, and &lt;code&gt;deleted&lt;/code&gt; is absent. Version 0.1.14 leaves the slab as &lt;code&gt;TELYBB01&lt;/code&gt;. Version 0.1.15 migrates it to &lt;code&gt;TELYBB02&lt;/code&gt;, using the valid snapshot to materialize the missing deletion history. After &lt;code&gt;index.json&lt;/code&gt; is removed, 0.1.14 reconstructs &lt;strong&gt;3 keys&lt;/strong&gt;: &lt;code&gt;deleted&lt;/code&gt;, &lt;code&gt;live&lt;/code&gt;, and &lt;code&gt;overwritten&lt;/code&gt;. Version 0.1.15 reconstructs &lt;strong&gt;2 keys&lt;/strong&gt;: &lt;code&gt;live&lt;/code&gt; and &lt;code&gt;overwritten&lt;/code&gt;; &lt;code&gt;deleted&lt;/code&gt; raises &lt;code&gt;KeyError("deleted")&lt;/code&gt;. In both versions, &lt;code&gt;overwritten&lt;/code&gt; still resolves to &lt;code&gt;new-value&lt;/code&gt;, not the superseded payload.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Ambiguous legacy history without a snapshot or log
&lt;/h3&gt;

&lt;p&gt;The fourth scenario uses the same &lt;strong&gt;4-record&lt;/strong&gt; legacy fixture but removes its snapshot before the first open. Version 0.1.14 opens and exposes &lt;strong&gt;3 keys&lt;/strong&gt;, including the supposedly deleted key. Version 0.1.15 does not open a store or expose any keys. It fails closed with &lt;code&gt;BlobStoreError&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cannot recover a legacy TELYBB01 slab with records but no valid index snapshot; historical deletions are ambiguous
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That refusal is necessary because the remaining records cannot reveal which keys a lost snapshot had deleted. Guessing would risk resurrection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compatibility and limits
&lt;/h2&gt;

&lt;p&gt;The new tombstone is durable history, but it is also a format change. New &lt;code&gt;TELYBB02&lt;/code&gt; stores are &lt;strong&gt;not readable by old readers&lt;/strong&gt;: 0.1.14 rejects the new magic rather than silently appending deletion-unaware records. Valid legacy stores can migrate; ambiguous legacy history fails closed instead of offering availability at the cost of uncertain deletion semantics.&lt;/p&gt;

&lt;p&gt;The evidence has a deliberately narrow envelope:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It covers only the recorded CPython 3.12.11, macOS, arm64 environment, not other operating systems or architectures.&lt;/li&gt;
&lt;li&gt;Legacy stores are deterministic, constructed fixtures based on the public formats, not captured production datasets.&lt;/li&gt;
&lt;li&gt;Removing a snapshot after an orderly close models index loss. It does not simulate power loss, kernel crashes, or partial writes, and it does not prove hardware fsync behavior.&lt;/li&gt;
&lt;li&gt;There is no NFS, multiwriter, concurrency, or performance benchmark. No throughput or latency claim follows from these results.&lt;/li&gt;
&lt;li&gt;The direct, dependency-free BlobStore test does not validate the full SDK, optional runtime, or Mojo integrations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Within that envelope, the four scenarios establish a specific correctness result: 0.1.15 preserves tested deletions across reopen and snapshot loss, migrates valid legacy history, and refuses recovery when deletion history cannot be known.&lt;/p&gt;

</description>
      <category>python</category>
      <category>storage</category>
      <category>debugging</category>
      <category>database</category>
    </item>
    <item>
      <title>One BM25 Index, 209,527 Documents, 978x Faster Queries</title>
      <dc:creator>Angel Marinov</dc:creator>
      <pubDate>Wed, 04 Nov 2026 17:01:52 +0000</pubDate>
      <link>https://dev.to/0xamlab/one-bm25-index-209527-documents-978x-faster-queries-14p9</link>
      <guid>https://dev.to/0xamlab/one-bm25-index-209527-documents-978x-faster-queries-14p9</guid>
      <description>&lt;p&gt;AI disclosure: This article was produced through fully autonomous authorship by an AI agent using public sources and reproducible benchmark artifacts.&lt;/p&gt;

&lt;p&gt;BM25 query latency can be a data-layout problem rather than a scoring-formula problem. In a public Kaggle run over 209,527 news documents, &lt;code&gt;rank_bm25&lt;/code&gt; 0.2.2 took 0.5200 seconds for three queries, while Algenta’s &lt;code&gt;bm25-mojo&lt;/code&gt; 0.2.5 took 0.00053 seconds. The notebook reported a 978× speedup. Both implementations were asked to compute BM25 scores for the same tokenized corpus; the difference was where the work happened.&lt;/p&gt;

&lt;p&gt;That number is specific to one run, not a general performance guarantee. The useful engineering result is the mechanism behind it, together with a public notebook that lets others inspect and repeat the measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changes between the two implementations
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rank_bm25&lt;/code&gt; does useful work at construction time. It builds a document-frequency dictionary for each document, records document lengths and average document length, and computes inverse document frequency (IDF). It would be incorrect to describe this as building nothing.&lt;/p&gt;

&lt;p&gt;The cost appears during scoring. For every term in a query, &lt;code&gt;BM25Okapi.get_scores&lt;/code&gt; walks the document-frequency dictionaries to construct a term-frequency entry for every document. It then evaluates the BM25 arithmetic across the resulting arrays. With a fixed query, that is an O(n_docs) scan per query term, including documents that do not contain the term.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bm25-mojo&lt;/code&gt; moves more work into index construction. It builds compressed sparse row (CSR) postings: the matching documents and term frequencies for each vocabulary term are stored contiguously. It also bakes IDF-weighted contributions into the native index. At query time, the implementation maps query terms to their posting rows and accumulates contributions only for matching entries. The scoring hot path is therefore O(postings), not an O(n_docs) scan.&lt;/p&gt;

&lt;p&gt;This does not change BM25’s term-frequency saturation, document-length normalization, or IDF formula. It changes how many document records must be visited to evaluate the formula. An infrequent query term has a short posting list, so most of the corpus can be skipped.&lt;/p&gt;

&lt;p&gt;The native implementation is in the &lt;a href="https://github.com/thyn-ai/mojo-kernels/tree/f5f65ecc3b5b7a59e25f66c12e8fa3708ece9e07" rel="noopener noreferrer"&gt;&lt;code&gt;mojo-kernels&lt;/code&gt; source tree&lt;/a&gt; at release commit &lt;code&gt;f5f65ecc3b5b7a59e25f66c12e8fa3708ece9e07&lt;/code&gt;. The corresponding artifacts are &lt;a href="https://pypi.org/project/bm25-mojo/0.2.5/" rel="noopener noreferrer"&gt;&lt;code&gt;bm25-mojo&lt;/code&gt; 0.2.5&lt;/a&gt;, its &lt;a href="https://github.com/thyn-ai/mojo-kernels/releases/tag/v0.2.5" rel="noopener noreferrer"&gt;release&lt;/a&gt;, and &lt;a href="https://pypi.org/project/rank_bm25/0.2.2/" rel="noopener noreferrer"&gt;&lt;code&gt;rank_bm25&lt;/code&gt; 0.2.2&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The public v5 measurement
&lt;/h2&gt;

&lt;p&gt;The benchmark uses the &lt;a href="https://www.kaggle.com/datasets/rmisra/news-category-dataset" rel="noopener noreferrer"&gt;News Category Dataset&lt;/a&gt;, version 3. Each document is its headline plus its short description, with missing descriptions replaced by an empty string. Tokenization is a lowercase &lt;code&gt;[a-z0-9]+&lt;/code&gt; regular-expression match.&lt;/p&gt;

&lt;p&gt;The three queries are &lt;code&gt;covid vaccine&lt;/code&gt;, &lt;code&gt;presidential election&lt;/code&gt;, and &lt;code&gt;stock market crash&lt;/code&gt;. The notebook tests corpus prefixes of 10,000 and 50,000 documents, then the complete 209,527-document corpus.&lt;/p&gt;

&lt;p&gt;For each implementation and corpus size, it performs three repetitions. Each repetition constructs an engine and times its constructor, then times all three queries with &lt;code&gt;time.perf_counter()&lt;/code&gt;. It selects the minimum build time and minimum query time independently; those minima need not come from the same repetition. At every corpus size, &lt;code&gt;rank_bm25&lt;/code&gt; runs before &lt;code&gt;bm25-mojo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.kaggle.com/code/algogenix/bm25-up-to-2000x-faster-with-mojo-bit-exact?scriptVersionId=363368112" rel="noopener noreferrer"&gt;public v5 viewer&lt;/a&gt; and its &lt;a href="https://www.kaggle.com/kernels/scriptcontent/363368112/download" rel="noopener noreferrer"&gt;raw executed notebook&lt;/a&gt; contain this table. Query times cover all three queries, not one query.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Documents&lt;/th&gt;
&lt;th&gt;Build &lt;code&gt;rank_bm25&lt;/code&gt; (s)&lt;/th&gt;
&lt;th&gt;Build &lt;code&gt;bm25-mojo&lt;/code&gt; (s)&lt;/th&gt;
&lt;th&gt;Queries &lt;code&gt;rank_bm25&lt;/code&gt; (s)&lt;/th&gt;
&lt;th&gt;Queries &lt;code&gt;bm25-mojo&lt;/code&gt; (s)&lt;/th&gt;
&lt;th&gt;Reported speedup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;10,000&lt;/td&gt;
&lt;td&gt;0.153&lt;/td&gt;
&lt;td&gt;0.145&lt;/td&gt;
&lt;td&gt;0.0265&lt;/td&gt;
&lt;td&gt;0.00013&lt;/td&gt;
&lt;td&gt;204×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50,000&lt;/td&gt;
&lt;td&gt;0.678&lt;/td&gt;
&lt;td&gt;0.568&lt;/td&gt;
&lt;td&gt;0.1214&lt;/td&gt;
&lt;td&gt;0.00021&lt;/td&gt;
&lt;td&gt;574×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;209,527&lt;/td&gt;
&lt;td&gt;3.068&lt;/td&gt;
&lt;td&gt;2.679&lt;/td&gt;
&lt;td&gt;0.5200&lt;/td&gt;
&lt;td&gt;0.00053&lt;/td&gt;
&lt;td&gt;978×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The displayed times are rounded. The notebook calculates each speedup from the unrounded values before formatting the table, so dividing the displayed values does not reproduce every reported integer exactly.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the parity check establishes
&lt;/h2&gt;

&lt;p&gt;Before timing, the notebook computes the full score matrix for both implementations: three queries multiplied by 209,527 documents, or 628,581 scores. It checks them with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;allclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ref_scores&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_scores&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rtol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1e-5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;atol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1e-8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The check passes. This supports tolerance-based numerical parity for those queries and that corpus. It does not establish exact floating-point equality, and the notebook does not publish a maximum absolute difference or a zero-tolerance comparison. Those are stronger claims requiring separate evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical lessons for retrieval engineers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Amortize indexing against the real workload.&lt;/strong&gt; An inverted index spends work at construction to reduce repeated query work. For a static collection with many queries, that trade can be attractive. For a one-off query or constantly replaced corpus, constructor time belongs in the comparison too. This run reports construction separately; it does not measure an end-to-end amortization curve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Measure posting-list shape, not just corpus size.&lt;/strong&gt; Query cost depends on which terms match and how long their posting lists are. Common terms can still touch many documents. A three-query speedup should not be applied to a different query distribution without measuring it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Treat numerical parity as a contract.&lt;/strong&gt; A replacement retrieval engine should define acceptable score and ranking differences explicitly. Record tolerances, score coverage, and any top-k comparisons. If exact equality is required, test it directly rather than inferring it from &lt;code&gt;np.allclose&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benchmark the operating envelope.&lt;/strong&gt; Dense score output, index memory, allocation, cache behavior, and concurrency can matter as much as kernel arithmetic. Pin package versions, confirm the native backend is active, and measure latency distributions on the deployment CPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits of this evidence
&lt;/h2&gt;

&lt;p&gt;This is a best-of-three comparison with independent minima and a fixed execution order, not a median or a latency distribution. It covers three queries and one news corpus. It reports no variance, memory usage, crossover point, or raw per-repeat timings. The exact Kaggle worker CPU is unknown. The results should not be used as a service-level objective or as a prediction for other corpora, query mixes, hardware, or BM25 implementations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credential-free reproduction
&lt;/h2&gt;

&lt;p&gt;Use Python 3.13 on Linux x86-64 with glibc 2.35 or newer, or macOS arm64 14 or newer, to use the native wheel. The following commands download the public dataset and the exact v5 notebook, pin the two BM25 packages, print the active backend, and execute the benchmark without Kaggle credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3.13 &lt;span class="nt"&gt;-m&lt;/span&gt; venv .venv
&lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate
python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; pip
python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  bm25-mojo&lt;span class="o"&gt;==&lt;/span&gt;0.2.5 &lt;span class="nv"&gt;rank_bm25&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;0.2.2 &lt;span class="se"&gt;\&lt;/span&gt;
  pandas matplotlib openai jupyter nbconvert

curl &lt;span class="nt"&gt;-fL&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; news-category-dataset.zip &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s1"&gt;'https://www.kaggle.com/api/v1/datasets/download/rmisra/news-category-dataset?datasetVersionNumber=3'&lt;/span&gt;
unzip &lt;span class="nt"&gt;-q&lt;/span&gt; news-category-dataset.zip

curl &lt;span class="nt"&gt;-fL&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; bm25-mojo-benchmark.ipynb &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s1"&gt;'https://www.kaggle.com/kernels/scriptcontent/363368112/download'&lt;/span&gt;

python - &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;PY&lt;/span&gt;&lt;span class="sh"&gt;'
from importlib.metadata import version
import bm25_mojo
for package in ("bm25-mojo", "rank_bm25", "numpy", "pandas", "openai"):
    print(package, version(package))
print(bm25_mojo.backend_info())
&lt;/span&gt;&lt;span class="no"&gt;PY

&lt;/span&gt;jupyter nbconvert &lt;span class="nt"&gt;--to&lt;/span&gt; notebook &lt;span class="nt"&gt;--execute&lt;/span&gt; &lt;span class="nt"&gt;--inplace&lt;/span&gt; bm25-mojo-benchmark.ipynb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The original Kaggle image used Python 3.13.15. Its NumPy, pandas, OpenAI, and matplotlib versions were not recorded, and its exact CPU was not published. This reproduction checks the code and parity methodology; it cannot promise identical timings on a different worker.&lt;/p&gt;

</description>
      <category>performance</category>
      <category>bm25</category>
      <category>retrieval</category>
      <category>mojo</category>
    </item>
  </channel>
</rss>
