Skip to main content
Lesson 2 of 18 · Embeddings, RAG, and Semantic Search

The mistral-embed Model

Lesson 2 of 18 Updated November 2, 2026 Developer
On this page
  1. Overview of mistral-embed
  2. Setup and Installation
  3. Generating Embeddings
  4. API Response Structure
  5. Complete Example: Encode and Store
  6. Limits and Best Practices
  7. Key Takeaways

Overview of mistral-embed

mistral-embed is Mistral AI’s text embedding model. It transforms any text into a 1024-dimensional vector, regardless of input length—whether a short sentence or an entire paragraph, the output vector always has the same size. This fixed dimensionality isn’t a minor detail: it lets you index both a product title and its full description in the same vector space, then compare them directly without any special processing to reconcile different formats.

This model is optimized for semantic search, classification, and clustering tasks on natural language text (articles, documents, conversations, and more). Use it to index a knowledge base, FAQ, meeting transcripts, or a decade of support tickets.

Setup and Installation

Before calling the API, install the Mistral Python SDK and configure your API key:

# Installation
# pip install mistralai

import os
from mistralai.client import Mistral

# Initialize the client
api_key = os.environ.get("MISTRAL_API_KEY")
client = Mistral(api_key=api_key)

Get your API key from the Mistral console. Store it in an environment variable to keep it out of your code. Reading via os.environ.get isn’t just theoretical hygiene: it prevents your key from ending up in a Git history snapshot the day your project goes public.

Generating Embeddings

The API call is straightforward: pass a list of texts and retrieve the corresponding vectors. Note that even for a single text, the input must be a list—the API always works in batches, which pays off as soon as your corpus grows.

from mistralai.client import Mistral

client = Mistral(api_key=api_key)

# Generate embeddings for one or more texts
response = client.embeddings.create(
    model="mistral-embed",
    inputs=[
        "Embeddings capture semantic meaning.",
        "Mistral AI offers high-performance models.",
        "RAG improves response quality."
    ],
)

# Access the vectors
for i, data in enumerate(response.data):
    print(f"Text {i+1}: vector of {len(data.embedding)} dimensions")
    print(f"  First elements: {data.embedding[:5]}")

Typical output:

Text 1: vector of 1024 dimensions
  First elements: [0.0234, -0.1567, 0.0891, 0.0123, -0.0456]
Text 2: vector of 1024 dimensions
  First elements: [0.0189, -0.1234, 0.0678, 0.0345, -0.0567]
Text 3: vector of 1024 dimensions
  First elements: [0.0312, -0.1456, 0.0789, 0.0234, -0.0345]

API Response Structure

The response contains more than just vectors. It also tells you which model was actually used and how many tokens were consumed—two pieces of information you’ll want to log once encoding runs in production and someone needs to explain the bill. Pay special attention to the index field: it indicates the position of the text in the list you sent, letting you map each vector back to its source document.

response = client.embeddings.create(
    model="mistral-embed",
    inputs=["Example text to encode."],
)

# Response object
print(response.model)          # "mistral-embed"
print(response.usage)          # tokens consumed

# Embedding data
embedding_data = response.data[0]
print(embedding_data.index)     # 0 (position in the inputs list)
print(len(embedding_data.embedding))  # 1024
print(type(embedding_data.embedding))  # list[float]

Complete Example: Encode and Store

Here’s a typical pipeline for encoding a document corpus and preparing vectors for later search. The switch to NumPy is the critical step: while your vectors are Python lists, every similarity calculation happens element by element; once you build a matrix, a single operation compares the query against the entire corpus.

import numpy as np
from mistralai.client import Mistral

client = Mistral(api_key=api_key)

# Document corpus
documents = [
    "Mistral AI is a French artificial intelligence company.",
    "RAG combines information retrieval and text generation.",
    "Embeddings enable semantic search.",
    "Python is the most widely used language in data science.",
    "FAISS is a vector search library by Meta.",
]

# Encode all documents
response = client.embeddings.create(
    model="mistral-embed",
    inputs=documents,
)

# Convert to a NumPy matrix for calculations
embeddings_matrix = np.array([d.embedding for d in response.data])

print(f"Embeddings matrix: {embeddings_matrix.shape}")
# Embeddings matrix: (5, 1024)

# Save for later use
np.save("document_embeddings.npy", embeddings_matrix)

Saving as .npy avoids paying to re-encode every time your application restarts. On a corpus of several thousand documents, this is the difference between instant startup and several minutes of billed API calls.

Limits and Best Practices

Four factors determine the quality of your results. First, the maximum length: the model truncates texts that are too long, and truncation is silent—a forty-page report encoded in one block will effectively represent only its beginning. Prefer chunks of 512 to 2048 tokens, covered in the lesson on chunking.

Second, unlike some other APIs, mistral-embed does not distinguish between query and document: there is no input type, you simply pass the text. In practice, user questions and indexed documents go through the same call with the same parameters, simplifying your search code.

The third point is cost: embeddings are billed per token. Encoding a thousand documents one by one costs the same in tokens as encoding them in a batch, but it multiplies network round trips and processing time; you optimize by batching calls, which is the subject of the next lesson on batching. Finally, determinism works in your favor: for the same text, the model always returns the same vector. You can therefore cache embeddings by text hash and re-encode only what has actually changed between two versions of a document.

Key Takeaways

  • mistral-embed produces 1024-dimensional vectors for any text
  • The API accepts a list of inputs and returns the corresponding vectors
  • Vectors are lists of floats, easily convertible to NumPy arrays
  • Store your embeddings as a NumPy matrix for similarity calculations
  • Remember to split long texts before encoding