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

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# Working with Bedrock in Pixeltable

[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-bedrock.ipynb)  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-bedrock.ipynb)  [![Download Notebook](https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue)](https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/providers/working-with-bedrock.ipynb)

> [!TIP]
>
> This documentation page is also available as an interactive notebook. You can launch the notebook in
> Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
> above links.

Pixeltable’s Bedrock integration enables you to access AWS Bedrock
foundation models directly from your tables.

### Prerequisites

* Activate Bedrock in your AWS account.
* Request access to your desired models (e.g. Claude Sonnet 3.7, Amazon
  Nova Pro).
* Obtain a **Bedrock API Key** from the AWS console (under Bedrock >
  API keys), or configure standard AWS IAM credentials.

### Important notes

* Bedrock usage may incur costs based on your Bedrock plan.
* Be mindful of sensitive data and consider security measures when
  integrating with external services.

First you’ll need to install required libraries and configure your
Bedrock credentials.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
%pip install -qU pixeltable
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import getpass
import os

if 'BEDROCK_API_KEY' not in os.environ:
    os.environ['BEDROCK_API_KEY'] = getpass.getpass(
        'Enter your Bedrock API Key: '
    )

# Optional: set the region if your Bedrock endpoint is not in us-east-1
# os.environ['BEDROCK_REGION_NAME'] = 'us-west-2'
```

Now let’s create a Pixeltable directory to hold the tables for our demo.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt

# Remove the `bedrock_demo` directory and its contents, if it exists
pxt.drop_dir('bedrock_demo', force=True)
pxt.create_dir('bedrock_demo')
```

<pre>
  Created directory 'bedrock\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x1512adb10>
</pre>

## Messages

Create a Table: In Pixeltable, create a table with columns to represent
your input data and the columns where you want to store the results from
Bedrock.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
from pixeltable.functions import bedrock

# Create a table in Pixeltable and add a computed column that calls Bedrock

t = pxt.create_table('bedrock_demo/chat', {'input': pxt.String})

t.add_computed_column(
    output=bedrock.converse(
        model_id='amazon.nova-pro-v1:0',
        messages=[{'role': 'user', 'content': [{'text': t.input}]}],
    )
)
```

<pre>
  Created table 'chat'.
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Parse the response into a new column
t.add_computed_column(response=t.output.output.message.content[0].text)
```

<pre>
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Start a conversation
t.insert(
    [
        {
            'input': 'What was the outcome of the 1904 US Presidential election?'
        }
    ]
)
t.select(t.input, t.response).show()
```

<pre>
  Inserted 1 row with 0 errors in 2.75 s (0.36 rows/s)
</pre>

### Learn more

To learn more about advanced techniques like RAG operations in
Pixeltable, check out the [RAG Operations in
Pixeltable](https://docs.pixeltable.com/howto/use-cases/rag-operations.md)
tutorial.


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