Matryoshka hash codes improve scalable document search and retrieval
Matryoshka Hash Representations for Model-Aware Compact Semantic Retrieval
Information RetrievalArtificial IntelligenceMachine Learning
Summary
Finding relevant documents quickly in large collections depends on representing each document as a compact code that computers can search efficiently. The authors introduce Matryoshka Hash Representations, a two-step method that creates these compact codes in a way that works well for different lengths without losing accuracy. Their approach first creates a long code and then adds smaller parts to make shorter, directly searchable prefixes. This lets search systems be flexible in how much memory they use while still finding useful results. Tests show this method outperforms common alternatives, especially when memory is tight.
retrieval-augmented generationdense retrievalquantizationproduct quantizationbinary codessearch indexFAISS FastScanNDCG@10Recall@100semantic retrieval
Authors
Peichun Hua, Yunming Xiao
Abstract
Retrieval-augmented generation (RAG) depends on dense retrieval: each document is stored as a learned vector, and a query is answered by finding its nearest neighbors in that vector space. Keeping one full-precision vector per document is the dominant index cost at corpus scale, so retrieval systems replace each vector with a short code of a few bytes---a step called quantization. Standard quantizers such as product quantization (PQ) pick the code that reconstructs the original vector most closely. A single code is even more useful if it serves several byte budgets at once: when its short prefixes are each directly searchable, a deployment can set its efficiency--quality operating point without re-encoding the corpus. But training all prefixes under one objective makes the early bits a compromise across budgets---short codes improve while the full-width code degrades. Quantization to low-bit representation, such as binary codes, further sharpens the conflict. We introduce Matryoshka Hash Representations (MHR), a two-stage procedure that separates full-width training from prefix organization. MHR first learns a longer binary code, then freezes the model and trains additional zero-initialized residual code adaptors for directly searchable prefixes. Documents are stored at one bit per coordinate, while queries keep continuous logits like PQ to attain sufficient expressivity. We implement the search process with FAISS FastScan. Trained on MS MARCO and zero-shot transferred to seven BEIR datasets, MHR reaches .5561 NDCG@10 and .6535 Recall@100 at 32 bytes, surpassing the best baseline of the same budget. The advantage is more pronounced in lower budgets. The same code also strengthens two common pipelines: shortlisting candidates for full-precision reranking, and pruning a low-storage graph index such as LEANN.