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

Introduction to Embeddings

Lesson 1 of 18 Updated November 3, 2026 Developer
On this page
  1. What is an embedding?
  2. Vectors and semantic space
  3. Distance as a measure of similarity
  4. Applications of embeddings
  5. Why Mistral for embeddings?
  6. Key takeaways

Updated November 2, 2026 — Models. Mistral Large 3 (mistral-large-2512) and Mistral Medium 3.5 were deprecated on October 31, 2026, and will be retired on April 30, 2027. Their designated successor, Mistral Large 4 (mistral-large-4), has been in public preview since October 6. The examples in this course use the alias mistral-large-latest, which still points to Mistral Large 3 according to its official specification (verified November 3, 2026). Similarly, mistral-medium-latest points to Mistral Medium 3.5. These aliases will remain valid until April 30, 2027. For new projects, test mistral-large-4, their designated successor.

What is an embedding?

An embedding is a numerical representation of text as a vector in a multidimensional space. Every word, sentence, or document transforms into a list of numbers—a vector—that captures its semantic meaning. The reason for this transformation is simple: computers do not understand raw text; they work with numbers. Embeddings translate human language into a format that algorithms can manipulate, compare, and analyze.

Consider a customer support team archiving ten years of tickets. As long as those tickets remain plain text, the only mechanical operation possible is exact keyword search: searching for “delivery” will never find “shipment.” Once the tickets are encoded as vectors, they become comparable points in space. “My package never arrived” clusters with “order not received” even though they share no common words.

Vectors and semantic space

Imagine a space with many dimensions (1,024 dimensions for mistral-embed, for example). Each text occupies a precise position in this space, and texts with similar meanings end up geometrically close to one another.

# An embedding is simply a list of numbers
embedding_example = [0.0234, -0.1567, 0.0891, 0.0456]  # 1024 values in reality

# Two similar sentences will have close vectors
sentence_1 = "The cat sleeps on the couch"     # -> vector A
sentence_2 = "The feline dozes on the sofa"    # -> vector B (close to A)
sentence_3 = "The stock market crashed yesterday" # -> vector C (far from A and B)

This property is what makes embeddings so powerful: geometric proximity reflects semantic proximity. The model never learned a rule stating that “feline” is a synonym for “cat.” Instead, it learned to place these two words in similar contexts, which is enough to bring vectors A and B closer together while keeping C apart.

1024
Dimensions for mistral-embed (text)
3072
Dimensions for codestral-embed (code)
5
Precision types (dtype)
< 1s
API latency per request

Distance as a measure of similarity

To determine whether two texts are similar, you measure the distance between their vectors. Three metrics dominate the field. Euclidean distance corresponds to the straight line between two points: the shorter the line, the more similar the texts. Cosine similarity measures the angle between two vectors; an angle of 0° (cosine = 1) means the texts are semantically identical. Finally, the dot product is fast to compute, which explains why it is commonly used for ranking.

Cosine similarity became the standard because it ignores vector length. Compare a three-line contract summary to the full forty-page contract. Euclidean distance penalizes the summary even though it covers the exact same topic, whereas the angle between the two vectors remains small.

import numpy as np

def cosine_similarity(vec_a, vec_b):
    """Calculate cosine similarity between two vectors."""
    dot_product = np.dot(vec_a, vec_b)
    norm_a = np.linalg.norm(vec_a)
    norm_b = np.linalg.norm(vec_b)
    return dot_product / (norm_a * norm_b)

# Result between -1 and 1
# 1.0 = identical, 0.0 = unrelated, -1.0 = opposite

Applications of embeddings

Embeddings underpin many modern applications, and it is worth seeing what each one looks like in practice. Semantic search finds documents by meaning rather than exact keywords: an internal procedure database answers “what to do if a customer refuses delivery” even if the procedure is titled “managing returns at the depot.” RAG (Retrieval-Augmented Generation) takes this logic further by injecting retrieved documents into an LLM’s prompt, allowing it to answer based on your data rather than its training memory.

Three other use cases leverage the same geometry. Text classification automatically categorizes documents by observing which known group their vector is closest to—an incoming email lands in “billing” or “technical” without any hand-written rules. Duplicate detection spots near-identical content in a database, preventing you from publishing the same product sheet twice because two teams wrote it. Clustering groups documents by theme without predefined labels, a common method for making sense of a corpus whose structure no one knows. Finally, recommendation systems suggest similar content, exactly like the “related articles” mechanism at the bottom of a page.

Why Mistral for embeddings?

Mistral offers two specialized embedding models. mistral-embed handles natural language and produces 1,024 dimensions; codestral-embed is trained on source code and goes up to 3,072 dimensions. You choose between them based on the nature of your raw material: written documentation on one side, .py or .ts files on the other.

These models are accessible via a simple API with an excellent price-performance ratio. In the following lessons, you will learn how to use them in practice.

Key takeaways

  • An embedding transforms text into a multidimensional numerical vector
  • Geometric proximity between vectors reflects semantic similarity
  • Cosine similarity is the most common metric for comparing embeddings
  • Mistral offers two models: mistral-embed (text) and codestral-embed (code)
  • Embeddings are the foundation of RAG, semantic search, and clustering