Skip to content

tdfs4ds.genai.operator_context

tdfs4ds.genai.operator_context

Context for in-database operators a documented SQL calls (0.3.5.15).

A view that scores a BYOM model (ONNXPredict ...) or compresses time series with ts_compress_to (td-ts-compressor) is opaque to the LLM: it sees a function call and string parameters, not what they compute nor which model is used. Each handler in tdfs4ds.genai.operators recognises its operators in the SQL and writes a fixed text block the documentation and the agent's EXPLAIN give the LLM as ground truth.

A handler is a module with three functions:

  • detect(sql) -> list[dict]: pure; one dict per call found, [] when none.
  • collect(found) -> list[dict]: reads what the database knows (a model table's rows); fail-open, returns found (possibly enriched) and never raises.
  • render(items) -> str: pure; the text block, '' for nothing.

Rule: a SQL calling no known operator gets '', so every other prompt is unchanged.

HANDLERS module-attribute

HANDLERS = ('tdfs4ds.genai.operators.byom', 'tdfs4ds.genai.operators.ts_compress')

HEADER module-attribute

HEADER = '\n\nIN-DATABASE OPERATORS CALLED BY THIS SQL (read from the SQL and the database by code; ground truth: describe what they compute in business terms and never contradict this):\n'

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

detect_operators

detect_operators(sql: str) -> List[dict]

Every known operator call in sql, each dict tagged with its handler. Pure, never raises.

operator_context

operator_context(sql: str, *, read: bool = True) -> str

The block for sql, '' when it calls no known operator.

read: let handlers read the database (model rows); False keeps it pure.