# Codestral Embed

The first embedding model designed exclusively for code retrieval, built to power semantic code search, RAG pipelines for coding agents, and duplicate detection across software repositories.

- **Model ID:** `mistral/codestral-embed`
- **Type:** embedding
- **Providers:** mistral
- **Context window:** Not applicable
- **Maximum output tokens:** 0
- **Pricing:** $0.15/1M input tokens
- **Canonical page:** https://vercel.com/ai-gateway/models/codestral-embed

## Supported parameters

Detailed capability metadata has not been reported for this model.

## Example

```ts
import { embed } from 'ai';

const result = await embed({
  model: 'mistral/codestral-embed',
  value: 'Sunny day at the beach',
})
```

## About

Released May 28, 2025, Codestral Embed is Mistral's first embedding model purpose-built for code. Codestral Embed achieves an 85% average score on code retrieval benchmarks, outperforming Voyage Code 3, Cohere Embed v4.0, and OpenAI's large embedding model on evaluations derived from real-world code data.

Codestral Embed supports variable dimensions with ordered relevance. You can truncate to the first n dimensions and still get ranked embeddings. Mistral's benchmarks show retrieval performance even at 256 dimensions with int8 precision, enabling index size reduction without proportional quality loss.

The context window is 0 tokens. For repositories with large files, Mistral recommends chunking at 3,000 characters with 1,000-character overlap. This balances retrieval recall against chunk boundary artifacts.

## What to consider

Codestral Embed supports variable embedding dimensions, letting you tune the size-versus-quality tradeoff to match your vector store's cost and latency constraints.

## When to use

### Best For

- Building RAG pipelines for coding agents that need to retrieve relevant code snippets
- Semantic code search over large repositories where keyword search is insufficient
- Duplicate code detection and similarity analysis across codebases
- Code clustering for analytics, refactoring identification, or repository organization
- Large-scale indexing pipelines where embedding cost is a primary concern

### Consider Alternatives When

- You need to embed general text documentation rather than source code (consider Mistral Embed)
- Your retrieval workload is primarily over natural language descriptions of code rather than code itself
- You require generation capabilities alongside embedding in a single model call

## Best for

- **RAG pipelines for coding agents:** Building pipelines that retrieve relevant code snippets
- **Semantic code search:** Large repositories where keyword search is insufficient
- **Duplicate code detection:** Similarity analysis across codebases using Codestral Embed's 85% average on code retrieval benchmarks
- **Code clustering:** For analytics, refactoring identification, or repository organization
- **Large-scale indexing pipelines:** Workloads where embedding cost is a primary concern at millions of documents

## Consider alternatives

- **General text documentation:** You need to embed prose rather than source code (consider Mistral Embed)
- **Natural language retrieval:** Your workload is primarily over descriptions of code rather than code itself
- **Generation alongside embedding:** You require both capabilities in a single model call

## Frequently asked questions

### What makes Codestral Embed different from a general text embedding model?

Codestral Embed was trained on real-world code data and optimized for code retrieval tasks. These tasks involve matching function signatures, logic patterns, and structural similarities that general text models don't capture well.

### What is the context window for Codestral Embed?

0 tokens. For files larger than this, chunk at 3,000 characters with 1,000-character overlap.

### What embedding dimensions does Codestral Embed support?

Variable dimensions with ordered relevance: you can keep the first n dimensions for a quality-versus-cost tradeoff. Codestral Embed scores well on retrieval at 256 dimensions with int8 precision in published benchmarks.

### What is the pricing for Codestral Embed?

Check the pricing panel on this page for today's numbers. AI Gateway tracks rates across every provider that serves Codestral Embed.

### Can Codestral Embed be used for duplicate code detection?

Yes. Semantic similarity via embeddings is an effective approach for identifying duplicate or near-duplicate code patterns that differ syntactically but are logically equivalent.

### How does Codestral Embed compare to Mistral Embed?

Mistral Embed is a general-purpose text embedding model. Codestral Embed was trained specifically for code and outperforms general models on code retrieval benchmarks. Use Codestral Embed when your corpus is source code; use Mistral Embed for natural language documents.

## Links

- [Model page](https://vercel.com/ai-gateway/models/codestral-embed)
- [AI Gateway documentation](https://vercel.com/docs/ai-gateway)
- [Provider model documentation](https://docs.mistral.ai/capabilities/embeddings/code_embeddings/)
- [Provider pricing](https://mistral.ai/pricing#api-pricing)
