Compact binary codes improve document search efficiency and accuracy
Matryoshka Hash Representations for Model-Aware Compact Semantic Retrieval
Information RetrievalArtificial IntelligenceMachine Learning
Summary
Searching large collections of documents can be slow and costly when storing detailed information about each document. The authors introduce a new method called Matryoshka Hash Representations that stores document data in compact binary codes which can be searched quickly without losing much accuracy. This method first learns a longer binary code, then creates shorter subsections of that code that can be searched efficiently. Their approach works better than current techniques, especially when very little storage space is available.
What this means in practice
- •For search infrastructure engineers: Store document representations as compact binary codes enabling faster and more flexible search with adjustable speed-quality trade-offs without re-encoding the dataset.
- •For content recommendation teams: Improve candidate retrieval efficiency and accuracy in multi-step recommendation pipelines by integrating compact codes as a lightweight pre-filtering stage.
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.