Skip to content

Fixes AI Platform #1262: Apply persona scope to MCP search - #32919

Merged
pmbrull merged 2 commits into
open-metadata:mainfrom
pmbrull:pmbrull/fix-ai-platform-1262
Sep 10, 2026
Merged

pmbrull merged 2 commits into
open-metadata:mainfrom
pmbrull:pmbrull/fix-ai-platform-1262

Conversation

@pmbrull

@pmbrull pmbrull commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes open-metadata/ai-platform#1262

Resolves #32457, the parent feature that introduced persona search scopes for AI search tools.

MCP keyword and semantic searches now apply the active user's persona search scope by default. The tools expose ignorePersonaScope for an explicit retry beyond that scope after a scoped miss or user request.

The change also preserves X-OpenMetadata-Persona through the MCP transport, composes persona and caller filters with AND semantics, and adds compiled-query-filter support to both Elasticsearch and OpenSearch vector searches.

Type of change:

  • Bug fix

High-level design:

  • Resolve the active or default persona through the existing PersonaContextAccess path and compile its rules with PersonaContextBuilder, keeping persona scope a relevance preference rather than an authorization boundary.
  • Conjoin the compiled scope with caller filters for search_metadata; forward the same raw DSL filter to both vector backends for semantic_search.
  • Carry the active-persona header through the stateless MCP context so the existing SubjectContext membership validation selects only an assigned persona.
  • Preserve existing constructors and vector-search overloads for compatibility. Backends that do not support compiled vector filters fail explicitly instead of silently widening results.
  • If no usable persona scope exists, retain the existing unscoped behavior. Empty scoped results explain how to request an explicit unscoped retry.

Tests:

Use cases covered

  • An assigned active persona limits MCP keyword results to assets selected by its search rule.
  • Caller filters and persona filters are both enforced.
  • Semantic search forwards the same compiled persona scope to Elasticsearch and OpenSearch queries.
  • ignorePersonaScope=true preserves the existing unscoped keyword and semantic search paths.
  • Missing or invalid persona scopes degrade safely to the existing unscoped relevance behavior.
  • The active-persona header survives MCP context extraction and JWT security-context reconstruction.

Unit tests

  • Added and updated service and MCP unit tests for the new behavior.
  • openmetadata-service: 130 focused tests passed; changed-line coverage is 95.45%, with every touched production file at or above 90%.
  • openmetadata-mcp: 630 tests passed; changed-line coverage is 96.70%, with every touched production file at or above 90%.

Commands:

mvn -pl openmetadata-service org.jacoco:jacoco-maven-plugin:0.8.10:prepare-agent -DskipTests=false -Dtest=VectorSearchQueryBuilderTest,VectorIndexServiceTest,ElasticSearchVectorServiceTest,OpenSearchVectorServiceTest,PersonaContextBuilderTest,JwtFilterTest test org.jacoco:jacoco-maven-plugin:0.8.10:report
mvn -pl openmetadata-mcp org.jacoco:jacoco-maven-plugin:0.8.10:prepare-agent -DskipTests=false test org.jacoco:jacoco-maven-plugin:0.8.10:report
mvn spotless:check

Backend integration tests

  • Added an end-to-end MCP scenario to PersonaAIContextIT covering default scoping and explicit bypass with a real MySQL, Elasticsearch, application, and MCP server stack.
  • 8 PersonaAIContextIT tests passed.
mvn -pl openmetadata-integration-tests -Dit.test=PersonaAIContextIT -DintegrationTests.skipIsolated=true -DintegrationTests.skipParallel=false verify

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Tested against a locally running OpenMetadata and MCP server with real OpenSearch embeddings:

  1. Created a temporary persona assigned to the authenticated user with a scoped rule selecting one indexed table.
  2. Called search_metadata without the bypass flag and verified only the selected table was returned; ignorePersonaScope=true returned both tables allowed by the caller filter.
  3. Verified an empty scoped keyword search explains how to retry with ignorePersonaScope=true.
  4. Called semantic_search without the bypass flag and verified only the selected table was returned; the explicit bypass returned all five relevant embedded tables.
  5. Hard-deleted the temporary persona after the smoke test.

UI screen recording / screenshots:

Not applicable; there are no UI changes.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>.
  • My PR is linked to a GitHub issue via the cross-repository Fixes reference above.
  • I have commented on the non-obvious filter-composition and compatibility behavior.
  • JSON Schema migrations are not applicable; this change does not modify a schema.
  • UI recordings are not applicable; this change does not modify the UI.
  • I have added tests and listed them above.
  • I have added a test that covers the exact bug scenario.

Copilot AI lite review requested due to automatic review settings September 8, 2026 06:46
@pmbrull
pmbrull requested a review from a team as a code owner September 8, 2026 06:46

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 Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Sep 8, 2026
Comment on lines +118 to 132
Optional<PersonaSearchScope> personaScope = personaSearchScope(securityContext, params);
VectorSearchParameters searchParameters =
new VectorSearchParameters(
query,
filters,
size,
from,
k,
threshold,
null,
null,
personaScope.map(PersonaSearchScope::queryFilter).orElse(null));

try {
VectorSearchResponse response =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: Persona filter forwarded verbatim to embedding index may match nothing

SemanticSearchTool now forwards the persona's compiled searchScope queryFilter (raw DSL authored against the regular entity/dataAsset indexes) to the vector search, which queries the separate data_asset_embeddings_chunks (dataAssetEmbeddings) index. That chunk index carries denormalized fields (entityType, tags, owners, tier, service, fullyQualifiedName) but its mapping can differ from the entity index — e.g. analyzed .keyword subfields or nested owner structures a persona rule references may be unmapped there — so a term/terms clause silently matches zero documents. A persona whose scope works correctly for search_metadata could then make every semantic_search return empty, and since scope now applies by default (falling back to the user's default persona even when no X-OpenMetadata-Persona header is sent), affected users lose semantic results until they retry with ignorePersonaScope=true. Consider validating/translating persona filter fields against the embedding index mapping, or documenting the field constraints persona rules must satisfy to remain semantic-search compatible. The empty-result annotation that suggests the bypass partially mitigates this, but the degradation is silent.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Applies persona search scope to MCP keyword and semantic searches, with ignorePersonaScope for explicit bypass. Persona and caller filters compose with AND semantics, the active-persona header survives MCP transport, and vector backends fail explicitly on unsupported filters. Comprehensive test coverage includes 95.45% changed-line coverage in the service layer and an end-to-end integration scenario.

Consider validating or translating persona filter fields against the embedding index mapping before forwarding to semantic search, since the chunk index may lack subfields (e.g., .keyword variants or nested structures) that the persona rule references, causing silent zero-match results. The empty-result annotation suggests a bypass, but the degradation is not obvious to users until they retry with ignorePersonaScope=true.

💡 Edge Case: Persona filter forwarded verbatim to embedding index may match nothing

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/SemanticSearchTool.java:118-132 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorSearchQueryBuilder.java:394-404

SemanticSearchTool now forwards the persona's compiled searchScope queryFilter (raw DSL authored against the regular entity/dataAsset indexes) to the vector search, which queries the separate data_asset_embeddings_chunks (dataAssetEmbeddings) index. That chunk index carries denormalized fields (entityType, tags, owners, tier, service, fullyQualifiedName) but its mapping can differ from the entity index — e.g. analyzed .keyword subfields or nested owner structures a persona rule references may be unmapped there — so a term/terms clause silently matches zero documents. A persona whose scope works correctly for search_metadata could then make every semantic_search return empty, and since scope now applies by default (falling back to the user's default persona even when no X-OpenMetadata-Persona header is sent), affected users lose semantic results until they retry with ignorePersonaScope=true. Consider validating/translating persona filter fields against the embedding index mapping, or documenting the field constraints persona rules must satisfy to remain semantic-search compatible. The empty-result annotation that suggests the bypass partially mitigates this, but the degradation is silent.

🤖 Prompt for agents
Code Review: Applies persona search scope to MCP keyword and semantic searches, with `ignorePersonaScope` for explicit bypass. Persona and caller filters compose with AND semantics, the active-persona header survives MCP transport, and vector backends fail explicitly on unsupported filters. Comprehensive test coverage includes 95.45% changed-line coverage in the service layer and an end-to-end integration scenario.
  
  Consider validating or translating persona filter fields against the embedding index mapping before forwarding to semantic search, since the chunk index may lack subfields (e.g., `.keyword` variants or nested structures) that the persona rule references, causing silent zero-match results. The empty-result annotation suggests a bypass, but the degradation is not obvious to users until they retry with `ignorePersonaScope=true`.

1. 💡 Edge Case: Persona filter forwarded verbatim to embedding index may match nothing
   Files: openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/SemanticSearchTool.java:118-132, openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorSearchQueryBuilder.java:394-404

   SemanticSearchTool now forwards the persona's compiled searchScope queryFilter (raw DSL authored against the regular entity/dataAsset indexes) to the vector search, which queries the separate `data_asset_embeddings_chunks` (dataAssetEmbeddings) index. That chunk index carries denormalized fields (entityType, tags, owners, tier, service, fullyQualifiedName) but its mapping can differ from the entity index — e.g. analyzed `.keyword` subfields or nested owner structures a persona rule references may be unmapped there — so a term/terms clause silently matches zero documents. A persona whose scope works correctly for search_metadata could then make every semantic_search return empty, and since scope now applies by default (falling back to the user's default persona even when no X-OpenMetadata-Persona header is sent), affected users lose semantic results until they retry with ignorePersonaScope=true. Consider validating/translating persona filter fields against the embedding index mapping, or documenting the field constraints persona rules must satisfy to remain semantic-search compatible. The empty-result annotation that suggests the bypass partially mitigates this, but the degradation is silent.

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

Copilot AI review requested due to automatic review settings September 8, 2026 08:43

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 safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Sep 8, 2026
@pmbrull
pmbrull added this pull request to the merge queue Sep 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-09-09T10:58:31Z)

Blocked the queue: integration-tests-postgres-opensearch

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

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-09-10T00:02:54Z)

Blocked the queue: playwright-summary

@pmbrull
pmbrull added this pull request to the merge queue Sep 10, 2026
Merged via the queue into open-metadata:main with commit 10cdd0f Sep 10, 2026
141 checks passed
@pmbrull
pmbrull deleted the pmbrull/fix-ai-platform-1262 branch September 10, 2026 09:57

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Persona AI Context is hidden in Settings and preloads every rule

3 participants