Multimodal RAG with Inkling 2 Mini: Chamfer, MUVERA and One Vector per Item

Inkling 2 Mini retrieves Flickr30k images and then picks the one that fits a caption. One centered mean vector beats exact Chamfer in search and in RAG, and a tuned MUVERA encoding comes within 2 points of Chamfer.

On this page

In the last post, Inkling 2 Mini named the class of CIFAR-10 images with no training. This post uses the same model and the same RTX 3080 Ti (12 GB) for a different job: retrieval-augmented generation (RAG) with images. A RAG system first finds a few items that fit a question, and then gives them to a language model so that it can answer.

The retrieval step usually keeps one vector per item. But a vision-language model makes one vector per token, and an image gives about 48 of them. Late-interaction search (as in ColBERT and ColPali) keeps all of them and compares two sets of vectors with Chamfer similarity. That is more information, but also much more storage and compute. MUVERA turns each set into one long vector, so that a normal inner-product search can approximate Chamfer.

I wanted to know three things:

  1. Does Chamfer over token vectors find better images than one vector per item?
  2. How close does MUVERA get to exact Chamfer, and at what cost?
  3. Does better retrieval give better answers when Inkling 2 Mini reads the retrieved images?

The data and the vectors

I used the 1K test split of Flickr30k: 1,000 photos with 5 captions each, so 5,000 captions in total. Every search in this post is a brute-force inner product in NumPy. With 1,000 images, a full matrix product takes well under a millisecond, so an approximate index such as FAISS or HNSW has nothing to save. This also means that every recall number is exact for its scoring method, with no index error on top.

Inkling 2 Mini is a chat model, not an embedding model, so I had to choose which hidden states to use. Each prompt puts the content (an image or a caption) in one user turn, then asks “Describe the image above in one word:” in a second turn. This trick (PromptEOL) makes the last hidden state sum up the content. From one pass, I keep two things:

  • The multi-vector set is the final hidden state of every content token: every image token, or every caption token. Each vector has 2,304 values.
  • The single vector is the mean of that set. I also kept the last-token vector of the prompt as a second single-vector option.

I resized every image to 320 pixels on the long side. The vision encoder makes one token per 40 × 40 pixel tile, so most images give 48 tokens.

Two histograms. Images have 24 to 64 vectors, mean 49.0, and most have 48. Captions have 3 to 94 vectors, mean 15.4.

The sets have different sizes: 24 to 64 vectors per image, and 3 to 94 per caption (median 14). Chamfer and MUVERA both work with sets of any size, which is the point of them.

Why I did not use llama-server

llama-server can return one vector per token with --embeddings --pooling none, but this did not work for this model. For a prompt with an image, the server returns only the vectors of the last text chunk, so the image token vectors are lost. Also, the embedding endpoint needs the full prompt in one micro-batch, and the CUDA build of b12600 gives garbage for this model when a micro-batch holds 32 or more tokens. That is the same bug as in the last post.

So I wrote a small C++ tool on top of the llama.cpp C API. It loads the model once, decodes each prompt in 16-token micro-batches, and copies the hidden state of every position. On my test prompts, its CUDA output matched a CPU-only build with a median cosine similarity of 0.996 or higher. Embedding all 6,000 items took about 2 hours.

Center the vectors first

The final hidden states of a language model share one large common direction. Without a correction, almost every pair of vectors has a high cosine similarity, and the ranking is mostly noise. So I subtract the mean vector of each modality (one mean for all image vectors and one for all caption vectors) and then scale every vector to unit length. Every method below uses these centered vectors.

The effect is large. For caption-to-image search with the mean vector, Recall@1 goes from 4.4% without centering to 24.8% with centering.

Chamfer similarity

Chamfer similarity compares a query set Q with a document set D. Each query vector finds its best match in the document, and the score is the sum of these best matches:

Chamfer(Q, D) = Σ over q in Q of max over d in D of ⟨q, d⟩

So a caption word such as “hat” can match the image tile with the hat, and “glasses” can match a different tile. The score is not symmetric. Chamfer(Q, D) and Chamfer(D, Q) are usually different numbers.

A photo of a man in glasses and an orange crocheted hat, with an 8 × 8 grid of 64 image tokens. Colored boxes show the tile that each caption word matches best: "pierced" and "ears" match the tile with the ear, "glasses" matches a background tile next to the hat, and "man" matches a background tile at the left. A bar chart at the right shows the best match of every caption token. The bars for "The", "an" and the period are as long as the bars for "man", "orange" and "hat". The Chamfer score is the sum of the bars, 2.29.

This example shows two weak points. First, the word matches are only partly right. “Pierced” and “ears” find the ear, but “glasses” finds a background tile, not the glasses. Second, function words add as much to the score as content words. “The” (0.17), “an” (0.18) and the period (0.17) each add more than “man” (0.12) or “hat” (0.11).

MUVERA

Exact Chamfer is expensive. For each caption, it multiplies about 15 query vectors with all 49,000 image vectors. Storage is also large: about 441 KB per image in float32, against 9 KB for one vector.

MUVERA (Dhulipala et al., 2024) makes one fixed-dimensional encoding (FDE) for each set. The inner product of a query FDE and a document FDE approximates their Chamfer score. Each repetition has four steps:

  1. SimHash: k_sim random hyperplanes cut the space into 2^k_sim buckets.
  2. Aggregate: a query adds up its vectors in each bucket, and a document takes the mean of its vectors in each bucket.
  3. Fill empty buckets: an empty document bucket takes the document vector whose hash is nearest in Hamming distance, so every query vector still finds a partner.
  4. Project: a random ±1 matrix reduces each bucket from 2,304 values to d_proj values.

The FDE puts reps repetitions one after the other, so it has reps × 2^k_sim × d_proj values for any set size.

Three panels with made-up 2-D points. Panel 1: two random lines cut the plane into 4 colored buckets, with query circles and document squares. Panel 2: one summed query point and one mean document point per bucket. Panel 3: an empty document bucket takes the nearest document vector.

There are two ways to use the FDEs:

  • FDE only: rank the images by the FDE inner product and stop.
  • FDE + re-rank: take the best 100 images by FDE, then sort only those 100 by exact Chamfer.

Search results

I ran two directions. Caption to image (text→image) uses all 5,000 captions as queries against 1,000 images. Image to caption (image→text) uses all 1,000 images as queries against 5,000 captions, and a hit is any of the 5 true captions.

Method Text→image R@1 R@5 R@10 Image→text R@1 R@5 R@10
Single vector, last token 0.7% 2.1% 3.5% 3.5% 7.3% 9.3%
Single vector, mean, no centering 4.4% 12.3% 18.8% 0.4% 1.3% 2.4%
Single vector, mean 24.8% 46.6% 55.9% 35.9% 62.6% 73.3%
Exact Chamfer 18.3% 38.7% 48.8% 26.1% 50.1% 62.7%
MUVERA FDE only, default (20,480 values) 3.5% 9.7% 14.9% 6.5% 17.2% 25.0%
MUVERA + re-rank, default 16.4% 30.4% 36.7% 23.7% 42.7% 48.9%
MUVERA FDE only, tuned (5,120 values) 16.4% 35.0% 45.2% 21.3% 46.0% 58.3%
MUVERA + re-rank, tuned 19.8% 42.6% 52.8% 29.9% 57.1% 67.5%

R@k (Recall@k) is the share of queries whose true match is in the first k results. The default MUVERA settings are k_sim = 5, d_proj = 32 and 20 repetitions. The tuned settings are k_sim = 1, d_proj = 64 and 40 repetitions.

These numbers are low next to published Flickr30k results, because Inkling 2 Mini was not trained for retrieval. A contrastive model such as CLIP learns to put an image and its caption close together. Inkling 2 Mini only learned to predict the next token. So compare the rows with each other, not with retrieval papers.

One mean vector beats Chamfer

This result surprised me. The centered mean vector is the best method in every column. For text→image R@1, it gets 24.8% against 18.3% for exact Chamfer. So with these hidden states, the extra detail of the token vectors does not help, and it hurts.

My best guess is the caption side. In Chamfer, every caption token adds its best match to the score, and that includes words such as “a”, “is” and “the”. The Chamfer example above shows this: “The” and “an” add more to the score than “man” and “hat”. A function word can find a tile that it matches well in almost any image, so it adds score that does not depend on the image. The mean vector mixes all tokens first, and the content words then decide. I did not test this guess. A test would be to remove stop words from the query sets, or to weight each query token.

The second reason is training. ColBERT and ColPali train their token vectors for Chamfer scoring. These token vectors were never trained for that, so Chamfer has no reason to work well on them.

What the MUVERA settings do

Six panels of Recall@1 against one MUVERA setting at a time, for text→image (top) and image→text (bottom). More repetitions and a larger d_proj raise both FDE-only and re-rank recall. A larger k_sim lowers it. Exact Chamfer and the single vector are horizontal lines, and the single vector line is the highest.

The default settings from the MUVERA paper did badly here. FDE only got 3.5% text→image R@1, which is about a fifth of Chamfer. The sweep shows why:

  • More buckets hurt. With k_sim = 5 there are 32 buckets, but a caption has only about 15 vectors and an image about 49. Most buckets hold zero or one vector, so a query vector and its best image tile often land in different buckets. FDE-only R@1 falls from 9.2% at k_sim = 1 to 3.5% at k_sim = 5.
  • A larger d_proj helps, because the random projection from 2,304 values loses less. R@1 goes from 0.9% at d_proj = 8 to 6.9% at 64.
  • More repetitions help, because each repetition is an independent estimate and the FDE averages them. R@1 goes from 0.3% with 1 repetition to 6.4% with 40.
  • Filling empty buckets changed FDE-only R@1 by only 0.2 points for text→image and 0.8 points for image→text.

To choose the tuned settings, I did not look at the true labels. I picked the setting whose text→image FDE search most often finds the exact-Chamfer winner in its first 100 results. That setting (k_sim = 1, d_proj = 64, 40 repetitions) has 5,120 values, a quarter of the default length, and it raises FDE-only R@1 from 3.5% to 16.4%.

Line chart of how often the exact-Chamfer top-1 image is in the MUVERA top 1, 10 and 100, against FDE length on a log axis from 1,024 to 40,960 values. All three lines rise from the shortest FDE, are highest at 5,120 to 20,480 values, and fall at 40,960. The top-100 line peaks at 0.77 and the top-1 line stays below 0.14.

A longer FDE is not always better. Each point in this chart is one setting from the sweep, and some long FDEs use many buckets, which work badly here. With the tuned settings, the Chamfer winner is in the FDE top 100 for 77% of captions, against 50% with the default settings. The correlation between FDE scores and Chamfer scores goes from 0.30 to 0.53.

Re-rank can beat the method it approximates

Tuned MUVERA + re-rank gets 19.8% text→image R@1, and exact Chamfer gets 18.3%. In the image→text direction, the difference is larger: 29.9% against 26.1%. But re-ranking sorts the candidates with exact Chamfer, so how can it be better than Chamfer?

The FDE step acts as a filter. In 23% of text→image queries, the Chamfer winner is not in the FDE top 100. The Chamfer winner is a wrong image for 82% of captions, so the filter often removes a wrong winner. So the two-step method is a different scoring method, and on this data, it is a slightly better one. I ran each setting with one random seed (seed 0), so I cannot say how much of the 1.5-point gain is luck of the hyperplanes. I would not expect this gain on a model whose token vectors are trained for Chamfer.

Cost

Two bar charts for the default MUVERA settings. Left: milliseconds per text→image query are 0.09 for the single vector, 11.13 for exact Chamfer, 1.07 for MUVERA FDE only and 5.61 for MUVERA + re-rank. Right: float32 storage per image is 9 KB for the single vector, 441 KB for the multi-vector set and 80 KB for the MUVERA FDE.

The chart shows the default settings. I timed the tuned settings in a second pass:

Method ms per text→image query (default pass) ms per query (tuned pass) Storage per image
Single vector 0.09 0.10 9 KB
Exact Chamfer 11.1 14.7 441 KB
MUVERA FDE only 1.07 2.5 80 KB (default), 20 KB (tuned)
MUVERA + re-rank 5.6 7.0 FDE + 441 KB

I measured these times on one CPU process, with the whole collection in memory, over the same queries one at a time. Exact Chamfer does the same work in both passes, but it took 11.1 ms in one and 14.7 ms in the other. So these times can change by about 30% from run to run, and only the large differences mean something.

The tuned FDE is 4 times shorter, but its query took longer (2.5 ms against 1.07 ms). The time includes the encoding of the query, and the tuned settings project every query vector 40 times to 64 values, against 20 times to 32 values. With 1,000 images, this encoding costs more than the search itself. With only 1,000 images, all of these times are small. Exact Chamfer grows with the total number of image vectors, so at 1 million images it would take more than 10 seconds per query. MUVERA FDE only is one inner-product search, so a normal vector index can make it fast at any size. Re-ranking still needs the full token vectors of the 100 candidates, so a large system must keep the 441 KB per image on disk.

RAG: does better retrieval give better answers?

Retrieval is only half of RAG. For the second half, I gave Inkling 2 Mini the retrieved images and a caption, and I asked it to choose:

Image 1: [image] Image 2: [image] … Which image matches this description: “<caption>“? Answer with the image number only (1 to k), or 0 if no image matches.

I picked 300 of the 5,000 captions at random (seed 0). For each caption, five retrievers gave the top k images, for k = 1, 3 and 5:

  • Random retrieval is the floor.
  • Single vector is the centered mean vector.
  • MUVERA FDE only and MUVERA + re-rank use the tuned settings.
  • Exact Chamfer is the reference for the other two MUVERA rows.

Reasoning effort was none, and the server ran 4 requests at a time with the same -ub 16 workaround as in the last post. I split the score into two parts, so that I can tell a retrieval failure from a reader failure:

  • Hit rate is the share of queries where the true image is among the k retrieved images.
  • Reader accuracy is the share of hits where the model picks the true image.
  • End-to-end accuracy is the share of all queries where the answer is the true image. It is close to hit rate × reader accuracy.

Three panels of bar charts for k = 1, 3 and 5, with one bar per retriever and error bars of one standard error. Left, retrieval: the share of queries with the true image among the k images rises with k, from 0.15 to 0.24 at k = 1 to 0.33 to 0.46 at k = 5, and the single vector is highest. Random retrieval is close to 0. Middle, reader: given that the true image is there, the model picks it 95% to 98% of the time at k = 1 and 87% to 93% at k = 3 and 5. Right, end to end: the single vector is highest at k = 1 and 5, MUVERA + re-rank is highest at k = 3, and MUVERA FDE only is lowest after random.

Retriever k Hit rate Reader accuracy End to end Prompt tokens
Random 1 0.0% n/a 0.0% 114
Single vector 1 23.7% 95.8% 22.7% 114
MUVERA FDE only 1 15.0% 97.8% 14.7% 113
MUVERA + re-rank 1 22.3% 95.5% 21.3% 116
Exact Chamfer 1 20.3% 95.1% 19.3% 116
Random 3 0.3% 1 of 1 0.3% 236
Single vector 3 38.3% 87.0% 33.3% 236
MUVERA FDE only 3 25.7% 88.3% 22.7% 232
MUVERA + re-rank 3 37.7% 92.9% 35.0% 239
Exact Chamfer 3 34.7% 91.3% 31.7% 242
Random 5 0.7% 2 of 2 0.7% 353
Single vector 5 46.3% 89.2% 41.3% 355
MUVERA FDE only 5 32.7% 86.7% 28.3% 348
MUVERA + re-rank 5 42.7% 88.3% 37.7% 359
Exact Chamfer 5 40.7% 87.7% 35.7% 364

Each row has 300 queries, so the standard error of a share near 35% is about 2.8 points. Two rows that differ by less than about 5 points can be in a different order in a new sample of queries.

Retrieval decides the result

The reader is not the weak part. When the true image is among the retrieved images, Inkling 2 Mini picks it 87% to 98% of the time. But the true image is there for at most 46% of the queries. So almost all of the end-to-end loss comes from retrieval, and the end-to-end order of the retrievers follows their hit rate.

That order matches the search results. The single vector is the best retriever at k = 1 and k = 5. MUVERA + re-rank and exact Chamfer come next, and MUVERA FDE only is clearly last, 8 to 13 points below the single vector. At k = 3, MUVERA + re-rank is 1.7 points above the single vector, which is well inside one standard error. MUVERA + re-rank is also 2.0 to 3.3 points above exact Chamfer at every k. That difference is inside the noise too. The search over all 5,000 captions points the same way: there, the tuned re-rank was 1.5 to 4.0 points above Chamfer at R@1, R@5 and R@10. But both results come from one set of random hyperplanes, so I can say that re-ranking a tuned FDE is about as good as exact Chamfer for RAG, but not that it is better in general.

More images help, up to 5

A larger k gives the reader a harder choice. Reader accuracy falls from about 96% at k = 1 to about 88% at k = 5. But the hit rate rises much more, so end-to-end accuracy goes up with k for every retriever. For the single vector, it goes from 22.7% at k = 1 to 41.3% at k = 5.

The cost is prompt length and time. Each image adds about 60 prompt tokens, so a k = 5 prompt has about 355 tokens against 114 for k = 1. With 4 requests at a time on the 3080 Ti, a request took 19 seconds on average at k = 1 and 43 seconds at k = 5. I did not try k above 5, so I cannot say where the extra images stop helping.

What the reader does when the true image is missing

I let the model answer 0 if no image matches. When the true image is missing, it mostly does that. But it still picks an image for 15% of misses with the single vector at k = 1, and for 24% at k = 5. With random images, it picks one for only 2% to 7% of queries. So the closer the retrieved images are to the caption, the more often the reader accepts a wrong one. Flickr30k captions are often general (“A dog runs through the grass.”), so some of these wrong picks probably fit the caption well. I did not check them by eye, so I cannot say how many are real reader errors.

Empty answers

159 of the 4,500 answers (3.5%) were empty, and 49 of those were queries with the true image in the context. These requests took 89 seconds at the median, against 15 to 39 seconds for the others. I think the model used all 512 output tokens on reasoning and had none left for the answer. I did not log the token counts, so I cannot confirm this. An empty answer counts as 0 (“none matches”), so the reader accuracy in the table is a little lower than the model’s real accuracy. Empty answers were more frequent at larger k (26 at k = 1, 56 at k = 3 and 77 at k = 5), so this effect is largest at k = 5.

Reproduce it

The code is in the repo. It needs Windows, an NVIDIA GPU with 12 GB, 32 GB of RAM, and the setup from the Inkling 2 Mini repo.

  1. Install the Python packages with uv sync.
  2. Build llama-inkling-embed from embedtool/ against llama.cpp commit 29b52d398, and put it in bin/ with the DLL files of the llama.cpp b12600 CUDA build.
  3. Download the Flickr30k 1K test split:
$ uv run python scripts/download_flickr.py
  1. Embed all images and captions (about 2 hours), run the search comparison (CPU only), run the RAG experiment (GPU), and make the charts:
$ uv run python scripts/embed_flickr.py
$ uv run python scripts/run_search.py
$ uv run python scripts/run_rag.py
$ uv run python scripts/make_figures.py

Each script continues from its output files if it stops.

What I take from this

  • Center the hidden states before you compare them. For the mean vector, centering raised text→image R@1 from 4.4% to 24.8%.
  • Token vectors from a chat model are not ColBERT vectors. Exact Chamfer over Inkling 2 Mini’s token vectors was 6.5 points below one centered mean vector in search, and 1.6 to 5.6 points below it in end-to-end RAG accuracy, at more than 100 times the query time and 49 times the storage.
  • Do not use the default MUVERA settings for small sets. With about 15 query vectors and 49 document vectors, fewer buckets and more repetitions work much better. The tuned FDE has a quarter of the length of the default and almost 5 times its R@1.
  • Tune MUVERA without labels. The share of exact-Chamfer winners in the FDE top 100 picked a good setting with no ground truth.
  • MUVERA + re-rank was as good as exact Chamfer, and even 1.5 points above it at R@1, at about half the query time. The FDE length does not depend on the set size, so the first step can use any normal vector index.
  • In this RAG setup, retrieval is the bottleneck, not the reader. Inkling 2 Mini picks the true image 87% to 98% of the time when it is there, but the best retriever puts it there for at most 46% of captions.
  • Give the reader more than one image. Going from 1 to 5 images nearly doubled end-to-end accuracy for every retriever, although the reader made more mistakes with 5 images.
Written by Sina Fathi-Kazerooni

I write about reinforcement learning, transformers, multi-agent systems, and the tools I build along the way.