<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohamed Hakim Bedhief on Medium]]></title>
        <description><![CDATA[Stories by Mohamed Hakim Bedhief on Medium]]></description>
        <link>https://medium.com/@mohamedhakim.bedhief_91578?source=rss-0d451f8fff6a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6W8Z4hOvaOe3f-rW</url>
            <title>Stories by Mohamed Hakim Bedhief on Medium</title>
            <link>https://medium.com/@mohamedhakim.bedhief_91578?source=rss-0d451f8fff6a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:18:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohamedhakim.bedhief_91578/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optimizing ColPali Retrieval at Scale]]></title>
            <link>https://medium.com/@mohamedhakim.bedhief_91578/optimizing-colpali-retrieval-at-scale-6e88e45f8725?source=rss-0d451f8fff6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e88e45f8725</guid>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[colpali]]></category>
            <category><![CDATA[pooling]]></category>
            <category><![CDATA[late-interaction]]></category>
            <category><![CDATA[image-optimization]]></category>
            <dc:creator><![CDATA[Mohamed Hakim Bedhief]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 09:52:04 GMT</pubDate>
            <atom:updated>2026-02-26T09:52:04.986Z</atom:updated>
            <content:encoded><![CDATA[<p>ColPali-style retrieval is one of those things that feels magical when it works: you embed a query, compare it against patch-level vectors from document pages, and get very strong visual-text retrieval quality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*W2D0_zcGIwFmcZCE7mkQzQ.png" /></figure><h4><strong>The catch is cost.</strong></h4><p>In this project, each page produces about 1,030 token vectors. With late interaction (MaxSim), that means a lot of comparisons per query. It is fine on small demos, but once your corpus grows, latency and storage pressure quickly become real production issues.</p><p>If you are building RAG or enterprise search, this tradeoff shows up immediately:</p><ul><li>Product wants high recall.</li><li>Users want fast responses.</li><li>Infrastructure wants lower memory and compute load.</li></ul><p>The goal of this work was simple: <strong>keep ColPali-level retrieval quality while making search faster and lighter</strong>.</p><p>I tested multiple optimization paths on a reproducible setup in Qdrant:</p><ul><li>dual-axis pooling (row + column),</li><li>token clustering (KMeans centroids),</li><li>MUVERA prefetch + rerank,</li><li>and ablations across prefetch depth and reranker choices.</li></ul><p>The short version: the initial intuition (dual-axis pooling) did not hold up, and token clustering became the best practical strategy.</p><h3>1- Basline Setup</h3><p>Before optimizing anything, I established a baseline that all methods are compared against.</p><h4>Dataset and evaluation protocol</h4><ul><li>Dataset: vidore/docvqa_test_subsampled (prepared via data/download_vidore.py)</li><li>Working set in this experiment ( 500 page images, 500 query rows and one relevance label per query in this setup</li><li>Metrics ( Recall@10, MRR, NDCG@10 andmean query latency (ms))</li></ul><h4>Retrieval baseline</h4><p>The baseline is full multivector ColPali search (used VAGOsolutions/SauerkrautLM-ColQwen3–4b-v0.1 as the document/ query embedding model) in Qdrant with MaxSim scoring.</p><p><strong><em>SauerkrautLM-ColQwen3–4b-v0.1</em></strong> achieves 90.80 NDCG@5 on ViDoRe v1, making it the <strong>#2</strong> overall among <strong>128-dim</strong> models and the best in the Large (3–5B) category for ViDoRe v1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*gbufVYKxqGGYMfZ9h7qcyA.png" /><figcaption>Table : Full-Baseline Results</figcaption></figure><h4>Collection/index setup (reproducible)</h4><p>The experiment collection includes baseline and optimized vector slots:</p><ul><li>colpali_original (SauerkrautLM-ColQwen3–4b-v0.1)</li><li>pooled variants (row_pooled, column_pooled, hierarchical_2x, hierarchical_4x)</li><li>quantized variants (scalar_quantized, binary_quantized)</li><li>muvera_fde</li><li>clustered variants (clustered_8x, clustered_16x, clustered_32x, clustered_64x)</li></ul><pre>from common.qdrant_collections import recreate_colpali_muvera_collection<br><br>recreate_colpali_muvera_collection(<br>    qdrant,<br>    collection_name=&quot;colpali_perf_benchmark&quot;,<br>    colpali_dim=128,<br>    muvera_dim=MUVERA_DIM,<br>    enable_optimized=True,<br>    clustered_k_values=[8, 16, 32, 64],<br>)</pre><h3>2) Optimization Ideas (Intuition First)</h3><p>All methods in this post follow the same two-stage idea:</p><ol><li><strong>Fast prefetch</strong> on compressed vectors to get candidate pages.</li><li><strong>Full rerank</strong> with colpali_original to recover quality.</li></ol><p>This is important because we are not throwing away ColPali scoring; we are using <strong>cheaper </strong>vectors as a candidate filter.</p><h4>2.1 Dual-axis pooling</h4><p>A ColPali page can be viewed as a patch grid (roughly 32 x 32 in this setup).<br>Dual-axis pooling compresses this grid in two ways:</p><ul><li>row pooling: average along columns</li><li>column pooling: average along rows</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cWwwXk11JIrOYIloILzO-A.png" /></figure><p>Intuition: rows and columns may preserve different layout cues (horizontal vs vertical structure), and combining both candidate lists should improve coverage.</p><h4>2.2 Token clustering</h4><p>Instead of averaging by spatial axis, token clustering groups similar patch tokens and keeps only <strong>centroid vectors</strong>.</p><pre>def cluster_tokens_kmeans(image_tokens, k=16, n_init=5, random_state=42):<br>    from sklearn.cluster import KMeans<br>    k_eff = max(1, min(int(k), image_tokens.shape[0]))<br>    km = KMeans(n_clusters=k_eff, n_init=n_init, random_state=random_state)<br>    km.fit(image_tokens)<br>    return km.cluster_centers_.astype(&quot;float32&quot;)</pre><p>Intuition: semantic clusters can preserve diverse content (charts, text blocks, logos, figures) better than simple averaging.</p><h4>Two-stage retrieval flow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LQidN7Jzvu01Mnh5v4XUWQ.png" /></figure><h3>3) Experiments and Results</h3><h4>3.1 First experiment: dual-axis pooling + rerank</h4><p>Method:</p><ul><li>prefetch from row_pooled and column_pooled</li><li>union candidates</li><li>rerank with colpali_original</li></ul><p>The outcome:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*NrT5D1kcGFXkC8hKPxPHzA.png" /><figcaption>Table : Dual-axis pooling + rerank results</figcaption></figure><p>This was the first major surprise: dual-axis was not better than row-only in practice.</p><p>Candidate overlap analysis explained why:</p><ul><li>row vs column prefetch candidate sets had <strong>mean Jaccard overlap = 0.9958</strong></li><li>they were almost the same list most of the time</li></ul><p>So the “two views should add diversity” hypothesis mostly failed on this dataset.</p><h4>3.2 Token clustering approach</h4><p>Method:</p><ul><li>build clustered page vectors (clustered_8x, clustered_16x, clustered_32x, clustered_64x)</li><li>prefetch on clustered vectors</li><li>rerank with full colpali_original</li></ul><p>Results:</p><ul><li><strong>32× compression</strong> offers the optimal balance — near-baseline quality with 4× speedup</li><li><strong>16× compression</strong> sacrifices more accuracy (Recall@10: 0.732) with similar latency</li><li><strong>8× compression</strong> shows significant quality drop (Recall@10: 0.690), suggesting over-compression</li></ul><p>The tradeoff was much better than pooling: quality stayed close while latency dropped significantly.</p><h4>3.3 Ablation studies</h4><p>I then ran controlled sweeps on prefetch depth, cluster K, axis choices, and reranker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*XvXz4sa8xrsbxYNay2FrGg.png" /><figcaption>Table : Ablation study</figcaption></figure><p>Takeaway: <strong>deeper prefetch</strong> helps dual-axis a bit, but it never catches up. Clustered variants remain strong and fast even at low/moderate prefetch.</p><h4>3.4 Final comparison</h4><p>clustered_64x_rerank was the most balanced winner:</p><ul><li>slightly better recall/NDCG (<strong>0.631</strong>) than baseline(<strong>0.630</strong>),</li><li>roughly <strong>2x lower latency (23.7 ms) </strong>than full baseline (<strong>49.7 ms</strong>)in this run.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*SYb7FptGijfqHTHMbONbMA.png" /><figcaption>Quality vs latency scatter plot</figcaption></figure><h3>4) Discussion: What Worked (and What Didn’t)</h3><h4>Why dual-axis pooling struggled</h4><p>Pooling is aggressive averaging. It can remove token-level differences that MaxSim depends on, especially for visually nuanced document patches.</p><p>The overlap result (~0.996 Jaccard) is the key clue: row and column branches did not produce complementary candidates. So dual-axis was mostly “same candidates twice,” plus extra overhead.</p><h4>Why clustering worked</h4><p>Clustering keeps representative token centroids instead of flattening everything by axis. That preserved more semantic diversity while reducing vector count sharply.</p><p>A practical way to read it:</p><ul><li>original: ~1,030 vectors/page</li><li>clustered_64x: 64 vectors/page</li><li>compression ratio: ~16x</li><li>quality: near-baseline (or slightly better in this setup)</li><li>Storage and memory implications</li></ul><p>This project did not include absolute RAM/disk deltas per method, but vector-count compression gives a strong proxy:</p><ul><li>fewer vectors per page means smaller multivector payloads,</li><li>smaller payloads reduce index/storage pressure and improve query-time efficiency.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e88e45f8725" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>