Pixels-To-Points / index.html
Alii-21's picture
Point links to the renamed GitHub repo
b11488c verified
Raw History Blame Contribute Delete
12.7 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>From Pixels to Points</title>
<meta name="description" content="How many vectors does a document page really need? Compressing ColPali-style visual document search.">
<style>
:root {
--bg: #ffffff; --text: #1f2328; --muted: #57606a; --line: #d0d7de;
--soft: #f6f8fa; --accent: #6d28d9; --accent-soft: #f3e8ff;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0d1117; --text: #e6edf3; --muted: #9da7b3; --line: #30363d;
--soft: #161b22; --accent: #c4a5ff; --accent-soft: #241a3a;
}
}
* { box-sizing: border-box; }
body {
margin: 0; background: var(--bg); color: var(--text);
font: 17px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
main { max-width: 760px; margin: 0 auto; padding: 48px 16px 80px; }
h1 { font-size: 2.6rem; line-height: 1.15; margin: 0 0 6px; letter-spacing: -0.02em; }
.subtitle { font-size: 1.3rem; color: var(--muted); margin: 0 0 20px; }
.hook { font-size: 1.1rem; }
h2 { font-size: 1.55rem; margin: 52px 0 12px; padding-top: 8px; border-top: 1px solid var(--line); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
figure { margin: 26px 0; }
figure img { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
figcaption { color: var(--muted); font-size: 0.9rem; text-align: center; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 0.95rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--soft); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.tldr { background: var(--accent-soft); border-radius: 12px; padding: 18px 22px; margin: 18px 0; }
.tldr ul { margin: 0; padding-left: 20px; }
.tldr li { margin: 8px 0; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin: 14px 0; }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.meta { color: var(--muted); font-size: 0.9rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
pre { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
footer { margin-top: 60px; color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--line); padding-top: 18px; }
@media (max-width: 520px) { h1 { font-size: 2rem; } body { font-size: 16px; } }
</style>
</head>
<body>
<main>
<h1>From Pixels to Points</h1>
<p class="subtitle">Compressing Visual Document Search</p>
<p class="hook">Some AI models search documents by looking at the pages, like we do. They need hundreds of vectors per page. <strong>How many does a page really need?</strong></p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/pareto.png" alt="Quality kept vs memory per page">
<figcaption>Quality kept vs memory per page, for every method.</figcaption>
</figure>
<p class="meta">Code, results and full details: <a href="https://github.com/ALI-AL-MARJANI/Pixels-To-Points">github.com/ALI-AL-MARJANI/Pixels-To-Points</a></p>
<h2>Built on</h2>
<div class="card">
<h3><a href="https://arxiv.org/abs/2407.01449">ColPali</a></h3>
<div>Searches page images with one vector per patch. The models compressed here.</div>
</div>
<div class="card">
<h3><a href="https://arxiv.org/abs/2409.14683">Token Pooling</a> <span class="meta">(Clavié et al.)</span></h3>
<div>Merges similar vectors of a page. The main compression method.</div>
</div>
<div class="card">
<h3><a href="https://arxiv.org/abs/2405.19504">MUVERA</a> <span class="meta">(Dhulipala et al.)</span></h3>
<div>Turns many vectors into one. Used as a fast first step.</div>
</div>
<div class="card">
<h3><a href="https://arxiv.org/abs/2601.08620">ViDoRe benchmark</a></h3>
<div>The visual document retrieval benchmark used for every test.</div>
</div>
<h2>TL;DR</h2>
<div class="tldr">
<ul>
<li><strong>Merging similar vectors is almost free.</strong> 4× fewer vectors keeps 99% of the quality. 16× fewer keeps 96%. Dropping vectors at random keeps only 87%.</li>
<li><strong>One bit per number is enough to find the right pages.</strong> With 4× merging plus 1 bit, a million pages go from 194 GB to 3 GB and keep 93% of the quality.</li>
<li><strong>A single vector per page is not enough on its own</strong> (60 to 82%). As a first filter, followed by an exact check of the top 100, it keeps 98.5 to 100%.</li>
</ul>
</div>
<h2>The problem</h2>
<p>A company has millions of PDF pages. Someone asks: <em>"How much did we spend on stock buybacks in 2024?"</em> The answer is one number, in one table, on one page.</p>
<p>The old way is to turn the pages into text (OCR) and search the text. It often breaks on tables, charts and scans. Models like ColPali skip that step: they look at the page image directly.</p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/architecture.png" alt="How ColPali-style models search a page">
<figcaption>How ColPali-style models search a page.</figcaption>
</figure>
<p>The catch: a page becomes hundreds of vectors, not one. With ColQwen2, that is 757 vectors of 128 numbers per page, so <strong>1 million pages take 194 GB of fast memory</strong>. The smaller model, ColSmol, is even worse (264 GB), because it cuts pages into more pieces.</p>
<p>So the question is simple: how few vectors, and how few bits, does a page really need?</p>
<h2>Four ways to make it smaller</h2>
<p><strong>Token pooling</strong> (<a href="https://arxiv.org/abs/2409.14683">Clavié et al.</a>). Group similar vectors and keep their average. To check that the grouping matters, it is compared with a dumb baseline: throw away the same number of vectors at random.</p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/pooling_clusters.png" alt="Which patches get merged on a real page">
<figcaption>Which patches get merged on a real page.</figcaption>
</figure>
<p><strong>Binarization.</strong> Keep only the sign of each number: 1 bit instead of 16. Each vector becomes 16× smaller.</p>
<p><strong>MUVERA</strong> (<a href="https://arxiv.org/abs/2405.19504">Dhulipala et al.</a>). Build one long vector per page that behaves almost like the full set. Any normal vector database can search it. Then the best 100 pages are checked again with the full vectors.</p>
<p><strong>Mix them.</strong> Fewer vectors and fewer bits per vector work together.</p>
<h2>Results</h2>
<p>Two models (<a href="https://huggingface.co/vidore/colqwen2-v1.0">ColQwen2-2B</a> and <a href="https://huggingface.co/vidore/colSmol-256M">ColSmol-256M</a>), four kinds of pages (finance reports, slides, economic reports, science figures) from the ViDoRe benchmark. "Quality kept" compares the ranking score (nDCG@5) with the uncompressed version.</p>
<div class="table-wrap">
<table>
<thead><tr><th>Method</th><th class="num">1M pages (ColQwen2)</th><th class="num">Quality kept, ColQwen2</th><th class="num">Quality kept, ColSmol</th></tr></thead>
<tbody>
<tr><td>Full</td><td class="num">194 GB</td><td class="num">100%</td><td class="num">100%</td></tr>
<tr><td>Pooling 4×</td><td class="num">49 GB</td><td class="num">99.2%</td><td class="num">98.5%</td></tr>
<tr><td>Pooling 16×</td><td class="num">12 GB</td><td class="num">95.7%</td><td class="num">93.3%</td></tr>
<tr><td>Random dropping 16×</td><td class="num">12 GB</td><td class="num">86.9%</td><td class="num">74.4%</td></tr>
<tr><td>1 bit per number</td><td class="num">12 GB</td><td class="num">95.9%</td><td class="num">93.5%</td></tr>
<tr><td>Pooling 4× + 1 bit</td><td class="num">3 GB</td><td class="num">93.3%</td><td class="num">90.9%</td></tr>
<tr><td>MUVERA, one vector</td><td class="num">1 to 20 GB</td><td class="num">60 to 82%</td><td class="num">35 to 63%</td></tr>
<tr><td>MUVERA, then exact check of top 100</td><td class="num"></td><td class="num">98.5 to 100%</td><td class="num">95.8 to 99.4%</td></tr>
</tbody>
</table>
</div>
<p class="meta">Every number comes from <code>results/</code> in the GitHub repo. The full table is in <code>results/table.md</code>.</p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/pool_vs_random.png" alt="Pooling vs random dropping">
<figcaption>Smart merging vs random dropping.</figcaption>
</figure>
<p>Two things stand out. <strong>Smart merging beats random dropping by a wide margin</strong>, so which vectors get merged really matters. And <strong>the bigger model handles compression better</strong> at every setting.</p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/two_step.png" alt="Two-step search">
<figcaption>One vector as a fast first filter, then an exact check of the top 100.</figcaption>
</figure>
<h2>Where it hurts</h2>
<p>The type of page that suffers most depends on the model. ColQwen2 loses most on dense finance pages (92% kept at 16×). ColSmol loses most on slides (88%). Science figures are the safest for both.</p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/by_page_type.png" alt="Quality kept per page type">
<figcaption>Quality kept per page type.</figcaption>
</figure>
<p>Below, each query word picks its best patch, and that patch lights up. With the full vectors, a few exact spots win. After heavy merging, a "winner" is the average of a whole group of patches, so the signal gets spread out and the wrong pages start to win.</p>
<figure>
<img src="https://raw.githubusercontent.com/ALI-AL-MARJANI/Pixels-To-Points/main/assets/heatmaps_worst_cases.png" alt="What the model looks at, before and after pooling">
<figcaption>What the model looks at, before and after pooling.</figcaption>
</figure>
<h2>Surprises</h2>
<ul>
<li><strong>A tiny bug cost 5 points.</strong> When you average vectors, you must rescale the result back to length 1. My first version skipped this, and quality dropped from 0.514 to 0.464.</li>
<li><strong>White space is not merged first.</strong> Blank patches end up in groups almost as small as text patches (10.5 vs 9.7 patches). The model mixes information from the whole page into every patch.</li>
<li><strong>1 bit is smaller, but not faster here.</strong> In plain NumPy, bit tricks were slower than normal math (178 ms vs 7 ms per query). Real speed needs special low-level code.</li>
<li><strong>The small model needs the biggest index.</strong> ColSmol makes 1,030 vectors per page, ColQwen2 only 757.</li>
</ul>
<h2>How it was tested</h2>
<ul>
<li><strong>Models:</strong> <a href="https://huggingface.co/vidore/colqwen2-v1.0">ColQwen2</a> and <a href="https://huggingface.co/vidore/colSmol-256M">ColSmol</a>. Pages encoded once on a laptop GPU (Apple M4), everything else on CPU.</li>
<li><strong>Data:</strong> 1,402 pages and 339 English questions from <a href="https://huggingface.co/datasets/vidore/vidore_v3_finance_en">finance</a>, <a href="https://huggingface.co/datasets/vidore/biomedical_lectures_v2">slides</a>, <a href="https://huggingface.co/datasets/vidore/economics_reports_v2">economics</a> and <a href="https://huggingface.co/datasets/vidore/arxivqa_test_subsampled">arXiv</a>. Three sets are fixed random subsets, to keep encoding time reasonable.</li>
<li><strong>Sanity check:</strong> on the full economics set, the uncompressed scores match the <a href="https://huggingface.co/blog/manu/vidore-v2">published ones</a> (ColQwen2 0.616 vs 0.615, ColSmol 0.526 vs 0.534).</li>
<li>All methods (scoring, pooling, binarization, MUVERA, metrics) are written from scratch in NumPy and checked against reference code.</li>
</ul>
<h2>Run it</h2>
<pre><code>git clone https://github.com/ALI-AL-MARJANI/Pixels-To-Points
cd Pixels-To-Points
uv sync --extra encode --extra dev
uv run pytest
uv run python -m p2p.encode --model colqwen2 --dataset economics_v2
uv run python -m p2p.run_experiments
uv run python -m p2p.plots</code></pre>
<footer>
Ali Al Marjani · <a href="https://github.com/ALI-AL-MARJANI/Pixels-To-Points">Code on GitHub</a> · <a href="https://github.com/ALI-AL-MARJANI">GitHub profile</a>
</footer>
</main>
</body>
</html>