# ensure_embeddings

> **Function** in `langgraph.store`

📖 [View in docs](https://reference.langchain.com/python/langgraph.store/base/embed/ensure_embeddings)

Ensure that an embedding function conforms to LangChain's Embeddings interface.

This function wraps arbitrary embedding functions to make them compatible with
LangChain's Embeddings interface. It handles both synchronous and asynchronous
functions.

## Signature

```python
ensure_embeddings(
    embed: Embeddings | EmbeddingsFunc | AEmbeddingsFunc | str | None,
) -> Embeddings
```

## Description

??? example "Examples"

Wrap a synchronous embedding function:

```python
def my_embed_fn(texts):
    return [[0.1, 0.2] for _ in texts]

embeddings = ensure_embeddings(my_embed_fn)
result = embeddings.embed_query("hello")  # Returns [0.1, 0.2]
```

Wrap an asynchronous embedding function:

```python
async def my_async_fn(texts):
    return [[0.1, 0.2] for _ in texts]

embeddings = ensure_embeddings(my_async_fn)
result = await embeddings.aembed_query("hello")  # Returns [0.1, 0.2]
```

Initialize embeddings using a provider string:

```python
# Requires langchain>=0.3.9 and langgraph-checkpoint>=2.0.11
embeddings = ensure_embeddings("openai:text-embedding-3-small")
result = embeddings.embed_query("hello")
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `embed` | `Embeddings \| EmbeddingsFunc \| AEmbeddingsFunc \| str \| None` | Yes | Either an existing Embeddings instance, or a function that converts text to embeddings. If the function is async, it will be used for both sync and async operations. |

## Returns

`Embeddings`

An Embeddings instance that wraps the provided function(s).

---

[View source on GitHub](https://github.com/langchain-ai/langgraph/blob/97320843fe78b93bd5290ce366841ff9850bf379/libs/checkpoint/langgraph/store/base/embed.py#L34)