---
title: "Generating Embeddings - Overview"
description: "Generate vector embeddings from your RavenDB documents using AI providers, stored as attachments for semantic similarity search."
url: "https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/overview"
version: "7.2"
language: "nodejs"
---

# Generating Embeddings - Overview

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/overview.md), [Python](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/overview.python.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - RavenDB can serve as a vector database, see [Why choose RavenDB as your vector database](https://docs.ravendb.net/7.2/ai-integration/vector-search/overview.md#why-choose-ravendb-as-your-vector-database).
>
> - Vector search can be performed on:
>   - Raw text stored in your documents.
>   - Pre-made embeddings that you created yourself and stored using these [Data types](https://docs.ravendb.net/7.2/ai-integration/vector-search/data-types-for-vector-search.nodejs.md#numerical-data).
>   - Pre-made embeddings that are automatically generated from your document content by RavenDB's  
>     **embeddings generation tasks** using external service providers, as explained below.
>
> - In this article:
>   - [Embeddings generation - overview](#embeddings-generation-overview)
>     - [Embeddings generation - process flow](#embeddings-generation---process-flow)
>     - [Supported providers](#supported-providers)
>   - [Creating an embeddings generation task](#creating-an-embeddings-generation-task)
>   - [Monitoring the tasks](#monitoring-the-tasks)
>   - [Get embeddings generation task details](#get-embeddings-generation-task-details)

## Embeddings generation - overview {#embeddings-generation-overview}

### Embeddings generation - process flow

- **Define an Embeddings Generation Task**:  
  Specify a [connection string](https://docs.ravendb.net/7.2/ai-integration/connection-strings/overview.md) that defines the AI provider and model for generating embeddings.  
  Define the source content - what parts of the documents will be used to create the embeddings.

- **Source content is processed**:
  1. The task extracts the specified content from the documents.
  2. If a processing script is defined, it transforms the content before further processing.
  3. The text is split according to the defined chunking method; a separate embedding will be created for each chunk.
  4. Before contacting the provider, RavenDB checks the [embeddings cache](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embedding-collections.md#the-embeddings-cache-collection)
     to determine whether an embedding already exists for the given content from that provider.
  5. If a matching embedding is found, it is reused, avoiding unnecessary requests.  
     If no cached embedding is found, the transformed and chunked content is sent to the configured AI provider.

- **Embeddings are generated by the AI provider**:  
  The provider generates embeddings and sends them back to RavenDB.  
  If quantization was defined in the task, RavenDB applies it to the embeddings before storing them.

- **Embeddings are stored in your database**:
  - Each embedding is stored as an attachment in a [dedicated collection](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embedding-collections.md#the-embeddings-collection).
  - RavenDB maintains an [embeddings cache](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embedding-collections.md#the-embeddings-cache-collection),
    allowing reuse of embeddings for the same source content and reducing provider calls.
    Cached embeddings expire after a configurable duration.

- **Perform vector search:**  
  Once the embeddings are stored, you can perform vector searches on your document content by:
  - Running a [dynamic query](https://docs.ravendb.net/7.2/ai-integration/vector-search/vector-search-using-dynamic-query.nodejs.md#querying-pre-made-embeddings-generated-by-tasks), which automatically creates an auto-index for the search.
  - Defining a [static index](https://docs.ravendb.net/7.2/ai-integration/vector-search/vector-search-using-static-index.nodejs.md#indexing-pre-made-text-embeddings) to store and query embeddings efficiently.

    The query search term is split into chunks, and each chunk is looked up in the cache.  
    If not found, RavenDB requests an embedding from the provider and caches it.  
    The embedding (cached or newly created) is then used to compare against stored vectors.

- **Continuous processing**:
  - Embeddings generation tasks are [Ongoing Tasks](https://docs.ravendb.net/7.2/studio/database/tasks/ongoing-tasks/general-info.md) that process documents as they change.  
    Before contacting the provider after a document change, the task first checks the cache to see if a matching embedding already exists, avoiding unnecessary requests.
  - The requests to generate embeddings from the source text are sent to the provider in batches.  
    The batch size is configurable, see the [Ai.Embeddings.MaxBatchSize](https://docs.ravendb.net/7.2/server/configuration/ai-integration-configuration.md#aiembeddingsmaxbatchsize) configuration key.
  - A failed embeddings generation task will retry after the duration set in the  
    [Ai.Embeddings.MaxFallbackTimeInSec](https://docs.ravendb.net/7.2/server/configuration/ai-integration-configuration.md#aiembeddingsmaxfallbacktimeinsec) configuration key.

---

![flow chart](https://docs.ravendb.net/assets/images/embeddings-generation-task-flow-769ce3678c4545cc970c236dc355156e.png)

![flow chart](https://docs.ravendb.net/assets/images/vector-search-flow-fd83c999d67382ad3ab6d9c667802246.png)

### Supported providers

- The following service providers are supported for auto-generating embeddings using tasks:

  - [OpenAI & OpenAI-compatible providers](https://docs.ravendb.net/7.2/ai-integration/connection-strings/open-ai.nodejs.md)
  - [Azure Open AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/azure-open-ai.nodejs.md)
  - [Google AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/google-ai.nodejs.md)
  - [Vertex AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/vertex-ai.nodejs.md)
  - [Hugging Face](https://docs.ravendb.net/7.2/ai-integration/connection-strings/hugging-face.nodejs.md)
  - [Ollama](https://docs.ravendb.net/7.2/ai-integration/connection-strings/ollama.nodejs.md)
  - [Mistral AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/mistral-ai.nodejs.md)
  - [bge-micro-v2](https://docs.ravendb.net/7.2/ai-integration/connection-strings/embedded.nodejs.md) (a local embedded model within RavenDB)

## Creating an embeddings generation task {#creating-an-embeddings-generation-task}

- An embeddings generation tasks can be created from:
  - The **AI Tasks view in the Studio**, where you can create, edit, and delete tasks. Learn more in [AI Tasks - list view](https://docs.ravendb.net/7.2/ai-integration/ai-tasks-list-view.md).
  - The **Client API** - see [Configuring an embeddings generation task - from the Client API](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embeddings-generation-task.nodejs.md#configuring-an-embeddings-generation-task---from-the-client-api)

- From the Studio:

  ![Add ai task 1](https://docs.ravendb.net/assets/images/add-ai-task-1-c2033528dcf72906e17cc235acf34d03.png)

  1. Go to the **AI Hub** menu.
  2. Open the **AI Tasks** view.
  3. Click **Add AI Task** to add a new task.

  ![Add ai task 2](https://docs.ravendb.net/assets/images/add-ai-task-2-c0459ee0c64af442bb5c259ef8328a41.png)

- See the complete details of the task configuration in the [Embeddings generation task](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embeddings-generation-task.nodejs.md) article.

## Monitoring the tasks {#monitoring-the-tasks}

- The status and state of each embeddings generation task are visible in the [AI Tasks - list view](https://docs.ravendb.net/7.2/ai-integration/ai-tasks-list-view.md).

- Task performance and activity over time can be analyzed in the *AI Task Stats* view,  
  where you can track processing duration, batch sizes, and overall progress.  
  Learn more about the functionality of the stats view in the [Ongoing Task Stats](https://docs.ravendb.net/7.2/monitoring/performance-views/ongoing-task-stats.md) article.

- The number of embeddings generation tasks across all databases can also be monitored using [SNMP](https://docs.ravendb.net/7.2/monitoring/integrations/snmp/overview.md).  
  The following SNMP OIDs provide relevant metrics:
  - [5.1.11.25](https://docs.ravendb.net/7.2/monitoring/integrations/snmp/overview.md#value-5.1.11.25) – Total number of enabled embeddings generation tasks.
  - [5.1.11.26](https://docs.ravendb.net/7.2/monitoring/integrations/snmp/overview.md#value-5.1.11.26) – Total number of active embeddings generation tasks.

- Errors raised by embeddings generation tasks, and how those errors affect each task's
  health, are tracked in the [Task Errors view](https://docs.ravendb.net/7.2/monitoring/task-errors/studio-views.md#task-errors-view).  
  The [AI Task Errors view](https://docs.ravendb.net/7.2/monitoring/task-errors/studio-views.md#ai-task-errors-view),
  opened from the `AI Hub`, shows the same errors pre-filtered to AI tasks only.  
  For an introduction to task error monitoring, see the
  [Task errors overview](https://docs.ravendb.net/7.2/monitoring/task-errors/overview.md).

## Get embeddings generation task details {#get-embeddings-generation-task-details}

- Besides viewing the list of tasks in the [AI Tasks - list view](https://docs.ravendb.net/7.2/ai-integration/ai-tasks-list-view.md) in the Studio,  
  you can also retrieve embeddings generation task details programmatically.

- This is useful when issuing a vector search query that references an embeddings generation task,  
  where it's important to verify that the task exists beforehand. For example:
  - when [Querying pre-made embeddings generated by tasks](https://docs.ravendb.net/7.2/ai-integration/vector-search/vector-search-using-dynamic-query.nodejs.md#querying-pre-made-embeddings-generated-by-tasks)
  - or when [Indexing numerical data and querying using text input](https://docs.ravendb.net/7.2/ai-integration/vector-search/vector-search-using-static-index.nodejs.md#indexing-numerical-data-and-querying-using-text-input)

- There are two ways to check if an embeddings generation task exists:
  - Using `GetOngoingTaskInfoOperation`.
  - Accessing the full list of embeddings generation tasks from the database record.

### Get\_task\_info\_via\_operataion

```javascript
try {
    // Define the get task operation, pass the task NAME
    const getOngoingTaskOp = new GetOngoingTaskInfoOperation(
        "theEmbeddingsGenerationTaskName", // task name
        "EmbeddingsGeneration"             // task type
    );
        
    // Execute the operation by passing it to maintenance.send
    const task = await documentStore.maintenance.send(getOngoingTaskOp);
        
    // Access any of the task details
    const taskStatus = task.taskState;
    
    // Access the task identifier
    const taskIdentifier = task.configuration.identifier;
} 
catch (error) {
    // Task does not exist or failed to load - ignore or log
    // console.log("Ongoing task not found", error);
}
```

### Get\_task\_info\_via\_database\_record

```javascript
try {    
    // Define the get database record operation, pass your database name
    const getDatabaseRecordOp = new GetDatabaseRecordOperation("yourDatabaseName");
      
    // Execute the operation by passing it to maintenance.send
    const dbRecord = await documentStore.maintenance.server.send(getDatabaseRecordOp) 
      
    // Access the list of embeddings generation tasks
    const tasks = dbRecord?.embeddingsGenerations;
        
    if (!tasks || tasks.length === 0) {
        return;
    }

    // Access the first task
    const task = tasks[0];
      
    // Access any of the task details
    const isTaskDisabled = task.disabled;
      
    // Access the task identifier
    const taskIdentifier = task.identifier;
}
catch (error) {
    // Database does not exist or cannot be accessed - ignore or log
    // console.log("Failed to load database record", error);
}   
```

## See also

- [Vector search overview](https://docs.ravendb.net/7.2/ai-integration/vector-search/overview.md)
- [Vector search using a static index](https://docs.ravendb.net/7.2/ai-integration/vector-search/vector-search-using-static-index.nodejs.md)
- [Vector search using a dynamic query](https://docs.ravendb.net/7.2/ai-integration/vector-search/vector-search-using-dynamic-query.nodejs.md)
- [The Embedding Collections](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embedding-collections.md)
- [The Embedding generation task](https://docs.ravendb.net/7.2/ai-integration/generating-embeddings/embeddings-generation-task.nodejs.md)
- [Connection strings - overview](https://docs.ravendb.net/7.2/ai-integration/connection-strings/overview.md)
- [Azure Open AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/azure-open-ai.nodejs.md)
- [Google AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/google-ai.nodejs.md)
- [Hugging Face](https://docs.ravendb.net/7.2/ai-integration/connection-strings/hugging-face.nodejs.md)
- [Ollama](https://docs.ravendb.net/7.2/ai-integration/connection-strings/ollama.nodejs.md)
- [OpenAI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/open-ai.nodejs.md)
- [Mistral AI](https://docs.ravendb.net/7.2/ai-integration/connection-strings/mistral-ai.nodejs.md)
- [Embedded model](https://docs.ravendb.net/7.2/ai-integration/connection-strings/embedded.nodejs.md)
