Skip to main content

Voyage-Code-3: Smarter, More Efficient Code Retrieval with Nested Embeddings

Created on January 14|Last edited on January 14
Voyage AI has introduced voyage-code-3, a groundbreaking embedding model designed specifically to optimize code retrieval tasks. The model outperforms leading alternatives like OpenAI-v3-large and CodeSage-large by 13.80% and 16.81%, respectively, on a suite of 32 diverse datasets. Beyond raw accuracy, voyage-code-3 sets itself apart by enabling the use of smaller-dimensional embeddings (2048, 1024, 512, and 256 dimensions) and supporting advanced quantization formats such as int8 and binary. This combination dramatically reduces storage and retrieval costs while maintaining top-tier performance.

Matryoshka Embeddings: Flexible Nested Representations

At the heart of voyage-code-3 is a novel approach called Matryoshka embeddings. This method allows a single embedding to serve multiple dimensional needs. For example, a 2048-dimensional embedding can be truncated into smaller embeddings—such as 1024 or 256 dimensions—without re-embedding the data. This flexibility is achieved through "nested representation learning," where the model prioritizes encoding essential information in the first few dimensions. During training, each subset of dimensions is optimized to act as a standalone representation, ensuring that truncated embeddings still deliver excellent retrieval performance.
This approach is analogous to a Matryoshka doll: the largest "doll" (2048 dimensions) contains all the details, while each smaller doll (1024, 512, or 256 dimensions) is a complete but simpler version, preserving core information. As a result, users can precompute embeddings at the highest dimensionality and later choose shorter versions depending on their storage and computational constraints.

Quantization for Lower Storage Costs

Voyage-code-3 also supports various quantization formats, including float32, int8, and binary representations. Quantization reduces the precision of each number in the embedding vector, significantly lowering storage costs. For example, binary embeddings reduce storage by 32x compared to float32 embeddings, while int8 embeddings achieve a 4x reduction. These lower-precision embeddings are trained with "quantization-aware" techniques to ensure minimal degradation in retrieval quality, making them a practical choice for applications with resource limitations.
The model balances the tradeoff between retrieval quality and storage cost exceptionally well. Tests show that a 1024-dimensional binary embedding from voyage-code-3 achieves nearly the same quality as a 2048-dimensional float32 embedding, making it ideal for large-scale vector search systems that require both efficiency and accuracy.

Code Retrieval Challenges and Innovations

Code retrieval is more complex than general text retrieval due to the need to understand algorithmic reasoning, syntax, and structural nuances such as keywords, control flows, and formatting. Voyage-code-3 was designed to meet these challenges, excelling at subtasks like text-to-code (retrieving code snippets from natural language queries), code-to-code (finding semantically similar code snippets), and docstring-to-code (locating code based on function descriptions).
The model’s success stems from a highly curated training dataset, which combines trillions of tokens from code, text, and mathematical content. This dataset includes carefully constructed positive pairs, such as docstring-code and code-code relationships, across 300+ programming languages. Additional query-code pairs from real-world use cases were incorporated to improve robustness in practical scenarios. By aligning the training data with the complexities of real-world retrieval tasks, voyage-code-3 provides unmatched performance for developers and engineers.

Evaluation Across Diverse Datasets

Voyage-code-3 was rigorously tested on 32 datasets, covering a wide range of code retrieval tasks and challenging scenarios. Existing benchmarks often suffer from issues like noisy labels and overly simplistic examples, making them unsuitable for real-world applications. To address this, voyage-code-3's evaluation suite incorporates high-quality, diverse datasets that better reflect practical use cases. These include text-to-code, code-to-code, and more, along with specialized question-answer datasets repurposed for retrieval tasks.
The results show that voyage-code-3 outperforms other models, including OpenAI-v3-large, OpenAI-v3-small, and CodeSage-large, across every dataset group. The model’s versatility and reliability make it the leading choice for code retrieval applications.

Binary Rescoring for Enhanced Accuracy

Voyage-code-3 introduces an efficient hybrid technique called binary rescoring. In this approach, initial document retrieval is performed using binary embeddings for speed and low storage costs. The top results are then rescored with full-precision embeddings to maximize accuracy. This method boosts retrieval quality by up to 4.25%, making it ideal for systems requiring both speed and precision.

Cost-Performance Tradeoffs

A key strength of voyage-code-3 is its ability to provide flexible tradeoffs between storage cost and performance. By leveraging Matryoshka embeddings and quantization, users can adapt the model to their specific needs, whether they prioritize high retrieval quality or resource efficiency. For instance, a binary 256-dimensional embedding can still outperform many competitors' larger, float32 embeddings, even at a fraction of the storage cost.

Availability

Voyage-code-3 is now available for use, with the first 200 million tokens offered for free. Developers can explore the model through comprehensive documentation provided by Voyage AI. For organizations interested in fine-tuned embedding models or customized solutions, Voyage AI encourages inquiries and collaboration opportunities.
Voyage-code-3 represents a significant leap forward in embedding technology, offering unmatched accuracy, flexibility, and efficiency for code retrieval tasks. Whether you’re building code assistants, search systems, or developer tools, voyage-code-3 provides the tools to revolutionize your workflows.
Tags: ML News
Iterate on AI agents and models faster. Try Weights & Biases today.