Skip to content

Fixes 34861: Resolve glossary and metric concept context - #34863

Merged
pmbrull merged 13 commits into
mainfrom
pmbrull/openmetadata-ticket-prepare
Oct 10, 2026
Merged

pmbrull merged 13 commits into
mainfrom
pmbrull/openmetadata-ticket-prepare

Conversation

@pmbrull

@pmbrull pmbrull commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #34861

Agents can now resolve glossary terms and metrics to definitions, exact asset/column bindings, profiles, samples, related metrics, and saved-query evidence through entity context and the new get_concept_context MCP tool.

OpenMetadata portion of open-metadata/ai-platform#1586; ai-platform clients, SQL prompt integration, and benchmarks remain in that repository.

Example response

Glossary term Finance.Revenue (synonyms, one ontology attribute) tagged on column amount_cents of table warehouse.analytics.sales.orders, which has a table profile (1,200 rows), a column profile and five stored sample rows. Captured from a local server built from this branch:

GET /api/v1/glossaryTerms/name/Finance.Revenue/context?format=json (the MCP get_concept_context JSON output is identical)

{
  "id": "49e3b6ce-e7f2-4b49-8664-09622eab2fcc",
  "name": "Revenue",
  "fullyQualifiedName": "Finance.Revenue",
  "entityType": "glossaryTerm",
  "description": "Recognized revenue for an order, stored in integer cents (divide by 100 for USD).",
  "tags": [],
  "glossaryTerms": [],
  "metrics": [],
  "articles": [],
  "upstream": [],
  "downstream": [],
  "upstreamEdges": [],
  "downstreamEdges": [],
  "assetContext": {
    "conceptContext": {
      "definition": "Recognized revenue for an order, stored in integer cents (divide by 100 for USD).",
      "synonyms": [
        "Sales",
        "Turnover"
      ],
      "relatedTerms": [],
      "attributes": [
        {
          "id": "6f1c1d7e-0b7a-4a52-9d55-0a2f0b8e8a01",
          "name": "amount",
          "dataType": "INTEGER",
          "unit": "cents",
          "enumValues": [],
          "isIdentifier": false,
          "inherited": false
        }
      ],
      "bindings": [
        {
          "assetFqn": "warehouse.analytics.sales.orders",
          "assetType": "table",
          "column": "warehouse.analytics.sales.orders.amount_cents",
          "dataType": "bigint",
          "rowCount": 1200.0,
          "profile": {
            "name": "amount_cents",
            "nullProportion": 0.01,
            "distinctCount": 1103.0,
            "min": "0",
            "max": "125000",
            "mean": 4870.5
          },
          "sampleValues": [
            1999,
            4500,
            125000,
            null,
            0
          ]
        }
      ],
      "totalAssets": 1,
      "totalBindings": 1,
      "truncated": false,
      "metrics": [],
      "evidence": []
    }
  },
  "generatedAt": 1791446844139
}
Same request without format=json (Markdown, the MCP default)
---
type: "glossaryTerm"
title: "Finance.Revenue"
description: "Recognized revenue for an order, stored in integer cents (divide by 100 for USD)."
fullyQualifiedName: "Finance.Revenue"
timestamp: "2026-10-08T08:07:24.195Z"
---

Recognized revenue for an order, stored in integer cents (divide by 100 for USD).

# Concept Definition

Recognized revenue for an order, stored in integer cents (divide by 100 for USD).

**Synonyms:** Sales, Turnover

# Ontology Attributes

| Attribute | Type | Unit | Allowed values |
|---|---|---|---|
| amount | INTEGER | cents |  |

# Concept Bindings

| Asset | Type | Column | Data type |
|---|---|---|---|
| warehouse.analytics.sales.orders | table | warehouse.analytics.sales.orders.amount_cents | bigint |

Stored samples for `warehouse.analytics.sales.orders.amount_cents`: 1999, 4500, 125000, NULL, 0 (representative rows; never count or aggregate over them).

# Bound Profiles

| Asset | Rows | Column | Null % | Distinct | Min | Max |
|---|---|---|---|---|---|---|
| warehouse.analytics.sales.orders | 1200 | warehouse.analytics.sales.orders.amount_cents | 1% | 1103 | 0 | 125000 |

Bindings on non-table assets carry the asset (and field) only; from the same live run, with service names shortened:

{"assetFqn": "kafka.order_events", "assetType": "topic", "column": "kafka.order_events.payload.amount", "dataType": "LONG"},
{"assetFqn": "superset.revenue_board", "assetType": "dashboard"},
{"assetFqn": "superset.model.revenue_model", "assetType": "dashboardDataModel", "column": "superset.model.revenue_model.model_amount_cents", "dataType": "bigint"}

Type of change:

  • Breaking change

High-level design:

AIContextBuilder composes a catalog boundary, a conservative Calcite identifier resolver, and a concept Markdown renderer, sharing the REST/MCP authorization and existing profile/sample masking paths.

  • Schema-first ConceptContext, ConceptBinding, and ConceptEvidence; regenerated Java/Python models and checked-in TypeScript types
  • Exact glossary tag bindings on every data asset type (tables, dashboards, data models, containers, topics, API endpoints, search indexes, ML models, pipelines, ...), resolved at asset level and at column/field level through ChildFieldResolver
  • Metric APPLIED_TO assets of any type, with unambiguous expression columns resolved on tabular assets (table, dashboard data model, container, worksheet); context memories that share the metric's APPLIED_TO edge are evidence, not bindings
  • Table bindings carry rowCount and the bound column's profile (both gated by VIEW_DATA_PROFILE) plus stored samples (VIEW_SAMPLE_DATA + PII masking); bindings without samples omit sampleValues
  • Search cursors and relationship pagination; ten visible assets, 25 bindings per asset, real visible totals, and truncated
  • Approved source/attached memories to saved Query ids; twenty evidence entries and 4,000-character query excerpts, with execution status omitted when unknown
  • Existing 8K content budget shared by articles, memories, associated metrics, and field glossary definitions
  • Calcite identifier semantics to avoid literal/output-alias matches; unsupported expressions and multiple SELECT scopes retain source assets without guessed columns

Column glossary definitions now live at assetContext.table.columns[].glossaryTerms instead of the flattened envelope list, so consumers must read that field; metric generic.definition and sourceAssets remain available, and no database migration is needed because these schemas describe responses only.

Tests:

Use cases covered

  • Exact and nested bindings; quoted column names; metric aliases and ambiguous/nested SQL scopes
  • Bindings on dashboards, dashboard data-model columns and nested topic schema fields; metric column resolution on data models but not on schema fields
  • Table rowCount on asset- and column-level bindings, absent without VIEW_DATA_PROFILE
  • Context memories attached to a metric are evidence, not bindings or totals
  • Asset and column caps with complete visible totals
  • Denied assets and independent profile/sample permissions; PII masking
  • Ontology units, enum values, typed relations, and section-aware Markdown
  • Saved-query provenance, deletion, excerpts, and unknown execution status
  • JSON/Markdown MCP parity and unchanged Mode B glossary routing

Unit tests

  • Added/updated tests for the changed logic
  • 115 focused unit tests passed (112 service, 3 MCP)
  • Service package: openmetadata-service/src/test/java/org/openmetadata/service/aicontext/
    • AIContextBuilderTest.java, AIContextMarkdownTest.java, AIContextFinderTest.java
    • ConceptContextBuilderTest.java, ConceptContextCatalogTest.java, ConceptContextMarkdownTest.java
  • MCP: openmetadata-mcp/src/test/java/org/openmetadata/mcp/tools/GetConceptContextToolTest.java
  • JaCoCo line coverage on new production classes (unit + ConceptContextIT combined):
Class Line coverage
ConceptContextBuilder 98.0%
ConceptContextCatalog 91.5%
ConceptContextMarkdown 99.3%
MetricColumnResolver 96.8%
GetConceptContextTool 96.2%
  • Changed executable lines in existing AIContextBuilder, AIContextFinder, AIContextMarkdown, and DefaultToolContext: 100% (coverage scope is the changed lines, not their entire existing classes)

Backend integration tests

  • Added REST/MCP integration coverage
  • 33 tests passed against real PostgreSQL and OpenSearch containers (ConceptContextIT 18, AIContextRestIT 9, AIContextMcpIT 6)
  • Added openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/mcp/ConceptContextIT.java
  • Regression suites: AIContextRestIT, AIContextMcpIT

Ingestion integration tests

  • Not applicable — no ingestion implementation changes

Playwright (UI) tests

  • Not applicable — regenerated transport types only; no rendered UI or user workflow changes

Manual testing performed

  • Automated REST/MCP scenarios against the local container stack; no manual UI testing
  • 72 live REST/MCP checks against a server built from this branch (MySQL + Elasticsearch, admin and restricted users): term/metric definitions, attributes and relations; table, dashboard, data-model and topic-field bindings; caps and totals; alias/ambiguity/subquery resolution; profiles, rowCount, samples and PII masking; deny rules for view, profile and sample access; saved-query evidence (approved vs draft memories, excerpts, deletion); JSON/Markdown and REST/MCP parity; MCP and REST error paths
  • make generate, isolated TypeScript validation, UI checkstyle, Spotless, pre-commit, and git diff --check passed
  • Reproduction:
mvn -pl openmetadata-integration-tests -am verify -Ppostgres-opensearch \
  -Dtest=AIContextBuilderTest,ConceptContextBuilderTest,ConceptContextCatalogTest,ConceptContextMarkdownTest,AIContextMarkdownTest,AIContextFinderTest,GetConceptContextToolTest \
  -Dsurefire.failIfNoSpecifiedTests=false \
  -Dit.test=ConceptContextIT,AIContextRestIT,AIContextMcpIT \
  -Dfailsafe.failIfNoSpecifiedTests=false \
  -DintegrationTests.skipIsolated=true

UI screen recording / screenshots:

Not applicable — no rendered UI changes

Checklist:

  • Read the repository's CONTRIBUTING.md
  • PR title follows Fixes <issue-number>: <short explanation>
  • Linked issue via Fixes #34861
  • Comments explain non-obvious SQL scope handling
  • JSON Schema migration rationale included above
  • Applicable unit/integration tests listed above
  • Documented the response contract and limits in JSON Schema and MCP metadata
  • Backward-Incompatible-Change label for the column glossary placement change
  • UI recording: not applicable — transport types only

Collate worker configuration companion: https://github.com/open-metadata/openmetadata-collate/pull/7498; the ai-platform client and SQL integration merged in https://github.com/open-metadata/ai-platform/pull/1696.

Keep glossary definitions on their columns and resolve bounded concept context through REST and MCP.

Refs #34861
Refs open-metadata/ai-platform#1586
@pmbrull
pmbrull requested a review from a team as a code owner October 7, 2026 16:19
Copilot AI balanced review requested due to automatic review settings October 7, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 7, 2026
- Glossary bindings now search the data-asset alias instead of the table
  index, excluding column, glossary term, tag and article documents, and
  resolve field-level bindings through ChildFieldResolver (data model and
  container columns, topic/API schema fields, search index fields, ML
  features, pipeline tasks).
- Metric expressions resolve SQL identifiers against any column-bearing
  asset (table, dashboard data model, container, worksheet).
- Context memories attached to a metric share its APPLIED_TO edge; they are
  no longer reported as bindings or counted in totals.
- ConceptBinding.rowCount carries the bound table's latest profiled row
  count, gated by VIEW_DATA_PROFILE like the column profile. Markdown
  renders it in a "Bound Profiles" table; counts print as integers.
- Bindings without stored samples omit sampleValues instead of returning [].
- ConceptContextIT covers non-table bindings, memory evidence vs bindings,
  nested and asset-level bindings, per-asset caps, alias/ambiguity
  resolution, related metrics, draft evidence and long-query excerpts,
  Markdown sections, MCP errors and row counts.
Copilot AI balanced review requested due to automatic review settings October 8, 2026 08:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 76%
76.32% (120386/157738) 62.28% (74597/119762) 63.72% (24919/39101)

… scope alias handling to ORDER BY

- Stop scanning concept candidates after 500 assets; mark the context truncated and
  treat totals as lower bounds. A capped metric scan resolves no columns, since
  unscanned assets could make them ambiguous.
- Compare SQL identifier components against structured field paths so a quoted
  "amount.cents" column and a nested amount.cents field stay distinct.
- Only ORDER BY resolves bare names to projection aliases; WHERE, GROUP BY and
  HAVING keep the input column binding.
Copilot AI balanced review requested due to automatic review settings October 8, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🔄 Playwright impact map auto-refreshed

This PR touched specs or UI source that changed the source→spec routing map. I regenerated .github/playwright/impact-map.generated.json and pushed the diff to this branch.

- source entries: 852 → 853
- 1 added, 0 removed, 18 changed spec-list

New source→spec entries:
  openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/isolatedUser.ts

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/constant/config.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/domain/DataProduct.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/BundleTestSuiteClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/fixtures/userPages.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/persona/PersonaClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/admin.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/common.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/entity.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/waitHelpers.ts
  openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx
  … and 8 more

What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing getByTestId strings. Hand-authored routing in impact-map.json always wins on conflict.

What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit:

python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit  # or a separate commit

Copilot AI balanced review requested due to automatic review settings October 8, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/, public/jsons/) have been automatically updated
based on JSON schema changes in this PR.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 09:29
@pmbrull
pmbrull enabled auto-merge October 9, 2026 06:14
Copilot AI balanced review requested due to automatic review settings October 9, 2026 06:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pmbrull
pmbrull added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-09T09:00:48Z)

Blocked the queue: integration-tests-postgres-opensearch

@pmbrull
pmbrull added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-09T14:42:48Z)

Blocked the queue: integration-tests-postgres-opensearch

A glossary term's context found its tagged assets with the query
`** AND (tags.tagFQN:"<fqn>")` on the data-asset alias. The data-asset
query builder also runs that text through a multi_match over every
search field, so a long FQN overflowed OpenSearch's 1024-clause limit:
20 of 24 shards failed and the context returned 500
(GlossaryTermResourceIT.get_entityAiContext_200_OK in the
postgres-opensearch merge-queue lane; Elasticsearch allows more clauses).

Match the tag with a term filter under a match-all query, so the clause
count no longer depends on the FQN. tagSearchRequest now takes the
entity types to exclude, so Mode B's glossary routing gets the same fix.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 15:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · The new concept-context APIs expose profiles, samples, and saved-query SQL under permission checks, so authorization mistakes could leak sensitive catalog data.

Adds glossary and metric concept context to entity responses and the new get_concept_context MCP tool, with exact asset and column bindings, profiles, samples, and saved-query evidence. Two earlier issues were resolved: concept resolution no longer loads every candidate table without a bound, and column glossary terms are now resolved once per table instead of separately for every column. No open issues remain.

✅ 2 closed
✅ Performance: Concept resolution loads every candidate table, with no upper bound

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextBuilder.java:126-140 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextBuilder.java:173-187 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextBuilder.java:222-233 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextCatalog.java:77-91 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/ConceptContextCatalog.java:136-146
scanCandidates keeps paging until the search or relationship source runs out. For every candidate it calls catalog.canView and then catalog.table(reference), which loads the full entity with columns and tags. Only ten assets are kept, but every candidate is loaded to compute totalAssets/totalBindings. A glossary term tagged on thousands of tables, or a metric applied to many assets, will cost thousands of DB loads and policy checks on each REST/MCP context request. The metric path also loads the retained tables a second time in addMetricBindings. This is easy to trigger with popular terms and can make the endpoint slow or time out.

Fix: put a hard cap on how many candidates are scanned (for example a few pages). When the cap is hit, set truncated=true and treat the totals as lower bounds. Alternatively, get counts from search aggregations instead of loading each entity. Also cache the loaded Table objects in the metric path so retained tables are not fetched twice.

✅ Performance: Column glossary terms are fetched separately for every column

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/AIContextBuilder.java:1081 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/AIContextBuilder.java:1101-1110 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/AIContextBuilder.java:1253-1267
resolveFieldGlossary runs once per FieldContext, and the list now includes nested children flattened into it. For each glossary FQN on a field it calls toGlossaryKnowledgeItem, which does an Entity.getEntityByName DB read plus an authorizer.authorize call. Nothing is shared between columns, so a wide or deeply nested table where many columns carry the same term (for example 500 columns tagged PII-like business terms) costs hundreds of identical lookups on every get_asset_context request. Resolve each distinct FQN once per build and reuse the result: collect the distinct FQNs across all fields, resolve them into a Map<String, KnowledgeItem>, and fill each field from that map. A computeIfAbsent cache gives the same result.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

❌ UI Checkstyle Failed

❌ Bundle Runtime Check

A route chunk loads but one of its chunks still exports undefined: a chunking change broke module initialisation. Run yarn build && yarn bundle:runtime locally.


Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@pmbrull
pmbrull added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-09T20:23:13Z)

Blocked the queue: integration-tests-postgres-opensearch

@pmbrull
pmbrull added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-09T20:58:29Z)

Blocked the queue: py-tests-status, py-tests-status, java-checkstyle, py-checkstyle

@pmbrull
pmbrull added this pull request to the merge queue Oct 10, 2026
Merged via the queue into main with commit af7152d Oct 10, 2026
81 checks passed
@pmbrull
pmbrull deleted the pmbrull/openmetadata-ticket-prepare branch October 10, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backward-Incompatible-Change Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve glossary terms and metrics to physical AI context bindings

5 participants