fix: stop excluding measurement fields whose names contain "id" from metric detection - #4
Open
EAWRCEQA wants to merge 1 commit into
Open
Conversation
_detect_metric_field skipped any numeric field whose lowercased name contained the substring "id", which unintentionally matched common measurement columns such as width, humidity, grid_load and candidate_count. These aggregatable metrics were dropped from the auto-generated semantic layer on data upload. Match "id"/"_id" precisely (standalone name or _id suffix), mirroring the existing _detect_id_field logic, so real ID columns (id, vehicle_id, user_id) are still excluded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_detect_metric_field()inagentic_core/schema_inference.py:96decides whether a numeric column should become an aggregatable metric in the auto-generated semantic layer. It excludes "ID-like" fields with a substring test:Because
"id"is checked as a substring, it matches any field name that merely contains those two letters. Common measurement columns are silently dropped from metrics:width,humidity,grid_load,candidate_count, and similar. On data upload (POST /api/data/upload→infer_schema), these valid metrics never make it into the semantic layer, so the assistant can't aggregate them.Note this is inconsistent with the sibling function
_detect_id_field()(same file), which already matches ID patterns precisely viaendswith/ equality rather than substring.Reproduction
Loading the module and calling
infer_schemaon genuine (non-ID, low-cardinality) float measurements:widthandhumidityhaveis_id=False— they are legitimate metrics — yet are excluded purely because their names containid.Fix
Match
id/_idprecisely (standalone name or_idsuffix), mirroring_detect_id_field:After the fix, the same input yields:
and real ID columns are still excluded (
id,vehicle_id,user_id→ not metrics).Verification
python -m py_compile agentic_core/schema_inference.pypasses.strandsimport) before and after the change; confirmed the excluded measurement fields are recovered and thatid/*_idcolumns stay excluded.The change is limited to the name-matching heuristic in
_detect_metric_field; thecode/编号/year/月/日matches are preserved unchanged.