Skip to content

tdfs4ds.serve.bootstrap

tdfs4ds.serve.bootstrap

Runtime bootstrap for the tdfs4ds API server.

Establishes the Teradata connection, lets tdfs4ds load its own TDFS4DS_* configuration (SCHEMA, DATA_DOMAIN, INSTRUCT_MODEL_, EMBEDDING_MODEL_, CHROMA_*, VECTOR_STORE_BACKEND …), and optionally pre-builds the consumer-agent vector index so the first SEARCH does not pay a cold build.

The Teradata connection is not covered by tdfs4ds/config.py — that module loads feature-store / LLM / vector-store settings but never opens a database context. This bootstrap owns the connection and reads it directly from the environment:

TDFS4DS_TD_HOST        Teradata host (required)
TDFS4DS_TD_USERNAME    Teradata user (required for a password logon)
TDFS4DS_TD_PASSWORD    Teradata password (required for a password logon)
TDFS4DS_TD_LOGDATA     Token logon instead of a password, e.g. 'token=<jwt>'
                       (used only when no password is set)
TDFS4DS_TD_LOGMECH     Logon mechanism (optional, e.g. LDAP / TD2; JWT for a token)
TDFS4DS_TD_DATABASE    Default database for the session (optional)
TDFS4DS_TD_ENCRYPT     Enable wire encryption — 'true' or 'false' (optional)

Server-specific flags:

TDFS4DS_SERVE_BUILD_INDEX   'true' (default) builds the vector index at
                            startup; set 'false' for a QO-only deployment.

logger module-attribute

logger = getLogger('tdfs4ds.serve')

_bootstrapped module-attribute

_bootstrapped = False

CONNECTED module-attribute

CONNECTED = False

LAST_CONNECT_ERROR module-attribute

LAST_CONNECT_ERROR = None

_FORM_KEYS module-attribute

_FORM_KEYS = {'host': 'TDFS4DS_TD_HOST', 'username': 'TDFS4DS_TD_USERNAME', 'password': 'TDFS4DS_TD_PASSWORD', 'logmech': 'TDFS4DS_TD_LOGMECH', 'database': 'TDFS4DS_TD_DATABASE', 'encryptdata': 'TDFS4DS_TD_ENCRYPT'}

is_connected

is_connected() -> bool

connection_status

connection_status() -> dict

Small status payload for /health and the UI status dot.

_env

_env(name, default=None)

_truthy

_truthy(value, default=True)

_token_logon_kwargs

_token_logon_kwargs(host, password)

create_context kwargs for a token logon, or None for the password path.

Only when no password is available and TDFS4DS_TD_LOGDATA is set: the shape a platform that authenticates with a token gives (AI Studio: logmech='JWT', logdata='token=…'). The kwargs come from :func:tdfs4ds.utils.reconnect._connect_kwargs, the one place that maps TDFS4DS_TD_* onto a connection, so the startup logon and the automatic reconnect agree. With a password set this returns None and the historical path runs unchanged.

create_teradata_context

create_teradata_context()

Open a teradataml context from TDFS4DS_TD_* environment variables.

Returns the teradataml context object. Raises RuntimeError with a clear message when the mandatory connection variables are missing.

connect_error_text

connect_error_text(exc) -> str

A failed logon, with the errors it was raised from.

teradataml raises TDML_2000 Failed to connect to Teradata Vantage from the driver's error, which is the one naming the fault (bad password, LDAP refusal, unknown host, encryption setting). str(exc) keeps only the first, so the Connect page said nothing useful. Every message of the chain (__cause__, else __context__), whole, without the driver's Go frames.

_remember_credentials

_remember_credentials(kwargs: dict) -> None

connect_teradata

connect_teradata(host=None, username=None, password=None, logmech=None, database=None, encrypt=None, build_index=None)

Open (or re-open) the Teradata context and run post-connection setup.

Reusable by both the startup bootstrap and the in-app Connect page. Any credential left None falls back to the matching TDFS4DS_TD_* env var. On success, sets the module CONNECTED flag, applies tdfs4ds config and (optionally) builds the vector index. On failure, CONNECTED stays False and LAST_CONNECT_ERROR records the reason — the caller decides whether to raise.

Returns {"connected": bool, "error": str|None}.

_post_connect_setup

_post_connect_setup(build_index=None)

Apply tdfs4ds config (already loaded on import) and build the index.

_adopt_session_store

_adopt_session_store() -> str

Use the session's default database as the feature store when it holds one.

import tdfs4ds takes SCHEMA from the teradataml context, but the app imports tdfs4ds before it connects, so a logon with database= (the Connect page's Default database, or TDFS4DS_TD_DATABASE) left SCHEMA empty and every panel failed on FROM .FS_FEATURE_CATALOG (seen at a site). Adopted only when that database holds a complete feature store; returns its name, else ''. Never fails the startup.

_validate_read_stores

_validate_read_stores()

Attach the read-only stores named in the configuration properly.

TDFS4DS_SCHEMA_READONLY (or JSON schema_readonly) only sets tdfs4ds.SCHEMA_READONLY to plain names; nothing checked them or probed what they offer until a store switch in Parameters. extend_read_stores does both. Never fails the startup.

index_job_key

index_job_key(store=None) -> str

Status-bar key of a store's index build (one build per store at a time).

start_index_builds

start_index_builds(stores=None, force_rebuild: bool = False) -> list

Build the vector index, one job per store, shown in the status bar.

stores: database names or descriptors (default: every attached store, the primary first). Returns the job keys.

In the background only when it is safe: on Chroma, with the TDFS4DS_TD_* credentials to open a connection of its own (vector_index.own_connection), since a background read on teradataml's single shared connection breaks it for the whole process (seen live). The Teradata Vector Store backend works through teradataml throughout, so it builds in the calling thread, as before 0.3.3.15, for the primary only; so does Chroma when no connection of its own can be opened.

_index_summary

_index_summary(result) -> str

'objects 3 embedded / 40 unchanged, …' from a Chroma build summary ('' otherwise).

bootstrap

bootstrap(force: bool = False)

Idempotent, NON-FATAL server bootstrap.

Attempts the Teradata connection from TDFS4DS_TD_* env vars. If it fails (missing creds or unreachable host) the app still boots disconnected — the shell, /health and the in-app Connect page load, and the user can connect at runtime via POST /ui/connect. Safe to call more than once.