> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lambdadb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Native embeddings

> Configure native embedding vector fields in LambdaDB, including supported providers and models, text and image sources, dimension rules, write behavior, and query behavior.

Native embeddings let LambdaDB generate vector values from fields in your documents and store them in a `vector` field. Sources can be text, or text and images with a multimodal model.

Choose the provider and model in the field's `embedding` configuration. LambdaDB handles:

* provider credentials
* vector generation during document writes
* query embedding generation for vector search

Native embedding generation consumes **inference usage**. Inference usage is measured in LIU (LambdaDB Inference Unit). See [Understanding costs](https://docs.lambdadb.ai/guides/costs/understanding-costs.md#inference-usage).

## Supported providers and models

| Provider | Model | Sources | Default dimensions | Dimensions parameter |
| :- | :- | :- | :- | :- |
| `openai` | `text-embedding-3-small` | Exactly one text source | `1536` | Optional, from `64` to `1536` |
| `openai` | `text-embedding-3-large` | Exactly one text source | `3072` | Optional, from `64` to `3072` |
| `openai` | `text-embedding-ada-002` | Exactly one text source | `1536` | Fixed at `1536` |
| `cohere` | `embed-v5.0-pro` | Text or image sources | `2048` | Optional: `256`, `512`, `768`, `1024`, `1536`, or `2048` |
| `cohere` | `embed-v5.0-fast` | Text or image sources | `2048` | Optional: `256`, `512`, `768`, `1024`, `1536`, or `2048` |

LambdaDB's [dimension limits](https://docs.lambdadb.ai/guides/get-started/limits.md#collections-and-schema) also apply when the embedding provider accepts smaller values. Optional `embedding.similarity` supports `cosine` and `euclidean`; all models default to `cosine`.

## Collection schema

Define a vector field with an `embedding` block to let LambdaDB generate its vectors. `sources` lists the document fields to embed, in order, each with its `type`.

```json theme={null}
{
  "indexConfigs": {
    "body": {
      "type": "text",
      "analyzers": ["english"]
    },
    "bodyEmbedding": {
      "type": "vector",
      "embedding": {
        "provider": "openai",
        "model": "text-embedding-3-small",
        "sources": [{ "field": "body", "type": "text" }]
      }
    }
  }
}
```

A Cohere field can combine several text and image sources into one vector. Source fields do not need their own index configs; `photos` below is stored but not indexed:

```json theme={null}
{
  "indexConfigs": {
    "title": {
      "type": "text"
    },
    "embedding": {
      "type": "vector",
      "embedding": {
        "provider": "cohere",
        "model": "embed-v5.0-pro",
        "dimensions": 1024,
        "sources": [
          { "field": "title", "type": "text" },
          { "field": "photos", "type": "image" }
        ]
      }
    }
  }
}
```

## Schema rules

See [Limits](https://docs.lambdadb.ai/guides/get-started/limits.md#native-inference) for a summary of source, image, and request constraints.

Use the recommended [SDK, CLI, MCP server, and Migration CLI releases](https://docs.lambdadb.ai/reference/sdk/introduction.md#supported-sdk-versions) for native configuration.

* `embedding.provider`, `embedding.model`, and `embedding.sources` are required
* `embedding.sources` holds a nonempty ordered list of `{ "field", "type" }` entries; `type` is `text` or `image`, and field paths must be unique
* a source `field` is a dotted path in the stored document; it does not need an index config. If it is indexed, the leaf must be `text` or `keyword` and its ancestors must be `object` fields
* OpenAI models accept exactly one `text` source; Cohere models accept text and image sources in any order
* native embedding vector fields must not use top-level `dimensions` or `similarity`; set them inside `embedding`, where omitted values use the model defaults
* LambdaDB resolves and stores the effective `embedding.dimensions` and `embedding.similarity`

## Write behavior

Send the source fields and let LambdaDB generate the vector. You can also send the vector field directly; a supplied vector is stored as is and skips inference and image retrieval for that document.

| Operation | Behavior |
| :- | :- |
| Upsert | Present sources generate a vector. A supplied vector takes precedence over generation. Upsert replaces the whole document, so a document with neither sources nor a vector has no vector, even if the previous version had one |
| Update | A supplied vector takes precedence. Otherwise, unchanged source input reuses the existing vector, changed source input regenerates it, and removing the last source removes a generated vector. Metadata-only updates keep a directly supplied vector when the source fields are unchanged |

Text sources must be scalar strings. Image sources are a string or a flat array of strings; every array element is embedded with the other sources into one combined vector. Missing sources and empty image arrays are skipped; if no source is present, no vector is generated. Explicit `null`, arrays on text sources, objects, and other non-string values return HTTP `400` when inference is needed. To omit a source, leave out the JSON property rather than setting it to `null`.

Example upsert payloads for the two schemas above:

```json theme={null}
{
  "docs": [
    {
      "id": "doc-1",
      "body": "Refunds are available within 7 days of purchase."
    }
  ]
}
```

```json theme={null}
{
  "docs": [
    {
      "id": "shoe-1",
      "title": "Red canvas running shoes",
      "photos": [
        "https://example.com/shoe-front.png",
        "https://example.com/shoe-side.png"
      ]
    }
  ]
}
```

### Text input limits

Use nonempty source text within the selected provider's input budget:

| Provider | Text input limit |
| :- | :- |
| OpenAI | 8,192 tokens per input; 300,000 tokens across inputs in one provider request |
| Cohere | Selected model's context length |

OpenAI token budgets follow its [embedding input contract](https://developers.openai.com/api/reference/resources/embeddings/methods/create). LambdaDB requests no truncation for Cohere, so an input over the model's context limit is rejected with HTTP `400`.

These limits apply to source text and query text, independently of LambdaDB's request and document byte limits. LambdaDB sends source strings to the provider without automatic chunking or truncation. Split long documents into separate records with stable chunk IDs before writing them, and count tokens using the selected model's tokenizer. When writing many long records, use smaller upsert or update batches to stay within the provider's combined token limit.

### Image inputs

Image sources are available with Cohere models. Each value is either a public HTTPS URL that LambdaDB downloads, or a data URI with base64 content, such as `data:image/png;base64,...`. Supported formats are PNG, JPEG, GIF, and WebP. Images are downloaded and decoded while the write or query is prepared; they are not stored by LambdaDB, and the document keeps the original URL or data URI.

See [embedding limits](https://docs.lambdadb.ai/guides/get-started/limits.md#embeddings) for the allowed number of parts and images, decoded image bytes, and pixel count.

A failed download, an unsupported or mismatched format, or an input over these limits returns HTTP `400`.

### Failed embedding generation

Embedding generation completes before a write is submitted for indexing. If generation fails for any document or native field, the write request fails without submitting its documents; it does not store a partially embedded batch. Successful embedding calls can still consume inference usage if a later call in the same request fails.

| Status | Meaning and next step |
| :- | :- |
| `400` | Invalid source or query input, including an empty string, an invalid image, or a provider token-limit rejection. Correct or split the input before retrying |
| `403` | Project inference quota exceeded. Check plan usage before retrying |
| `429` | Request or provider throttling. Retry with bounded backoff |
| `500` | Provider failure, invalid response, or embedding transport failure. Retain the server message for troubleshooting |

Native embeddings have no `returnOriginal` fallback. The [reranking failure policy](https://docs.lambdadb.ai/guides/search/native-reranking.md#handle-failures) applies only to the reranking stage; it cannot bypass query embedding failures. For an overall request timeout or an unknown write outcome, [verify the resulting state before retrying](https://docs.lambdadb.ai/guides/documents/upsert-data.md#ids-and-retries).

## Query behavior

A `knn` query on a native embedding vector field takes exactly one of:

* `queryText`: text that LambdaDB embeds with the field's model
* `queryInputs`: ordered parts, each `{ "type": "text" | "image", "value": "..." }`; Cohere fields accept mixed text and image parts, OpenAI fields accept one text part
* `queryVector`: a vector you computed yourself, which skips inference

Query text must be nonblank and fit the input limits above; query images follow the [image input limits](#image-inputs). LambdaDB prepares all inputs and generates the query vector before retrieval; if that fails, the query fails without returning search results.

```json theme={null}
{
  "size": 10,
  "query": {
    "knn": {
      "field": "bodyEmbedding",
      "queryText": "refund policy",
      "k": 10
    }
  }
}
```

```json theme={null}
{
  "query": {
    "knn": {
      "field": "embedding",
      "queryInputs": [
        {
          "type": "text",
          "value": "red shoes"
        },
        {
          "type": "image",
          "value": "https://example.com/shoe.png"
        }
      ],
      "k": 10
    }
  },
  "size": 10
}
```

For full query examples, see [Vector query](https://docs.lambdadb.ai/guides/search/vector.md).

## Bulk upsert

[Bulk upsert](https://docs.lambdadb.ai/guides/documents/bulk-upsert-data.md) never generates embeddings. For each native embedding field, a document with no source values can omit the vector; a document with a present source must supply the vector directly. A document with a present source but no vector fails the whole bulk request before any documents are committed; empty image arrays are skipped. To generate embeddings, use the regular [upsert](https://docs.lambdadb.ai/guides/documents/upsert-data.md) or [update](https://docs.lambdadb.ai/guides/documents/update-data.md) flow.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.