Voyage Code 4 vs Codestral Embed for Code
Voyage Code 4 vs Codestral Embed for code search and repository RAG: context windows, chunking, the parameters that reach each model, and a recall test to run.
By OceanToken Team

Editor's note: Code search is where a general text embedding model most often looks fine in a demo and then misses the function you actually needed. Our position is that a repository deserves a model built for code, chunked the way code is written. We have not benchmarked these models, so this piece gives you the facts that shape the decision and a small recall test, not a winner.
Short answer: In the Voyage Code 4 vs Codestral Embed choice, the deciding fact is context: voyageai/voyage-code-4 takes 32K tokens, mistralai/codestral-embed-2505 takes 8,192. Both are built for code. Pick Voyage Code 4 when you embed whole files, Codestral Embed when you chunk by function, and measure recall on your own repository before you commit.
On OceanToken, both models, plus the general-purpose qwen/qwen3-embedding-8b, openai/text-embedding-3-large and thenlper/gte-large, sit behind one key and the same OpenAI-compatible POST /v1/embeddings call, so a five-way comparison on your own code is a loop over model ids rather than five accounts (docs.oceantoken.ai, checked November 29, 2026).
01 · Voyage Code 4 vs Codestral Embed at a glance
Both models are code specialists, and that is the first thing they have in common. Our model page describes Voyage Code 4 as "a code embedding model" from Voyage AI, released August 13, 2026. The Codestral Embed page, quoting Mistral, says it is "specially designed for code", meant for code databases, repositories and coding assistants. Neither page publishes retrieval scores, and we are not going to borrow vendor benchmark numbers, because they are measured on someone else's code.
What separates them on paper is size and age. Voyage Code 4 reads up to 32,000 tokens per input. Codestral Embed 2505 reads up to 8,192, and it is the older model: Mistral's docs label it version 25.05, and our model page lists it as released October 30, 2025. On the OceanToken API they are called the same way and return the same response shape, so the practical differences come down to how you cut your code and how good the vectors are on your languages and naming conventions.
Here are the five models worth considering for a code index, as our docs and model pages list them today:
| Model id | Built for | Context per input | Parameters on OceanToken | Released |
|---|---|---|---|---|
voyageai/voyage-code-4 |
Code retrieval | 32K (32,000 tokens) | model, input, encoding_format |
August 13, 2026 |
mistralai/codestral-embed-2505 |
Code retrieval | 8K (8,192 tokens) | model, input, encoding_format |
October 30, 2025 (our model page) |
qwen/qwen3-embedding-8b |
General text | 41K | model, input, encoding_format |
See model page |
openai/text-embedding-3-large |
General text | 8K | model, input, encoding_format |
See model page |
thenlper/gte-large |
General text, baseline | 1K in the API reference, 512 in the public catalog | model, input, encoding_format |
See model page |
The GTE-Large row has a wrinkle we cannot resolve from the outside: its API reference says 1K tokens, while our public catalog lists 512 input tokens. Plan for 512. A baseline that silently truncates your functions is worse than no baseline, because it makes every other model look better than it is.
Prices for all five are listed per million input tokens on each model page; see the current rate on /voyage-api and on the Voyage Code 4 and Codestral Embed 2505 pages.
02 · Which code search embedding model to start with
A code search embedding model should be chosen by what you will embed, and for a repository the best place to start is a model trained for code: Voyage Code 4 if your chunks are large, Codestral Embed if they are function-sized. General models come second, as a check.
The reason is the gap between how people ask and how code is written. A developer types "where do we retry failed webhook deliveries". The code says def _requeue(evt, attempt), and the word "webhook" may only appear in a module name three directories up. A general text model has seen plenty of code, but it was tuned to match prose to prose. A code model was tuned on exactly this mismatch: natural language on one side, identifiers, signatures and comments on the other. That is the claim both vendors make, and it is the claim your recall test should confirm or reject.
There are cases where a general model is the better first pick:
- Your "code" is mostly documentation. If the index is READMEs, architecture notes and runbooks with code snippets inside, you are doing prose retrieval. A general model with a long window, such as Qwen3 Embedding 8B, fits that well.
- You mix code and tickets in one index. Queries that should hit both a Jira-style description and the commit that fixed it may favor a general model. Test both.
- You already run a general model for docs search. Adding a second model means a second index, because vectors from different models cannot be compared. That is real operational cost, and it is fine to measure whether the code model earns it.
When none of those apply, start with a code model. Between the two, the context window usually settles it, which is the subject of the next section.
03 · Embeddings for code repository RAG: how to chunk
For code repository RAG, chunk along the code's own structure: one function or class per chunk, with the file path and enclosing class name prepended, and fall back to whole files only when the model's window allows it. The window decides how far you can push that.

Character-count chunking is the usual mistake. A 1,500-character window cuts a function in half, so the first half carries the signature and the second half carries the logic, and neither chunk answers the question on its own. Splitting by syntax keeps each unit whole. Tree-sitter or your language's own parser gives you function and class boundaries cheaply, and it costs little extra indexing code.
How big each unit can be depends on the model:
| Chunking strategy | Fits Voyage Code 4 (32K) | Fits Codestral Embed (8,192) | When it helps |
|---|---|---|---|
| One function or method per chunk | Yes | Yes | Most code search; answers point at a precise location |
| One class with its methods | Usually | Large classes overflow | Questions about how a component behaves as a whole |
| One whole file per chunk | Most source files | Short files only | Small files, config, scripts; fewer chunks to manage |
| Path and symbol header on every chunk | Yes | Yes | Always; gives the model the context a function lacks |
| Sliding window with overlap | Rarely needed | Fallback for very long functions | Generated code, long SQL, vendored files |
The header line matters more than people expect. A chunk that starts with # billing/webhooks/retry.py :: class DeliveryQueue :: def _requeue gives the model words a developer might actually type, even when the function body has none of them. It costs a few tokens per chunk, and embeddings are charged per input token, so the overhead is visible but small.
What happens when an input is longer than the model's window is something to check, not assume. Our docs list the context for each model but do not say whether an over-long input is refused or cut. Send one deliberately oversized function to each model and see whether you get an error or a vector. If you get a vector, assume the tail was ignored and split long units before indexing.
Batching is the other habit that pays off immediately. The input field takes a list, and our embeddings guide says one request with a list is faster and simpler than one request per text. The answer has one vector per input, in the same order, under data[].embedding, with the token count in usage.prompt_tokens.
04 · The parameters that actually reach each model
In our docs, all five models list the same three request fields: model, input and encoding_format (float by default, or base64). That short list hides the most important pitfall in this comparison.
Voyage's own API documents an input_type field that takes query or document. According to Voyage's docs, setting it makes their service prepend a fixed instruction to your text before embedding, which is meant to make search vectors better. That field does not appear in our parameter list for voyageai/voyage-code-4. Our API reference is explicit about what happens to a parameter a model's listing does not include: it is dropped, the request runs without it, and a successful response is not proof that every parameter took effect. A parameter may also be named in the x-oceantoken-dropped-params response header.
So code copied from a vendor tutorial that sends input_type: "query" will run, return vectors, and quietly behave differently from the tutorial. The same applies to dimensions. Our embeddings guide says it shortens the vector only on models that offer it, with openai/text-embedding-3-small as the example, and none of the five models here lists it.
Two practical consequences:
- Plan storage for full-size vectors. Print
len(data[0].embedding)for each model on day one and size your vector store from that, instead of assuming you can ask for a shorter vector. - Test the query instruction yourself. Voyage's docs publish the instruction text they prepend for queries and documents. You can prepend the same text to your own inputs and see whether recall moves. Treat this as an experiment, not a recipe: we have not run it, and it may help, hurt or do nothing on your code.
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.oceantoken.ai/v1",
api_key=os.environ["OCEANTOKEN_API_KEY"])
r = client.embeddings.with_raw_response.create(
model="voyageai/voyage-code-4",
input=["def _requeue(evt, attempt): ..."],
extra_body={"input_type": "document"}, # not in the listed parameters
)
print(r.headers.get("x-oceantoken-dropped-params"))
print(len(r.parse().data[0].embedding))
If the header names input_type, you have your answer for this request. If it is empty, the field may still have had no effect, which is why the recall test below compares runs with and without it.
05 · Qwen3 Embedding 8B for code: the general-purpose challenger
Qwen3 Embedding 8B is a reasonable code embedding choice when your chunks are long or mixed with prose, because its 41K window is the largest of the five; it is not marketed as a code specialist, so it belongs in your test as the general-purpose challenger, not as the default.
Its window means you can embed whole modules, long migration files or a class together with its docstring and tests without splitting. For repositories with large generated files, or when you want one index for code and design docs together, that convenience is real. It also has a different publisher and training mix from the two code models, which makes it a useful check: if a general model matches the code models on your queries, the extra index for a code model may not be worth running.
openai/text-embedding-3-large plays the same role with an 8K window, the same size class as Codestral Embed. GTE-Large is the floor. It is small and its window is short, so it is useful mainly to show how much the larger models add on your data. We cover it in more depth in the GTE-Large embedding API guide, and its trade-offs against general models in GTE-Large vs text-embedding-3-small for RAG and GTE-Large vs BGE-M3 for multilingual RAG.
The rule that ties all of this together is in our embeddings guide: use the same model for your documents and for the questions you search with, because vectors from different models cannot be compared. Switching from Codestral Embed to Voyage Code 4 later means re-embedding the whole repository, not just new commits. Budget that re-index when you plan a trial.
06 · Retrieval, then rerank
Embeddings get you candidates, and a reranker puts the best of them first. Our embeddings guide describes the same two steps for search over your own documents. For code, the pattern is to pull the top 30 or 50 chunks by vector similarity, then send them with the question to POST /v1/rerank and keep the top few for the coding assistant's context.
Rerank changes what you need from the embedding model. With a reranker behind it, the embedding model only has to get the right function into the candidate list, which is recall@50, not recall@1. That can make a cheaper or shorter-window model good enough, so measure both stages. Our rerank API guide for RAG shows the request shape and how rerank models are charged.
How to test this on your workload
We have not run these tests for you. The script below builds a small index with each model and reports recall@k on questions you write yourself. Start with fifty real questions from your team, each paired with the chunk that answers it; add more if two models land close together.
import os, numpy as np
from openai import OpenAI
client = OpenAI(base_url="https://api.oceantoken.ai/v1",
api_key=os.environ["OCEANTOKEN_API_KEY"])
MODELS = ["voyageai/voyage-code-4", "mistralai/codestral-embed-2505",
"qwen/qwen3-embedding-8b", "openai/text-embedding-3-large"]
chunks = load_chunks() # list of strings: header + function body
pairs = load_questions() # list of (question, index_of_correct_chunk)
def embed(model, texts, batch=64):
out = []
for i in range(0, len(texts), batch):
r = client.embeddings.create(model=model, input=texts[i:i + batch])
out += [d.embedding for d in r.data]
v = np.array(out, dtype=np.float32)
return v / np.linalg.norm(v, axis=1, keepdims=True)
for model in MODELS:
doc = embed(model, chunks)
qry = embed(model, [q for q, _ in pairs])
ranks = np.argsort(-(qry @ doc.T), axis=1)
for k in (1, 5, 20):
hit = np.mean([gold in ranks[i, :k] for i, (_, gold) in enumerate(pairs)])
print(f"{model:36s} recall@{k}: {hit:.2f}")
Then work through this list:
- Recall on your questions. Run the script and compare recall@1, @5 and @20 across the four models. Write the questions before you look at results.
- Chunking. Repeat with function-level chunks and file-level chunks. Codestral Embed can only take the file run where files fit in 8,192 tokens.
- Header line. Repeat with and without the path and symbol header on each chunk.
- Query instruction. For Voyage Code 4, rerun with Voyage's published query and document instructions prepended to your text, and once with
input_typeinextra_body. Checkx-oceantoken-dropped-params. - Over-long input. Send one input longer than each model's window and record whether you get an error or a vector.
- GTE-Large window. Send a 700-token input to
thenlper/gte-largeand see whether it is accepted, to settle 1K against 512 for your account. - Vector size and storage. Record the vector length per model and estimate your index size.
- Cost per index. Sum
usage.prompt_tokensacross the indexing run and check the charge in the console's Logs. - With rerank. Add a rerank step on the top 50 and see whether the gap between models shrinks.
Our take: For a code repository, start with a code model and chunk by function. Choose Voyage Code 4 if you want whole files or large classes in one vector; choose Codestral Embed if your chunks are function-sized and you want a second code specialist in the test. Keep Qwen3 Embedding 8B in the run as the general-purpose check, and do not send input_type or dimensions expecting them to work.
Running it on OceanToken
The base URL is https://api.oceantoken.ai/v1, the endpoint is POST /v1/embeddings, and the model ids are voyageai/voyage-code-4, mistralai/codestral-embed-2505, qwen/qwen3-embedding-8b, openai/text-embedding-3-large and thenlper/gte-large. What helps for this comparison, from our docs as of November 29, 2026:
- One key for every embedding model. All five models above, and rerank models on
POST /v1/rerank, use the same key and one prepaid balance, so the recall script is a loop over model ids. - OpenAI-compatible.
client.embeddings.create()works with only the base URL and key changed, and switching models is themodelstring. - Same response shape across models. One vector per input in input order, plus
usage.prompt_tokens, whichever model you call. - Dropped parameters are visible. The
x-oceantoken-dropped-paramsheader can name a field that did not apply, which is how you catch a copiedinput_type.
Price: see the current rate on /voyage-api, and per model on Voyage Code 4, Codestral Embed 2505, Qwen3 Embedding 8B, Text Embedding 3 Large and GTE-Large.
FAQ
Is Voyage Code 4 better than Codestral Embed? We have not measured it, and neither model page publishes scores. Voyage Code 4 has the larger window (32K against 8,192) and is newer; run the recall script on your own code to decide.
Can I use different models for code and for queries? No. Our embeddings guide says to use the same model for documents and queries, because vectors from different models cannot be compared.
Does input_type work for Voyage Code 4 through our API? It is not in the model's parameter list, and parameters a model does not list are dropped. Check the x-oceantoken-dropped-params header and compare recall with and without it.
Can I shorten the vectors with dimensions? Not on these five models; none of them lists it. Size your vector store from the length you get back.
How should I chunk code for embeddings? One function or class per chunk, with the file path and symbol names as a header line, and whole files only when the model's window allows.
How are embeddings charged? Per input token, shown in usage.prompt_tokens. See the current rate on each model page.
Sources
- docs.oceantoken.ai: Embeddings and rerank guide (checked 2026-11-29)
- docs.oceantoken.ai: API reference, dropped parameters (checked 2026-11-29)
- docs.oceantoken.ai: Voyage Code 4 API reference (checked 2026-11-29)
- docs.oceantoken.ai: Codestral Embed 2505 API reference (checked 2026-11-29)
- Voyage AI docs: Text embeddings and input_type (checked 2026-11-29)
- Mistral docs: Code embeddings (checked 2026-11-29)
Get your OceanToken API key
- Create an OceanToken account and an API key.
- Copy the snippet below, paste your key, and run it.
- Check the current rate on /voyage-api.
curl https://api.oceantoken.ai/v1/embeddings \
-H "Authorization: Bearer $OCEANTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "voyageai/voyage-code-4", "input": ["def _requeue(evt, attempt): ...", "where do we retry failed webhook deliveries"]}'
More from the blog
HappyHorse 1.1 vs Wan 3.0 Prime by Job
HappyHorse 1.1 vs Wan 3.0 Prime on one video API: durations, aspect ratios, seed, sound, first and last frames and reference limits, and which job goes where.
AI Image Generator Text Rendering Compared
AI image generator text rendering compared across eight models: what each API takes, a five-step test for lettering, and when to add type after generation.
JSON Schema Output on Chinese LLM APIs
JSON schema output on Chinese LLM APIs: which response_format DeepSeek, Qwen, GLM, MiniMax and Kimi accept, the Kimi K3 gotcha, and Python that fails loudly.