> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/using-the-api/embeddings.md).

# Embeddings

Generate vector embeddings for semantic search, similarity matching, and RAG applications.

The embeddings API generates vector representations of text. Use embeddings for semantic search, document similarity, clustering, and Retrieval-Augmented Generation (RAG).

## What Are Embeddings

Embeddings convert text into numerical vectors that capture semantic meaning. Similar texts produce similar vectors, enabling:

* **Semantic search** - Find content by meaning, beyond keyword matching
* **Document similarity** - Compare how related two pieces of content are
* **Clustering** - Group similar content together
* **RAG** - Retrieve relevant context for AI responses

## IAIEmbeddingService

The primary interface for embedding operations:

{% code title="IAIEmbeddingService.cs" %}

```csharp
public interface IAIEmbeddingService
{
    // Single embedding
    Task<Embedding<float>> GenerateEmbeddingAsync(
        Action<AIEmbeddingBuilder> configure,
        string value,
        CancellationToken cancellationToken = default);

    // Multiple embeddings
    Task<GeneratedEmbeddings<Embedding<float>>> GenerateEmbeddingsAsync(
        Action<AIEmbeddingBuilder> configure,
        IEnumerable<string> values,
        CancellationToken cancellationToken = default);

    // Advanced: Get a configured generator
    Task<IEmbeddingGenerator<string, Embedding<float>>> CreateEmbeddingGeneratorAsync(
        Action<AIEmbeddingBuilder> configure,
        CancellationToken cancellationToken = default);
}
```

{% endcode %}

## Basic Usage

{% code title="SearchService.cs" %}

```csharp
using Microsoft.Extensions.AI;
using Umbraco.AI.Core.Embeddings;

public class SearchService
{
    private readonly IAIEmbeddingService _embeddingService;

    public SearchService(IAIEmbeddingService embeddingService)
    {
        _embeddingService = embeddingService;
    }

    public async Task<float[]> GetEmbedding(string text)
    {
        var embedding = await _embeddingService.GenerateEmbeddingAsync(
            emb => emb.WithAlias("content-search"),
            text);
        return embedding.Vector.ToArray();
    }
}
```

{% endcode %}

## Choosing a Profile

### Default Profile

Once you have [configured a default embedding profile](/ai-in-umbraco/backoffice/managing-settings.md) in the backoffice, you can call without specifying a profile on the builder:

```csharp
var embedding = await _embeddingService.GenerateEmbeddingAsync(
    emb => emb.WithAlias("content-search"),
    text);
```

### Specific Profile

Select a profile by ID or alias on the builder:

```csharp
var embedding = await _embeddingService.GenerateEmbeddingAsync(
    emb => emb
        .WithAlias("content-search")
        .WithProfile(profileId),
    text);
```

## Common Use Cases

### Semantic Search

1. Generate embeddings for all searchable content
2. Store embeddings in a vector database
3. When searching, embed the query and find nearest neighbors

### Content Similarity

Compare two pieces of content:

```csharp
var embedding1 = await _embeddingService.GenerateEmbeddingAsync(
    emb => emb.WithAlias("content-similarity"),
    content1);
var embedding2 = await _embeddingService.GenerateEmbeddingAsync(
    emb => emb.WithAlias("content-similarity"),
    content2);

var similarity = CosineSimilarity(embedding1.Vector, embedding2.Vector);
```

### RAG (Retrieval-Augmented Generation)

1. Embed user question
2. Find relevant content via vector search
3. Include retrieved content in chat prompt

## In This Section

{% content-ref url="/pages/0C4RH6nNPlZv9XQEF6gy" %}
[Generating Embeddings](/ai-in-umbraco/using-the-api/embeddings/generating-embeddings.md)
{% endcontent-ref %}

{% content-ref url="/pages/A0Z9CPVOkiNJfTqwGEKq" %}
[Batch Embeddings](/ai-in-umbraco/using-the-api/embeddings/batch-embeddings.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.umbraco.com/ai-in-umbraco/using-the-api/embeddings.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
