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

# embed

> Generate vector embeddings from text and image columns.

`embed` generates a vector embedding for each row of a text or image column and returns a column of [AI envelopes](#ai-envelope). An AI envelope is a `STRUCT` value with the vector embedding and associated metadata.

Chowder picks the embedding model from your input. See [Models](https://docs.chowder.ai/concepts/models.md).

## Signature

```chowder-sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
embed(input)
```

| Parameter | Type | Description |
| - | - | - |
| `input` | `VARCHAR` or encoded image `BINARY` | Text or image to embed. |

## Input

Pass text, such as the `content` column from `read_documents` or a text column from `read_parquet`.

For images, pass the `image` column from `read_images`, `read_videos`, or `read_mcap`. It holds the encoded image bytes, which `embed` decodes for the embedding model.

## AI envelope

Each row's AI envelope has these fields:

| Field | Type | Description |
| - | - | - |
| `output` | `FLOAT[N]` | The vector embedding. Chowder resolves `N` from the embedding model during planning. |
| `confidence` | `FLOAT` | Always null. |
| `error` | `VARCHAR` | Why the row failed. Null otherwise. |
| `input_tokens` | `BIGINT` | Always null. |
| `input_ms` | `DOUBLE` | Always null. |
| `output_tokens` | `BIGINT` | Always null. |
| `output_ms` | `DOUBLE` | Always null. |
| `model` | `VARCHAR` | The model that produced the embedding. |
| `model_id` | `VARCHAR` | A compact identifier for the model. |
| `probabilities` | `NULL` | Always null. |

Rows that fail or have null input stay in the result with a null `output`. For failed rows, `error` explains why.

## Text embeddings

```chowder-sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
SELECT
    title,
    embed(content) AS content_embedding -- AI envelope; vector in .output
FROM read_parquet('hf://buckets/chowderai/chowder-demo/parquet/data/amazon-reviews/*.parquet')
LIMIT 3;
```

## Image and text embeddings

The default embedding model supports text and images in the same vector space.

```chowder-sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
WITH products AS (
    SELECT
        source,
        image
    FROM read_images('hf://buckets/chowderai/chowder-demo/image/data/amazon-products/drinking-cup/*.jpg')
    LIMIT 24 -- Bound the input before computing image embeddings
)
SELECT
    source,
    sim(
        embed(image).output, -- Embed images and text in the same vector space
        embed('a stack of disposable paper cups').output
    ) AS similarity
FROM products
ORDER BY similarity DESC
LIMIT 3;
```

## Behavior

* `embed` runs only on the rows the query needs. For example, it runs on rows that satisfy the `WHERE` conditions.
* Results are cached, so `embed` doesn't recompute results for the same input. See [Caching](https://docs.chowder.ai/concepts/caching.md).
* Vectors are L2-normalized by default, so their dot product equals their cosine similarity. To keep raw vectors, create the engine with `embed_config=chowder.EmbedConfig(normalize=False)`. See [Configuration](https://docs.chowder.ai/reference/configuration.md).
* Vectors are comparable only when they come from the same model. Check `model_id` before comparing stored vectors with new ones.


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