tdfs4ds.agent.eval_facts¶
tdfs4ds.agent.eval_facts
¶
Ground truth for the agent evaluation, read from the store (0.3.1.240).
Every expected fact of an evaluation turn is computed here, from the store,
through the same authorities the Report and the agent use: the catalog snapshot
at a valid time (store_consistency.collect_catalog_snapshot), the one count
definition (store_consistency.catalog_counts), the follow-up in business dates
(followup_business_dates), the persisted lineage graph at a valid time, the
business dictionary, and the process view DDL (sql_context). A disagreement
between the agent and these facts is then the agent's fault, not a second
definition's.
The facts are not the answer. They are what the judge checks the answer against: what must appear (names, figures, dates), what must not appear, and the business date the turn is about. Metadata (catalogs, business dictionary, lineage, datasets) carries real time as valid time and is ALWAYS read current; a turn's date applies to DATA only (feature values, run history / freshness).
Layers:
- :func:
collect_eval_facts- the only I/O: the store at a valid time. - :func:
build_facts- pure:(fact_spec, store) -> expected_facts. A turn keeps itsfact_spec, so the facts can be rebuilt at run time and a stale set detected (run_evaluation(refresh_facts=...)). - :func:
catalog_change_points, :func:pick_time_point- pure helpers choosing dates where the store at that date really differs from now.
_STOP
module-attribute
¶
_STOP = {'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'over', 'each', 'per', 'are', 'was', 'were', 'has', 'have', 'its', 'their', 'which', 'when', 'where', 'what', 'how', 'number', 'value', 'values', 'feature', 'features', 'computed', 'calculated', 'based', 'le', 'la', 'les', 'des', 'une', 'pour', 'par', 'dans', 'sur', 'avec', 'est', 'sont', 'total', 'average', 'mean', 'count', 'sum', 'data', 'given', 'used', 'using', 'between', 'column', 'represents', 'indicates', 'counts', 'measures', 'reflects', 'provides', 'within', 'across', 'specific', 'overall', 'calculates', 'calculated', 'number', 'amount', 'amounts', 'colonne', 'représente', 'indique', 'nombre', 'montant', 'chaque'}
_GENERATED_OPENING
module-attribute
¶
_GENERATED_OPENING = re.compile('^\\s*(this|the)\\s+(query|statement|sql|view|table)\\s+(creates|defines|builds|is|selects)\\b[^.]*\\.\\s*', re.I)
_SOURCE_STOP
module-attribute
¶
_SOURCE_STOP = {'query', 'queries', 'creates', 'view', 'views', 'named', 'selecting', 'columns', 'table', 'tables', 'source', 'direct', 'directly', 'access', 'read', 'only', 'provides', 'without', 'business', 'users', 'purpose', 'primary', 'ensures', 'ensuring', 'downstream', 'underlying', 'layer', 'records', 'record', 'information', 'consistency', 'structure', 'original', 'modification', 'modifying', 'transformations', 'filtering', 'representation', 'simplifies', 'centralize', 'related', 'applications', 'decision', 'making', 'reporting', 'analysis', 'analyze', 'enabling', 'retrieve', 'query', 'operational', 'help', 'helps', 'including', 'includes', 'while', 'preserving', 'standardize', 'referenced', 'abstracting'}
_BOILERPLATE
module-attribute
¶
_BOILERPLATE = re.compile('^\\s*(this|the)\\s+(column|feature|value|metric|field|variable)\\s+(represents|captures|shows|indicates|measures|reflects|provides|gives|is|contains|counts|records)\\s+(the\\s+|a\\s+|an\\s+)?', re.I)
_SOURCE_NOTE
module-attribute
¶
_SOURCE_NOTE = 'Source data: documented, but not a feature. It has no entity, no data domain, no run history; its key and the relations between its columns are not certain.'
_BUILDERS
module-attribute
¶
_BUILDERS = {'definition': _b_definition, 'explain': _b_explain, 'freshness': _b_freshness, 'lineage': _b_lineage, 'usage': _b_usage, 'dataset': _b_dataset, 'summary': _b_summary, 'data_domains': _b_data_domains, 'search': _b_search, 'feasibility': _b_feasibility, 'dataset_time': _b_dataset_time, 'static': _b_static, 'object': _b_object, 'source_object': _b_source_object, 'source_readers': _b_source_readers, 'source_column': _b_source_column, 'source_search': _b_source_search, 'plot': _b_plot, 'values': _b_values, 'data_query': _b_data_query}
show_text
¶
The rows of a SHOW statement joined into one text ('' for no row). Pure.
_norm_domains
¶
None / '' / [] -> None (every domain); a string or list -> a set of upper names.
scope_store
¶
Keep only the data domains named (pure, in place; None = unchanged).
Features, processes and datasets are filtered on their DATA_DOMAIN column
when the frame has one; the follow-up and process history follow the kept
processes. Without it facts are built from the whole store, which on a store
of several domains describes more than the conversation is about.
collect_eval_facts
¶
The store for :func:build_facts: the metadata CURRENT, the data (follow-up,
feature values) at the business date as_of (None = now). Fail-open:
a part that cannot be read is empty and its facts are skipped.
data_domains restricts it to those domains (default: the whole store).
_extremes_reader
¶
feature_extremes of one feature at t (cached; None when unreadable): the
VALUES turns' ground truth, computed in the database by the same function the
VALUES skill uses.
_manager_position
¶
The manager's current date and how many of its dates lie after the last one a process completed (independent of the agent's own computation).
features_index
¶
One record per feature triplet at the store's valid time.
_datasets_of
¶
Datasets reading this feature (triplet, through FEATURE_ID), with entity keys.
_names_at
¶
Feature names and process view names (upper) present in the store.
catalog_names
¶
Every real name of the store (upper): features, entities and their key columns, process views, datasets and their entity columns, documented objects and columns (source data included), lineage objects, managers. Pure.
The judge's list of names that are not inventions. It used to hold only what the agent's own context recorded, and clarifications and template answers (freshness, dataset lists) record almost nothing: every real name in them read as invented, whatever the judge model (0.3.7.29).
_is_manager_view
¶
A TimeManager / FilterManager view (or a soft clone): a view whose only read is a
*_HIDDEN table, or a name the manager index knows. Not source data.
source_objects
¶
Documented objects OUTSIDE the feature store (source data), with their documented
columns: [{database, object_name, object_type, description, columns: [{column_name,
description}]}], other databases than the store's first. Pure.
Inside / outside is the agent's own rule (documentation_export.object_scope):
process views, datasets, managers and FS_* objects are inside.
source_subject
¶
The words a user would ask about to find a source object: its description without a generated opening ("This query creates a view named X by selecting ..."), its own name and generic words left out, rarest across the source objects first. Pure.
source_readers
¶
The process views reading a source object (through views) and their features. Pure.
catalog_change_points
¶
Registration instants of every feature and process (UTC, sorted). Metadata history, no longer used to choose a turn's date (a date is a business date).
run_change_points
¶
Instants processes were registered or ran (UTC): real time, unlike feature catalog rows, which a TimeManager-driven run stamps with its business date.
pick_time_point
¶
A valid time between two registration instants, so the store at that time
differs from now: the middle of the widest gap, as YYYY-MM-DD when the gap
spans a midnight (the midnight after the earlier instant), else to the second
(UTC). None when every object was registered at once.
date_variants
¶
Forms a date may take in an answer: ISO, '30 June 2023', 'June 30, 2023', '30 juin 2023', '30/06/2023'.
content_words
¶
content_words(text: str, exclude: Iterable[str] = (), n: int = 4, frequency: Optional[Dict[str, int]] = None) -> List[str]
Words of a description that say what it is about. With frequency (how many descriptions of the store use each word), the rarest come first: they single the description out, where 'customer' or 'transaction' describe half the store.
description_phrase
¶
What a description is about, as a user would ask for it: its first sentence without the 'This column represents the' opening, cut at n_words.
word_frequency
¶
In how many of texts each word appears.
same_name
¶
Features carrying the same name (other entities, other domains).
_feature_core
¶
Identity facts. spec['scope'] == 'domain': the question names the domain;
spec['entity_known']: the conversation already fixed the entity (a pronoun
follow-up). Otherwise a name shared by several triplets expects the agent to
ask which one (or to answer for each).
build_facts
¶
Expected facts of one turn. store is the store at the spec's valid time;
store_now the current store (for absent_names). Raises nothing: an
object no longer found yields {"missing_object": ...} (the turn is stale).
facts_digest
¶
Stable digest of a facts dict (keys sorted, valid time included).