2. Documentation¶
Reference
The reference for this topic is Process documentation.
Needs an instruct model
This page calls a language model. Set INSTRUCT_MODEL_PROVIDER, INSTRUCT_MODEL_MODEL,
INSTRUCT_MODEL_API_KEY (and INSTRUCT_MODEL_URL or INSTRUCT_MODEL_REGION for your
provider) in the .env or in code, then check them with
tdfs4ds.check_configuration(). Without a model the calls below log that they are
skipped. See LLM & embedding models.
Goal: let an LLM write the business dictionary of the process from step 1: a description of the entity and of each feature, in plain words. The text is stored in the feature store and read by the consumer agent (module 4).
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 (the process of module 1, registered again if the session is new).
1 · Document the process¶
from tdfs4ds.genai import document_process_incremental
info = document_process_incremental(process_id, display=False, upload=True)
print(info["ENTITY_DESCRIPTION"])
You should see a short paragraph saying what one row represents (a customer, an
account, a machine, depending on your flavor) in business words. The function reads the
view's SQL and its EXPLAIN plan, asks the model for the description of the entity, the
business logic and every feature, and stores the answer (upload=True).
2 · Read the feature descriptions¶
for column, description in info["DOCUMENTED_FEATURE_COLUMNS"].items():
print(column, "-", description)
You should see one line per feature (nb_events, total_amount, avg_amount,
nb_partners), written from the SQL: how many ... the entity has, the total amount ....
The agent reads the stored copy of these texts.
3 · Document at registration time¶
The same step can be part of upload_features: document=True documents the process
right after it is registered, and cascade_redocumentation=True re-documents the
processes and datasets downstream when the text changed.
process_id = tdfs4ds.upload_features(
df=None,
sql_query=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""",
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=True, optimize_query=False, return_process_id=True,
)
You should see the same log as in module 1 plus the documentation lines. A person can also write or correct any text; an LLM run then keeps the human parts (Manual documentation).
Clean up¶
Nothing to remove: the documentation lives in the business dictionary tables of the store, dropped with the store. Module 13 lists the rest.
Learn more¶
- Process documentation
- Dataset documentation
- Business dictionary
- Recipes › Upload & document
- LLM & embedding models: required configuration before the LLM path runs.