---
layout: article
title: Embeddings
description: Generate text embeddings with Appwrite VectorsDB. Turn text into vector embeddings with built-in models and store them in your documents for vector search.
---
An embedding is a list of numbers that represents the meaning of a piece of text.
Appwrite generates embeddings for you with built-in models, so you can turn text into vectors and store them in a collection without running a separate embedding service.

The typical flow is two steps: generate an embedding from your text, then store that embedding in a document's `embeddings` field. Once stored, you can run [vector search](/docs/products/databases/vectorsdb/vector-search) over your documents.

# Generate embeddings
Embeddings come from the Embeddings service rather than the VectorsDB service, and generating them doesn't involve a database or collection at all.

Use the `createTextEmbeddings` method to turn one or more strings into vector embeddings. Pass an array of `texts` and, optionally, a `model`. When you omit `model`, Appwrite uses the default `nomic-embed-text` model. Appwrite [Server SDKs](/docs/sdks#server) require an [API key](/docs/advanced/platform/api-keys) with the `embeddings.write` scope.

```server-nodejs
const sdk = require('node-appwrite');

const client = new sdk.Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setKey('<YOUR_API_KEY>'); // Your secret API key

const embeddings = new sdk.Embeddings(client);

const result = await embeddings.createTextEmbeddings({
    texts: ['The quick brown fox jumps over the lazy dog'],
    model: sdk.EmbeddingModel.Nomicembedtext // optional, defaults to nomic-embed-text
});
```
```deno
import * as sdk from "npm:node-appwrite";

const client = new sdk.Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setKey('<YOUR_API_KEY>'); // Your secret API key

const embeddings = new sdk.Embeddings(client);

const result = await embeddings.createTextEmbeddings({
    texts: ['The quick brown fox jumps over the lazy dog'],
    model: sdk.EmbeddingModel.Nomicembedtext // optional, defaults to nomic-embed-text
});
```
```php
<?php

use Appwrite\Client;
use Appwrite\Services\Embeddings;
use Appwrite\Enums\EmbeddingModel;

$client = (new Client())
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    ->setProject('<YOUR_PROJECT_ID>') // Your project ID
    ->setKey('<YOUR_API_KEY>'); // Your secret API key

$embeddings = new Embeddings($client);

$result = $embeddings->createTextEmbeddings(
    texts: ['The quick brown fox jumps over the lazy dog'],
    model: EmbeddingModel::NOMICEMBEDTEXT() // optional, defaults to nomic-embed-text
);
```
```python
from appwrite.client import Client
from appwrite.services.embeddings import Embeddings
from appwrite.enums import EmbeddingModel

client = Client()
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
client.set_key('<YOUR_API_KEY>') # Your secret API key

embeddings = Embeddings(client)

result = embeddings.create_text_embeddings(
    texts = ['The quick brown fox jumps over the lazy dog'],
    model = EmbeddingModel.NOMIC_EMBED_TEXT # optional, defaults to nomic-embed-text
)
```
```ruby
require 'appwrite'

include Appwrite
include Appwrite::Enums

client = Client.new
    .set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
    .set_project('<YOUR_PROJECT_ID>') # Your project ID
    .set_key('<YOUR_API_KEY>') # Your secret API key

embeddings = Embeddings.new(client)

result = embeddings.create_text_embeddings(
    texts: ['The quick brown fox jumps over the lazy dog'],
    model: EmbeddingModel::NOMIC_EMBED_TEXT # optional, defaults to nomic-embed-text
)
```
```csharp
using Appwrite;
using Appwrite.Enums;
using Appwrite.Models;
using Appwrite.Services;

Client client = new Client()
    .SetEndPoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .SetProject("<YOUR_PROJECT_ID>") // Your project ID
    .SetKey("<YOUR_API_KEY>"); // Your secret API key

Embeddings embeddings = new Embeddings(client);

EmbeddingList result = await embeddings.CreateTextEmbeddings(
    texts: new List<string> { "The quick brown fox jumps over the lazy dog" },
    model: EmbeddingModel.NomicEmbedText // optional, defaults to nomic-embed-text
);
```
```dart
import 'package:dart_appwrite/dart_appwrite.dart';
import 'package:dart_appwrite/enums.dart' as enums;

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setKey('<YOUR_API_KEY>'); // Your secret API key

Embeddings embeddings = Embeddings(client);

EmbeddingList result = await embeddings.createTextEmbeddings(
    texts: ['The quick brown fox jumps over the lazy dog'],
    model: enums.EmbeddingModel.nomicEmbedText, // optional, defaults to nomic-embed-text
);
```
```kotlin
import io.appwrite.Client
import io.appwrite.services.Embeddings
import io.appwrite.enums.EmbeddingModel

val client = Client(context)
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val embeddings = Embeddings(client)

val response = embeddings.createTextEmbeddings(
    texts = listOf("The quick brown fox jumps over the lazy dog"),
    model = EmbeddingModel.NOMIC_EMBED_TEXT // optional, defaults to nomic-embed-text
)
```
```java
import io.appwrite.Client;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.services.Embeddings;
import io.appwrite.enums.EmbeddingModel;

Client client = new Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>"); // Your secret API key

Embeddings embeddings = new Embeddings(client);

embeddings.createTextEmbeddings(
    List.of("The quick brown fox jumps over the lazy dog"), // texts
    EmbeddingModel.NOMIC_EMBED_TEXT, // model (optional)
    new CoroutineCallback<>((result, error) -> {
        if (error != null) {
            error.printStackTrace();
            return;
        }

        System.out.println(result);
    })
);
```
```swift
import Appwrite
import AppwriteEnums

let client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

let embeddings = Embeddings(client)

let embeddingList = try await embeddings.createTextEmbeddings(
    texts: ["The quick brown fox jumps over the lazy dog"],
    model: .nomicEmbedText // optional, defaults to nomic-embed-text
)
```
```server-rust
use appwrite::Client;
use appwrite::services::Embeddings;
use appwrite::enums::EmbeddingModel;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    client.set_endpoint("https://<REGION>.cloud.appwrite.io/v1"); // Your API Endpoint
    client.set_project("<YOUR_PROJECT_ID>"); // Your project ID
    client.set_key("<YOUR_API_KEY>"); // Your secret API key

    let embeddings = Embeddings::new(&client);

    let result = embeddings.create_text_embeddings(
        vec!["The quick brown fox jumps over the lazy dog"],
        Some(EmbeddingModel::NomicEmbedText), // optional, defaults to nomic-embed-text
    ).await?;

    println!("{:?}", result);
    Ok(())
}
```
```bash
appwrite embeddings create-text-embeddings \
    --texts 'The quick brown fox jumps over the lazy dog' \
    --model 'nomic-embed-text'
```

The response is an embedding list. The `embeddings` array holds one entry per input text, in the same order you passed them.

```json
{
    "total": 1,
    "embeddings": [
        {
            "model": "nomic-embed-text",
            "dimension": 768,
            "embedding": [-0.012246467, 0.02621112, -0.15247375, ...],
            "error": ""
        }
    ]
}
```

Each entry contains:

| Field | Description |
| --- | --- |
| `model` | The model that generated this embedding. |
| `dimension` | The number of values in the embedding vector. |
| `embedding` | The embedding vector as an array of floats. If generation fails, this is an empty array. |
| `error` | An error message if this text could not be embedded. An empty string means there was no error. |

# Available models
Appwrite ships with the following text embedding models. The `dimension` of a model is the length of the vector it produces, and it must match the `dimension` you set on the [collection](/docs/products/databases/vectorsdb/collections) where you store the embeddings.

| Model | Dimension | Provider | Languages | Best for | Notes |
| --- | --- | --- | --- | --- | --- |
| `nomic-embed-text` | 768 | Nomic AI | English | General-purpose retrieval over long English documents | **Default.** 8K context window, so long documents embed in one call. |
| `embedding-gemma` | 768 | Google | 100+ | Multilingual search and cross-language retrieval | A query in one language matches content in another. |
| `all-minilm` | 384 | Sentence Transformers | English | High-volume workloads where speed and storage matter most | Fast to generate and cheap to store, at some cost to accuracy. |
| `bge-small` | 384 | BAAI | English | Ranking and reranking short English passages | Tuned for ranking quality over speed. |

**Match the model to your collection dimension**

Pick a model before you create your collection. In the Console you pick the model and the collection takes its dimension. Through an SDK you set `dimension` to the model's dimension. Every document in a collection uses vectors of the same length, so a collection only works with models that match its dimension.

# Store embeddings
Once you have an embedding, store it in a document's `embeddings` field. The collection's `dimension` must match the embedding's `dimension`. You can store any related data alongside the vector in the document's `metadata` field.

```server-nodejs
const sdk = require('node-appwrite');

const client = new sdk.Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setKey('<YOUR_API_KEY>'); // Your secret API key

const embeddings = new sdk.Embeddings(client);
const vectorsDB = new sdk.VectorsDB(client);

const text = 'The quick brown fox jumps over the lazy dog';

const generated = await embeddings.createTextEmbeddings({
    texts: [text]
});

const result = await vectorsDB.createDocument({
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: sdk.ID.unique(),
    data: {
        embeddings: generated.embeddings[0].embedding,
        metadata: { text }
    }
});
```
```deno
import * as sdk from "npm:node-appwrite";

const client = new sdk.Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setKey('<YOUR_API_KEY>'); // Your secret API key

const embeddings = new sdk.Embeddings(client);
const vectorsDB = new sdk.VectorsDB(client);

const text = 'The quick brown fox jumps over the lazy dog';

const generated = await embeddings.createTextEmbeddings({
    texts: [text]
});

const result = await vectorsDB.createDocument({
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: sdk.ID.unique(),
    data: {
        embeddings: generated.embeddings[0].embedding,
        metadata: { text }
    }
});
```
```php
<?php

use Appwrite\Client;
use Appwrite\Services\Embeddings;
use Appwrite\Services\VectorsDB;
use Appwrite\ID;

$client = (new Client())
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    ->setProject('<YOUR_PROJECT_ID>') // Your project ID
    ->setKey('<YOUR_API_KEY>'); // Your secret API key

$embeddings = new Embeddings($client);
$vectorsDB = new VectorsDB($client);

$text = 'The quick brown fox jumps over the lazy dog';

$generated = $embeddings->createTextEmbeddings(
    texts: [$text]
);

$result = $vectorsDB->createDocument(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: ID::unique(),
    data: [
        'embeddings' => $generated['embeddings'][0]['embedding'],
        'metadata' => ['text' => $text]
    ]
);
```
```python
from appwrite.client import Client
from appwrite.services.embeddings import Embeddings
from appwrite.services.vectors_db import VectorsDB
from appwrite.id import ID

client = Client()
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
client.set_key('<YOUR_API_KEY>') # Your secret API key

embeddings = Embeddings(client)
vectors_db = VectorsDB(client)

text = 'The quick brown fox jumps over the lazy dog'

generated = embeddings.create_text_embeddings(
    texts = [text]
)

result = vectors_db.create_document(
    database_id = '<DATABASE_ID>',
    collection_id = '<COLLECTION_ID>',
    document_id = ID.unique(),
    data = {
        "embeddings": generated["embeddings"][0]["embedding"],
        "metadata": { "text": text }
    }
)
```
```ruby
require 'appwrite'

include Appwrite

client = Client.new
    .set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
    .set_project('<YOUR_PROJECT_ID>') # Your project ID
    .set_key('<YOUR_API_KEY>') # Your secret API key

embeddings = Embeddings.new(client)
vectors_db = VectorsDB.new(client)

text = 'The quick brown fox jumps over the lazy dog'

generated = embeddings.create_text_embeddings(
    texts: [text]
)

result = vectors_db.create_document(
    database_id: '<DATABASE_ID>',
    collection_id: '<COLLECTION_ID>',
    document_id: ID.unique(),
    data: {
        "embeddings" => generated.embeddings[0].embedding,
        "metadata" => { "text" => text }
    }
)
```
```csharp
using Appwrite;
using Appwrite.Models;
using Appwrite.Services;

Client client = new Client()
    .SetEndPoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .SetProject("<YOUR_PROJECT_ID>") // Your project ID
    .SetKey("<YOUR_API_KEY>"); // Your secret API key

Embeddings embeddings = new Embeddings(client);
VectorsDB vectorsDB = new VectorsDB(client);

var text = "The quick brown fox jumps over the lazy dog";

EmbeddingList generated = await embeddings.CreateTextEmbeddings(
    texts: new List<string> { text }
);

Document result = await vectorsDB.CreateDocument(
    databaseId: "<DATABASE_ID>",
    collectionId: "<COLLECTION_ID>",
    documentId: ID.Unique(),
    data: new {
        embeddings = generated.Embeddings[0].XEmbedding,
        metadata = new { text }
    }
);
```
```dart
import 'package:dart_appwrite/dart_appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setKey('<YOUR_API_KEY>'); // Your secret API key

Embeddings embeddings = Embeddings(client);
VectorsDB vectorsDB = VectorsDB(client);

final text = 'The quick brown fox jumps over the lazy dog';

EmbeddingList generated = await embeddings.createTextEmbeddings(
    texts: [text],
);

Document result = await vectorsDB.createDocument(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: ID.unique(),
    data: {
        "embeddings": generated.embeddings[0].embedding,
        "metadata": { "text": text }
    },
);
```
```kotlin
import io.appwrite.Client
import io.appwrite.ID
import io.appwrite.services.Embeddings
import io.appwrite.services.VectorsDB

val client = Client(context)
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val embeddings = Embeddings(client)
val vectorsDB = VectorsDB(client)

val text = "The quick brown fox jumps over the lazy dog"

val generated = embeddings.createTextEmbeddings(
    texts = listOf(text),
)

val response = vectorsDB.createDocument(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    documentId = ID.unique(),
    data = mapOf(
        "embeddings" to generated.embeddings[0].embedding,
        "metadata" to mapOf("text" to text)
    ),
)
```
```java
import io.appwrite.Client;
import io.appwrite.ID;
import io.appwrite.coroutines.CoroutineCallback;
import io.appwrite.services.Embeddings;
import io.appwrite.services.VectorsDB;
import java.util.List;
import java.util.Map;

Client client = new Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>"); // Your secret API key

Embeddings embeddings = new Embeddings(client);
VectorsDB vectorsDB = new VectorsDB(client);

String text = "The quick brown fox jumps over the lazy dog";

embeddings.createTextEmbeddings(
    List.of(text),
    new CoroutineCallback<>((generated, error) -> {
        if (error != null) {
            error.printStackTrace();
            return;
        }

        vectorsDB.createDocument(
            "<DATABASE_ID>",
            "<COLLECTION_ID>",
            ID.unique(),
            Map.of(
                "embeddings", generated.getEmbeddings().get(0).getEmbedding(),
                "metadata", Map.of("text", text)
            ),
            new CoroutineCallback<>((result, err) -> {
                if (err != null) {
                    err.printStackTrace();
                    return;
                }

                System.out.println(result);
            })
        );
    })
);
```
```swift
import Appwrite

let client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

let embeddings = Embeddings(client)
let vectorsDB = VectorsDB(client)

let text = "The quick brown fox jumps over the lazy dog"

let generated = try await embeddings.createTextEmbeddings(
    texts: [text]
)

let document = try await vectorsDB.createDocument(
    databaseId: "<DATABASE_ID>",
    collectionId: "<COLLECTION_ID>",
    documentId: ID.unique(),
    data: [
        "embeddings": generated.embeddings[0].embedding,
        "metadata": ["text": text]
    ]
)
```
```server-rust
use appwrite::Client;
use appwrite::services::{Embeddings, VectorsDB};
use appwrite::id::ID;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    client.set_endpoint("https://<REGION>.cloud.appwrite.io/v1"); // Your API Endpoint
    client.set_project("<YOUR_PROJECT_ID>"); // Your project ID
    client.set_key("<YOUR_API_KEY>"); // Your secret API key

    let embeddings = Embeddings::new(&client);
    let vectors_db = VectorsDB::new(&client);

    let text = "The quick brown fox jumps over the lazy dog";

    let generated = embeddings.create_text_embeddings(
        vec![text],
        None, // model (optional)
    ).await?;

    let result = vectors_db.create_document(
        "<DATABASE_ID>",
        "<COLLECTION_ID>",
        ID::unique(),
        json!({
            "embeddings": generated.embeddings[0].embedding,
            "metadata": { "text": text }
        }),
        None, // permissions (optional)
    ).await?;

    println!("{:?}", result);
    Ok(())
}
```
```bash
appwrite vectorsdb create-document \
    --database-id <DATABASE_ID> \
    --collection-id <COLLECTION_ID> \
    --document-id 'unique()' \
    --data '{ "embeddings": [-0.012246467, 0.02621112, -0.15247375], "metadata": { "text": "The quick brown fox jumps over the lazy dog" } }'
```

**Embed in batches**

You can pass several strings in one `createTextEmbeddings` call to embed them together. The response returns one entry per input text, in order, so you can map each embedding back to its source text before storing.

# Next steps
With embeddings stored in your documents, you can find the most similar documents to a query vector with vector search.

[Learn about vector search](/docs/products/databases/vectorsdb/vector-search)
