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

# AWS Bedrock

Use `bedrock-text` to embed text or `bedrock-image` to search images by text or image.

## Prerequisites

Install `boto3` for either embedding function. Install `pillow` as well for image embeddings.

```bash theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
pip install boto3 pillow
```

Configure AWS credentials with permission to invoke your model in the AWS Region where it is available. Use the AWS CLI to configure credentials and set the session token if you use temporary credentials.

```bash Bash icon="terminal" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
aws configure
aws configure set aws_session_token "<your_session_token>"
```

Verify the active credentials with the AWS CLI.

```bash Bash icon="terminal" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
aws sts get-caller-identity
```

## Text embeddings

The `bedrock-text` registry entry supports these model IDs.

| Model ID | Dimensions |
| - | - |
| `amazon.titan-embed-text-v1` (default) | 1536 |
| `amazon.titan-embed-text-v2:0` | 1024 |
| `cohere.embed-english-v3` | 1024 |
| `cohere.embed-multilingual-v3` | 1024 |

For Cohere text models, set `source_input_type` or `query_input_type` in `create()` to override `search_document` or `search_query`. You can also pass `profile_name`, `assumed_role`, and `role_session_name` to `bedrock-text`.

```python Python icon="python" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
import tempfile
from pathlib import Path

import lancedb
import pandas as pd
from lancedb.embeddings import get_registry
from lancedb.pydantic import LanceModel, Vector

model = get_registry().get("bedrock-text").create()

class TextModel(LanceModel):
    text: str = model.SourceField()
    vector: Vector(model.ndims()) = model.VectorField()

df = pd.DataFrame({"text": ["hello world", "goodbye world"]})
db = lancedb.connect(str(Path(tempfile.mkdtemp()) / "bedrock-demo"))
tbl = db.create_table("test", schema=TextModel, mode="overwrite")

tbl.add(df)
rs = tbl.search("hello").limit(1).to_pandas()
print(rs.head())
```

## Image embeddings

LanceDB embeds images when you add them to a table. You can search the table with text or a Pillow image. `bedrock-image` uses boto3's default credential chain. Select a profile with `AWS_PROFILE` in the application's environment or run the application with an IAM role.

| Model ID | Dimensions | Source image formats |
| - | - | - |
| `amazon.titan-embed-image-v1` (default) | 1024 | PNG, JPEG |
| `cohere.embed-v4:0` | 1536 | PNG, JPEG, WebP, GIF |

Choose a binary source column (`bytes`) for encoded image bytes or a string source column (`str`) for file paths readable by the process that adds rows. Pillow detects the source format from the file contents. If your table has nullable images and vectors, pass `on_bad_vectors="null"` to keep rows without an image. To use Cohere Embed v4, pass `name="cohere.embed-v4:0"` to `create()`.

```python Python icon="python" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
import io
import tempfile
from pathlib import Path

import lancedb
from lancedb.embeddings import get_registry
from lancedb.pydantic import LanceModel, Vector
from PIL import Image

model = get_registry().get("bedrock-image").create()

class Photo(LanceModel):
    label: str
    image: bytes = model.SourceField()
    vector: Vector(model.ndims()) = model.VectorField()

def png_bytes(color: str) -> bytes:
    buf = io.BytesIO()
    Image.new("RGB", (64, 64), color).save(buf, format="PNG")
    return buf.getvalue()

db_path = Path(tempfile.mkdtemp()) / "bedrock-image-demo"
db = lancedb.connect(db_path)
table = db.create_table("photos", schema=Photo, mode="overwrite")

table.add(
    [
        {"label": "red", "image": png_bytes("red")},
        {"label": "blue", "image": png_bytes("blue")},
    ]
)

text_matches = table.search("red square").limit(1).to_list()
print(text_matches[0]["label"])

query_image = Image.new("RGB", (64, 64), "blue")
image_matches = table.search(query_image).limit(1).to_list()
print(image_matches[0]["label"])
```

A query string is embedded as text. To search asynchronously with a Pillow image, pass `query_type="vector"`. Run the following code in an async context with the `db_path` and `query_image` from the example.

```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
async_db = await lancedb.connect_async(db_path)
async_table = await async_db.open_table("photos")
query = await async_table.search(query_image, query_type="vector")
results = await query.limit(1).to_list()
```

## AWS settings

Pass these options to `create()` with either registry entry.

| Parameter | Default | Description |
| - | - | - |
| `name` | Varies by registry entry | Model ID to invoke. |
| `region` | `"us-east-1"` | AWS Region where the model is available. |
| `max_retries` | `7` | Maximum retries. Image embeddings retry individual Bedrock requests. Set to `0` to disable retries. |


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