Skip to content

Fixes #35640: Clamp num_candidates to Elasticsearch engine maximum of 10000 - #35652

Merged
pmbrull merged 3 commits into
mainfrom
detail/bug-fix/fixes-35640-clamp-num-candidates-to-elasticsearch-4e5a21
Oct 20, 2026
Merged

pmbrull merged 3 commits into
mainfrom
detail/bug-fix/fixes-35640-clamp-num-candidates-to-elasticsearch-4e5a21

Conversation

@detail-app

@detail-app detail-app Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #35640

I clamped num_candidates to Elasticsearch's engine maximum of 10,000 in VectorSearchQueryBuilder.buildNativeESQuery, because the query builder previously computed num_candidates = k × multiplier with only an Integer.MAX_VALUE overflow guard. With the default knnNumCandidatesMultiplier of 2, any k > 5,000 — including the API's own advertised MAX_K = 10,000 — produced num_candidates > 10,000, which Elasticsearch hard-rejects with a 400. The service converted that 400 into an opaque HTTP 500 ({"error":"An internal error occurred"}), so every vector search with k in (5000, 10000] silently failed on Elasticsearch deployments.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • Vector search with k = 10,000 (the REST API and MCP SemanticSearchTool advertised maximum) produces a valid Elasticsearch request instead of a 400/500
  • Vector search with any k in [1, 10,000] and any configured multiplier never exceeds the engine's 10,000 num_candidates cap
  • Below-cap values (k × multiplier ≤ 10,000) are unchanged — no regression

Unit tests

  • I added unit tests for the new/changed logic.
  • Files updated:
    • openmetadata-service/src/test/java/org/openmetadata/service/search/vector/VectorSearchQueryBuilderTest.java — updated the existing overflow-clamp test to assert the 10,000 engine cap (was Integer.MAX_VALUE); added tests for the advertised MAX_K = 10,000 scenario, high-multiplier clamping, and a property-based sweep over k (1..10,000) × multipliers {1,2,3,5,10,50,100}
    • openmetadata-service/src/test/java/org/openmetadata/service/search/vector/ElasticSearchVectorServiceTest.java — added a test verifying the clamp reaches the actual HTTP request body through the full search() pathway
  • Coverage: 90.9% line on VectorSearchQueryBuilder (JaCoCo, mvn test -P static-code-analysis)

Backend integration tests

  • Not applicable (no backend API changes).
  • VectorEmbeddingIntegrationIT (10 tests, OpenSearch 3.4.0 via Testcontainers) ran successfully with no regressions.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • Attempted to run the full TestSuiteBootstrap (MySQL 8.3.0 + Elasticsearch 9.3.0 + OpenMetadata app) to exercise POST /v1/search/vector/query end-to-end, but the bootstrap fails with a pre-existing AppScheduler is not Initialized error during OpenMetadataApplication.registerResources() — unrelated to this fix, which only touches the query builder's num_candidates clamp and the config schema description.

UI screen recording:

Not applicable — backend-only change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes #35640: Clamp num_candidates to Elasticsearch engine maximum of 10000
  • My PR is linked to a GitHub issue via Fixes #35640 above.
  • 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. — No migration needed; only the knnNumCandidatesMultiplier description text was updated, no schema field or type changed.
  • For a UI feature or feature task: N/A (backend-only).
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Decision check: this PR does not introduce a durable decision — it enforces an existing Elasticsearch engine limit that was already violated by the code.

Automatic Fixes PRs can be configured here.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Caps Elasticsearch num_candidates at 10,000 while keeping the existing minimum of 100 and overflow-safe multiplication.

  • Elasticsearch vector searches cap candidate counts at 10,000.

Reviews (4) · Last reviewed commit: "Merge branch 'main' into detail/bug-fix/..." · Reviewed by Greptile

@detail-app
detail-app Bot requested a review from a team as a code owner October 16, 2026 12:53
@detail-app
detail-app Bot requested a review from manerow October 16, 2026 12:53
@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!

@detail-app detail-app Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 16, 2026
@github-actions

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.

@github-actions

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: 936 → 937
- 1 added, 0 removed, 11 changed spec-list

New source→spec entries:
  openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/QualityTab/QualityTab.component.tsx

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/e2e/fixtures/pages.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/TableClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/service/DatabaseServiceClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/admin.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/apiResponse.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/scopedLocators.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/testCases.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/waitHelpers.ts
  … and 1 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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 78%
78.81% (125962/159819) 64.88% (43735/67406) 68.11% (25173/36957)

@detail-app
detail-app Bot force-pushed the detail/bug-fix/fixes-35640-clamp-num-candidates-to-elasticsearch-4e5a21 branch from c82ed8e to 914e240 Compare October 19, 2026 11:46
@Vishnuujain
Vishnuujain added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-19T20:39:14Z)

Blocked the queue: java-checkstyle

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

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-20T10:08:44Z)

Blocked the queue: py-tests-status

@pmbrull
pmbrull enabled auto-merge October 20, 2026 10:21
@sonarqubecloud

Copy link
Copy Markdown

@pmbrull
pmbrull added this pull request to the merge queue Oct 20, 2026
@sonarqubecloud

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-20T16:44:45Z)

Blocked the queue: py-tests-status

@pmbrull
pmbrull added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit 4ae1868 Oct 20, 2026
98 checks passed
@pmbrull
pmbrull deleted the detail/bug-fix/fixes-35640-clamp-num-candidates-to-elasticsearch-4e5a21 branch October 20, 2026 21:33
joaopamaral added a commit to Automattic/OpenMetadata that referenced this pull request Nov 11, 2026
… 10,000

Backport of upstream open-metadata#35652 (fixes open-metadata#35640) to 2.0.7. num_candidates was
max(100, k * knnNumCandidatesMultiplier) with no upper bound, so any k
above 10,000 / multiplier made Elasticsearch reject the kNN query and the
vector search endpoint and the MCP semantic_search tool return 500. With a
multiplier of 50 that is any k above 200, including the REST endpoint's
default k of 1,000.

Only the query builder and its tests are backported; the upstream schema
description and generated UI types are unchanged here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Detail Bug] Search/Elasticsearch: Vector search fails for k > 5000 due to num_candidates exceeding Elasticsearch cap

1 participant