Skip to content

← Tutorials overview

5. Vector store backends

Reference

The reference for this topic is Consumer agent.

Needs an embedding model

Indexing calls an embedding model: set EMBEDDING_MODEL_PROVIDER (it falls back to the instruct model's), EMBEDDING_MODEL_MODEL and EMBEDDING_MODEL_DIM (and the URL, region or key of your provider). The index is built from the business dictionary, so run module 2 first. tdfs4ds.check_configuration() checks the models and, for the Teradata backend, the Vector Store service.

The consumer agent's SEARCH, DEFINITION and USAGE skills fall back to semantic search when an exact catalog lookup returns nothing. That search needs somewhere to keep the embedded business descriptions: a vector store. You can choose between ChromaDB (default, local) and the Teradata Enterprise Vector Store (in-database).

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()

You should see a process id.

Why a vector store at all

build_vector_index() reads the three business-dictionary tables and creates three collections:

Collection Source Used by
objects FS_BUSINESS_DICTIONARY_OBJECTS SEARCH (object-level matches)
sections FS_BUSINESS_DICTIONARY_SECTIONS SEARCH (FEATURE_THEMES, BUSINESS_QUESTIONS)
columns FS_BUSINESS_DICTIONARY_COLUMNS DEFINITION (per-feature descriptions)

Embeddings are computed once and queried on every chatbot turn that needs them. Without a vector store the agent only answers questions that match catalog names verbatim.

Backend choice at a glance

Chroma (default) Teradata Vector Store
Where vectors live Local file system or a separate Chroma HTTP server Inside Vantage, alongside your features
Governance Outside Teradata RBAC Uses Teradata privileges
Setup cost pip install only Requires the Enterprise Vector Store entitlement
Embedding source LangChain Embeddings (your vLLM / TEI / OpenAI) LangChain, or in-database TeradataAI
Best for Local development, notebooks, demos Shared deployments, governed environments

1 · Chroma, the default

tdfs4ds.VECTOR_STORE_BACKEND = "chroma"
tdfs4ds.CHROMA_MODE = "local"                    # persisted on disk
tdfs4ds.CHROMA_PATH = "./tdfs4ds_chroma"

from tdfs4ds.agent import build_vector_index, search_vector_index

build_vector_index(force_rebuild=False)
hits = search_vector_index("how much does an entity spend", top_k=3)
print(hits)

You should see the index built (one line per collection) and a DataFrame of the three closest descriptions, with total_amount or avg_amount first. CHROMA_MODE = "server" with CHROMA_HOST and CHROMA_PORT connects to a Chroma server instead.

Each feature store has its own three collections, tdfs4ds__<database>__objects and so on, so switching stores never wipes another store's embeddings. Each build records the database's time; the next build only embeds the documentation written since.

Know the limits before promoting Chroma beyond development:

  • Single machine, single process. Two Python processes writing to the same directory can corrupt it.
  • A separate daemon in server mode to operate, monitor and back up.
  • No Teradata governance: anyone with access to the index can read the descriptions.
  • Client-side embedding: vectors come from your LangChain Embeddings object and your proxy's rate limits (tdfs4ds sends batches of 8).

2 · The Teradata Vector Store

tdfs4ds.VECTOR_STORE_BACKEND = "teradata"
tdfs4ds.TERADATA_VECTOR_STORE_PREFIX = f"tdfs4ds_{S.name}"     # one prefix per store
build_vector_index(force_rebuild=False)
print(search_vector_index("how many events", top_k=3))

You should see three collections named <prefix>_objects, _sections and _columns created in Vantage, then the closest descriptions. The service authenticates through the TDFS4DS_VECTOR_STORE_AUTH_* variables (Connect and configure).

By default the Teradata backend reuses the same LangChain Embeddings object as Chroma. Where no client-side embedding is allowed, the in-database TeradataAI path computes the vectors inside Vantage:

tdfs4ds.TERADATA_AI_API_TYPE = "aws"                  # also: azure, gcp, nim, hugging_face, onnx, td_hosted
tdfs4ds.TERADATA_AI_MODEL_NAME = "amazon.titan-embed-text-v2:0"
tdfs4ds.TERADATA_AI_REGION = "us-west-2"
tdfs4ds.TERADATA_AI_ACCESS_KEY = os.environ["TDFS4DS_TERADATA_AI_ACCESS_KEY"]

With td_hosted only the type and the model name are needed: the active Teradata session authenticates.

3 · Switching backends

build_vector_index and search_vector_index dispatch on VECTOR_STORE_BACKEND at call time, so flipping the switch and re-indexing is the whole operation:

tdfs4ds.VECTOR_STORE_BACKEND = "chroma"
build_vector_index(force_rebuild=True)

You should see the three Chroma collections rebuilt. The chatbot launcher and the SEARCH skill need no other change.

Clean up

The Chroma index is a folder: delete ./tdfs4ds_chroma. A Teradata index is removed with tdfs4ds.agent.vector_store_teradata.reset_teradata_store() (admin rights). remove_process refreshes the index by default; pass refresh_index=False while tutorials are running.

Learn more