Skip to content

Running the Consumer Agent with AWS Bedrock (no Docker)

This guide launches the tdfs4ds consumer agent chatbot on a machine reached through VS Code SSH, with AWS Bedrock for both the instruct and the embedding model. No Docker and no separate Chroma server are needed. It uses the tutorial data, so you can follow it on an empty database.

Needs an instruct model

This page calls a language model and an embedding model on AWS Bedrock. Set INSTRUCT_MODEL_PROVIDER, INSTRUCT_MODEL_REGION, INSTRUCT_MODEL_API_KEY and INSTRUCT_MODEL_MODEL, then EMBEDDING_MODEL_PROVIDER, EMBEDDING_MODEL_REGION and EMBEDDING_MODEL_MODEL (step 3 sets them in code; they can also come from the .env). The bearer token is read from the environment variable BEDROCK_BEARER_TOKEN (a temporary token from the AWS console).

Prerequisites

  • A Python environment with network access to your Teradata Vantage instance.
  • AWS Bedrock access with a temporary bearer token.
  • VS Code with the Remote - SSH extension and port forwarding.

Step 1 · Install the package

pip install "tdfs4ds[agent]"
pip install boto3

langchain-aws comes with the agent extra; boto3 is required for Bedrock and is not always pulled in on every platform.

Step 2 · Connect and create a feature store to talk about

import dataclasses
import getpass
import os

import tdfs4ds                      # importing it first also loads a .env file, if you have one
import teradataml as tdml

# 1. Open the Teradata session. Host and user come from the environment (TDFS4DS_TD_HOST,
#    TDFS4DS_TD_USERNAME), the password from TDFS4DS_TD_PASSWORD or a prompt: nothing secret
#    is written on this page.
host = os.environ["TDFS4DS_TD_HOST"]
user = os.environ["TDFS4DS_TD_USERNAME"]
password = os.environ.get("TDFS4DS_TD_PASSWORD") or getpass.getpass("Teradata password: ")
tdml.create_context(host=host, username=user, password=password)

# 2. Pick your industry. This is the ONLY line to change: retail, banking, healthcare, pharma,
#    manufacturing, assembly, energy or transportation. Every name below comes from S.
S = tdfs4ds.tutorial_scenario("retail")

# 3. Connect to the feature store (created when missing) and choose a data domain. disposable=True
#    records that this domain is an experiment, so the last page removes it in one call.
DATABASE = os.environ.get("TDFS4DS_TD_DATABASE") or user
tdfs4ds.connect(database=DATABASE, create_if_missing=True)
tdfs4ds.create_data_domain(f"TUTORIAL_{S.name.upper()}", disposable=True)   # an experiment: removable in one call

# 4. The tutorial data: three tables written once; a second run keeps them.
try:
    S = tdfs4ds.create_tutorial_data(S.name, DATABASE)
except ValueError:
    S = dataclasses.replace(S, database=DATABASE)


def register_entity_features():
    """Page 1 in one call: (re)register the entity features and return the process id."""
    sql = f"""
        SELECT {S.entity}, COUNT(*) AS nb_events, SUM({S.amount}) AS total_amount,
               AVG({S.amount}) AS avg_amount, COUNT(DISTINCT {S.partner}) AS nb_partners
        FROM {S.table('events')}
        GROUP BY 1"""
    return tdfs4ds.upload_features(
        df=None, sql_query=sql, target_view_name=f"{S.database}.{S.name}_entity_features",
        entity_id=[S.entity], feature_names=["nb_events", "total_amount", "avg_amount", "nb_partners"],
        replace=True, document=False, optimize_query=False, return_process_id=True)

process_id = register_entity_features()
dataset = tdfs4ds.build_dataset(
    entity_id=[S.entity],
    selected_features=["nb_events", "total_amount", "avg_amount", "nb_partners"],
    view_name=f"{S.database}.{S.name}_entity_dataset",
)
print(dataset.shape)

You should see a process id and a dataset of about 2,000 rows. Skip the last lines on a store that already holds processes and datasets: connect(create_if_missing=True) (in the block above) creates the documentation and lineage tables when they are missing, and is safe to repeat.

Step 3 · Choose the models, document the store, build the index

os.environ["AWS_DEFAULT_REGION"] = "us-east-1"        # your Bedrock region

tdfs4ds.INSTRUCT_MODEL_PROVIDER = "bedrock"
tdfs4ds.INSTRUCT_MODEL_REGION = "us-east-1"
tdfs4ds.INSTRUCT_MODEL_API_KEY = os.environ["BEDROCK_BEARER_TOKEN"]
tdfs4ds.INSTRUCT_MODEL_MODEL = "anthropic.claude-3-5-sonnet-20240620-v1:0"

# EMBEDDING_MODEL_API_KEY falls back to INSTRUCT_MODEL_API_KEY automatically.
tdfs4ds.EMBEDDING_MODEL_PROVIDER = "bedrock"
tdfs4ds.EMBEDDING_MODEL_REGION = "us-east-1"
tdfs4ds.EMBEDDING_MODEL_MODEL = "amazon.titan-embed-text-v2:0"
tdfs4ds.EMBEDDING_MODEL_DIM = 1024                    # Titan v2 native dimension
tdfs4ds.CHROMA_PATH = "./tdfs4ds_chroma"              # the index is kept on this machine

tdfs4ds.rebuild_lineage_graph(all_data_domains=True)
tdfs4ds.rebuild_documentation(force_update=False, all_data_domains=True)

You should see log lines for the lineage edges recorded and for each process and the dataset being documented. force_update=False skips objects that already have stored documentation. rebuild_documentation also builds the vector index at the end.

You can seed the agent with descriptions of your own instead of (or before) the LLM: tdfs4ds.upload_business_dictionary_objects(df) and tdfs4ds.upload_business_dictionary_columns(df) take a pandas DataFrame (columns DATABASE_NAME, OBJECT_NAME, OBJECT_TYPE (V view, T table, D dataset) and BUSINESS_DESCRIPTION for the first; DATABASE_NAME, TABLE_NAME, COLUMN_NAME and BUSINESS_DESCRIPTION for the second).

Step 4 · Launch the chatbot

from tdfs4ds.agent import launch_chatbot_with_index

launch_chatbot_with_index(
    port=7860,
    inline=False,   # True only inside a Jupyter notebook
    share=False,    # VS Code port forwarding handles external access
)

You should see a line saying the interface is running on http://127.0.0.1:7860. Ask it: "Which features describe how much a customer spends?" (your entity's name in the other flavors).

Step 5 · Forward the port in VS Code

  1. Open the Ports panel in VS Code (bottom bar, or View > Ports).
  2. Click Forward a Port and enter 7860.
  3. Open http://localhost:7860 in your local browser.

The chatbot is reachable from your machine through the SSH tunnel: no public URL and no share=True.

Notes

Temporary credentials expire. Bearer tokens from the AWS console are short-lived; when one expires, Bedrock calls fail with an authentication error. Restart with a fresh token (there is no automatic refresh outside a notebook, where tdfs4ds asks for a new token).

Titan v2 embedding dimensions. amazon.titan-embed-text-v2:0 supports 256, 512 and 1024 (default). If you built a Chroma index with another model or dimension (for example 1536 from OpenAI text-embedding-3-small), delete the ./tdfs4ds_chroma folder before the first run to avoid a dimension mismatch.

Check the configuration. tdfs4ds.check_configuration() runs one prompt and one embedding and names the setting to change when something fails (Connect and configure).

Clean up

tdfs4ds.remove_process(process_id, refresh_index=False)
tdfs4ds.drop_tutorial_data(S.name, DATABASE)
tdml.remove_context()

You should see the process removed from the catalog and the three tutorial tables dropped. Delete the ./tdfs4ds_chroma folder to remove the local index.