Skip to content

Fixes #36463: use the configured vector service for find_context and company_context on Elasticsearch - #36517

Closed
zerafachris wants to merge 2 commits into
open-metadata:mainfrom
zerafachris:fix-36463-es-vector
Closed

zerafachris wants to merge 2 commits into
open-metadata:mainfrom
zerafachris:fix-36463-es-vector

Conversation

@zerafachris

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36463

Root cause: SearchRepository.initializeVectorSearchService() creates OpenSearchVectorService only when the search backend is OpenSearch. On Elasticsearch it creates ElasticSearchVectorService and stores it in SearchRepository.vectorIndexService, so OpenSearchVectorService.getInstance() stays null. AIContextFinder.searchKnowledge() and CompanyContextTool.runSearch() both read that OpenSearch-only singleton. As a result find_context / GET /api/v1/ai/context/find silently returned nothing, and company_context reported "Semantic search is not enabled", even though semantic_search works on the same index.

What changed: both call sites now use Entity.getSearchRepository().getVectorIndexService(), the backend-neutral VectorIndexService already used by the rest of the vector pipeline. This is the change the reporter proposed in the issue (thanks @MostafaAbdelsalam11). The methods they call (search(...), including the SubjectContext overload) are on the interface, and ElasticSearchVectorService applies the same context-memory visibility filtering (readableAnchorIds) as the OpenSearch implementation.

Scope: only the two call sites named in the issue. AIContextBuilder.queryRelevantExcerpt still reads the OpenSearch singleton because searchChunksByParent is not on VectorIndexService and has no Elasticsearch implementation, so excerpts stay absent on Elasticsearch exactly as before (no regression). The remaining getInstance() callers (VectorSearchUtils, RecreateWithEmbeddings, OpenMetadataOperations, OpenSearchBulkSink, DistributedJobParticipant) are OpenSearch-specific paths and are out of scope here.

Tests:

  • New AIContextFinderTest.findSearchesTheConfiguredVectorServiceOnElasticsearch: fails on main (the vector service is never queried) and passes with the fix. AIContextFinderTest: 10/10.
  • New CompanyContextToolTest.searchRunsOnTheElasticsearchVectorService: fails on main (the "not enabled" error is returned) and passes with the fix. CompanyContextToolTest: 18/18.
  • The three existing CompanyContextToolTest search tests stubbed OpenSearchVectorService.getInstance() statically. They now stub searchRepository.getVectorIndexService() instead. Assertions are unchanged.
  • mvn spotless:check passes for openmetadata-service and openmetadata-mcp.

Prepared with AI assistance (Claude Code, Anthropic), reviewed for correctness before submission.

Type of change:

  • Bug fix

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • I have added tests around the new logic.

…_context and company_context on Elasticsearch

AIContextFinder and CompanyContextTool read the OpenSearchVectorService
singleton, which is only created when the search backend is OpenSearch.
Read the backend-neutral VectorIndexService held by SearchRepository instead.
@zerafachris
zerafachris requested a review from a team as a code owner October 29, 2026 06:44
@zerafachris
zerafachris requested a review from IceS2 October 29, 2026 06:44
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@zerafachris

Copy link
Copy Markdown
Contributor Author

@pmbrull @Vishnuujain Ready for review and safe to test when you get a chance — thanks!

@harshach harshach added the safe to test Add this label to run secure Github workflows on PRs label Nov 2, 2026
@github-actions github-actions Bot removed the safe to test Add this label to run secure Github workflows on PRs label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@gitar-bot

gitar-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Using the configured vector service restores Elasticsearch results for find_context and company_context; inaccurate matches could add irrelevant material to responses.

Switches AIContextFinder.searchKnowledge() and CompanyContextTool.runSearch() to use the backend-neutral VectorIndexService from Entity.getSearchRepository().getVectorIndexService(), so find_context and company_context work on Elasticsearch instead of silently returning nothing. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@pmbrull

pmbrull commented Nov 4, 2026

Copy link
Copy Markdown
Member

hi thank you, closing in favor of #36548 since it's same approach 🙏

@pmbrull pmbrull closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP find_context and company_context return no results on Elasticsearch (OpenSearchVectorService singleton is null)

4 participants