Skip to content

Fixes #38516: Engine-neutral building blocks for hybrid search - #38517

Merged
manerow merged 47 commits into
mainfrom
feat/hybrid-search-engine-neutral
Nov 25, 2026
Merged

manerow merged 47 commits into
mainfrom
feat/hybrid-search-engine-neutral

Conversation

@manerow

@manerow manerow commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38516

Stacked on PR #38415. Its base is that PR's branch, so this diff shows only this PR's changes. Review and merge after it; once #38415 merges, this PR moves to main. Merge order: Collate PR #8922, OM PR #38415, this PR, Collate PR #8899, then OM PR #38565. The companion Collate PR is PR #8899, and the benchmark change is PR #2419.

I added small, engine-neutral primitives so a caller can build hybrid (keyword plus vector) search
on Elasticsearch as well as OpenSearch. The OpenSearch RRF search pipeline stays exactly as it is
on #38415: Collate main still calls it, so its removal waits until Collate stops using it.

  1. SearchClient.getQueryDsl() returns a SearchQueryDsl that renders OpenMetadata's typed,
    engine-specific builders as query JSON: one OMQueryBuilder clause (toJson), and the query
    /v1/search runs for a text with the ranking shell of the search settings
    (dataAssetQueryJson). Both clients implement it with their own JSON mapper.
  2. VectorIndexService.knnQueryClause(vector, parameters) returns the engine's kNN clause,
    usable inside bool and function_score, through a new buildKnnQueryClause hook:
    OpenSearch's knn clause plus ignore_unmapped, and Elasticsearch's knn query (k per shard,
    num_candidates clamped, similarity = 2 * threshold - 1 because Elasticsearch takes the raw
    cosine while the threshold is on the (1 + cosine) / 2 score scale). This resolves the
    "Revisit" clause of Fixes #37525: Run Elasticsearch semantic search on the shared vector index service #38415's decision record with a hook, as that record suggested.
  3. SearchRepository.getHybridWeights() exposes the keyword and semantic weights (search
    settings, then config, then 0.6 and 0.4) in one place, including when naturalLanguageSearch
    is not configured at all.
  4. SearchSourceBuilderFactory.assetTypeConfiguration(indexName, searchSettings), a static
    lookup that findAssetTypeConfig now delegates to, so a caller that holds no engine factory can
    use it instead of copying it.
  5. Elasticsearch vector fields pin their index options when created: float HNSW with m 48
    and ef_construction 256, the OpenSearch values, from one helper used by the entity indexes and
    the chunk index. A PUT _mapping on an existing index reads the live mapping first: if the
    index already has embedding, the field is left out of the body, so it keeps the options it
    was created with; if it has none yet (embeddings just turned on), the field is added with the
    pinned options. Re-declaring an existing field is refused either way: Elasticsearch reads a
    dense_vector without index_options as the engine default and will not change the options of
    an existing field, and sending the pinned options is refused on an index created before this PR.
    Because PUT _mapping is atomic, that refusal would drop every new field of an upgrade.
  6. The hybrid RRF search pipeline stays for now; its removal ships in OM PR Rename AvailableEntityTypes to EmbeddedEntityTypes #38565. Nothing in
    OpenMetadata runs a hybrid query or reads the stored hybrid-rrf pipeline, but Collate main
    still uses HYBRID_PIPELINE_NAME, buildHybridRrfPipelineDefinition,
    getHybridRrfPipelineDefinition and ensureHybridSearchPipeline, and OpenMetadata's
    compatibility check builds Collate main against every OM PR. Deleting the pipeline here would break that build and deadlock this PR with Collate
    PR getting error while connecting snowflake #8899, which needs this PR's new API before it can drop those calls. So this PR keeps every
    pipeline member, caller and test exactly as on Fixes #37525: Run Elasticsearch semantic search on the shared vector index service #38415: OpenSearch keeps creating and checking the
    pipeline, and the embeddings status still reports it. OM PR Rename AvailableEntityTypes to EmbeddedEntityTypes #38565 deletes it after Collate
    PR getting error while connecting snowflake #8899 merges. One small fix stays here: on Elasticsearch, which has no pipeline, the
    embeddings status no longer says "hybrid search pipeline" (usesHybridSearchPipeline).
  7. naturalLanguageSearch.hybridSearch.searchPipeline is unchanged in the configuration schema.
    It is still the pipeline name. After OM PR Rename AvailableEntityTypes to EmbeddedEntityTypes #38565 it stays and is ignored: the block does not
    allow unknown keys and Dropwizard fails startup on one, so deleting the key would stop a server
    whose configuration file still sets it.

Nothing changes for OpenMetadata's own vector search: buildQuery and buildKnnSearch are
untouched, and OpenSearch deployments keep the hybrid-rrf pipeline exactly as before.

Type of change:

  • Improvement

High-level design:

The consumer is Collate's hybrid search, which fuses the two legs itself with weighted RRF on both
engines. All engine syntax stays in OpenMetadata next to the clients; the caller composes requests
for rawSearchRequest without naming an engine. Fusion stays out of OpenMetadata.

Decision records:

  • docs/decisions/2026-11-23-search-clients-render-typed-builders-as-query-dsl.md (new)
  • docs/decisions/2026-11-23-elasticsearch-vector-fields-pin-their-index-options.md (new)
  • docs/decisions/2026-11-23-the-hybrid-rrf-pipeline-leaves-openmetadata.md (new; the decision
    and why the removal is staged: the deletion ships in OM PR Rename AvailableEntityTypes to EmbeddedEntityTypes #38565)
  • docs/decisions/2026-11-20-elasticsearch-and-opensearch-share-one-vector-index-service.md (v3
    amendment)

Tests

  • OpenSearchQueryDslTest, ElasticQueryDslTest, SearchQueryDslParityTest (the ranking shell
    and the memory visibility rule are equal on both engines; boost weights compared at float
    precision, because the OpenSearch client writes 0.30000001192092896 where Elasticsearch writes
    0.3).
  • VectorSearchQueryBuilderTest (both clause shapes, radial and top-k, the similarity conversion,
    the caps), EsUtilsTest (new field pinned, existing field kept, an update leaves out an embedding the
    live index has and adds the pinned one when it has none, a different live dimension fails),
    ElasticSearchIndexManagerTest (the live mapping is read through an alias over several
    indexes),
    ElasticSearchVectorServiceTest, ChunkSetBoundTest.
  • SearchSourceBuilderFactoryTest (new case for the static lookup),
    SearchRepositoryBehaviorTest.getHybridWeightsReadsTheAdminWeightsOfTheSearchSettings (new; the
    weights were only tested through the pipeline check before) and
    getHybridWeightsFallsBackToTheDefaultsWithoutNaturalLanguageSearchConfiguration (new), SystemRepositoryEmbeddingsValidationTest,
    ReindexingOrchestratorTest, OpenSearchVectorServiceTest, SystemResource*Test (their
    pipeline cases are kept as on Fixes #37525: Run Elasticsearch semantic search on the shared vector index service #38415).
  • Run locally after keeping the pipeline: 1264 unit tests green, 0 failures, 2 skipped (94 classes:
    the search.vector, search.queries, search.elasticsearch and search.opensearch packages plus
    SearchRepository*Test, SearchSourceBuilderFactoryTest, SystemRepository*Test,
    SystemResource*Test, ReindexingOrchestratorTest); openmetadata-integration-tests compiles
    (its pipeline cases in VectorEmbeddingIntegrationIT are kept).
    scripts/harness/check_decision_records.py clean. Collate main and Collate PR getting error while connecting snowflake #8899 both build against this branch
    (mvn -B clean install -DskipTests -pl '!collate-ui,!collate-dist').
  • After merging the updated Fixes #37525: Run Elasticsearch semantic search on the shared vector index service #38415 branch (main with PR #38574) at 47d2cdf35c8: 1298 unit tests green, 0 failures (108 classes: the packages above plus RecreateWithEmbeddingsTest, OpenMetadataOperations*Test and both bulk sinks). Collate main builds against it. Collate PR getting error while connecting snowflake #8899 builds, and collate-integration-tests compiles, once it has Collate main's PR #8473: this branch now carries OpenMetadata main's removal of BackgroundJob.JobType.DELETE_ENTITY, which PR Implement KPI checks in the processing workflow #8473 adapted Collate to.
  • On real clusters, through Collate's ApplicationFusionIT (OpenSearch 3.4.0 and Elasticsearch
    9.3.0, 9 cases each): the clause runs inside function_score inside bool.should, over an alias
    with an index that has no embedding field, with no shard failure; the threshold keeps and drops
    the same documents on both engines; a lowercase serviceType filter matches unnormalized chunks.
  • After the Elasticsearch mapping update fix at 64740defc33: 1258 unit tests green, 0 failures, 0 errors (99 classes: the search.vector, search.queries, search.elasticsearch and search.opensearch packages, SearchRepository*Test, SystemRepository*Test, SystemResource*Test, RecreateWithEmbeddingsTest, OpenMetadataOperations*Test; the 312 OpenSearch tests are unchanged and green). New ElasticsearchVectorMappingUpdateIT on Elasticsearch 9.3.0, 4 of 4 green: an index with the pinned options, reached through an alias as after a recreate, gets an upgrade's new field and keeps hnsw, m 48; an index created with the engine default gets the new field and keeps its default; an index without embedding gets the pinned field when embeddings turn on; a different embedding dimension fails with IllegalStateException. Against the previous head the same IT fails 3 of 4, with Elasticsearch's Cannot update parameter [index_options] from [{type=hnsw, m=48, ef_construction=256}] refusal. Collate main builds against this branch.
  • Not run locally: VectorEmbeddingIntegrationIT and the rest of the OpenMetadata IT suite.

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.
  • I have added tests around the new logic.
  • I have added a test that covers the exact scenario we are fixing.

harshach and others added 30 commits November 20, 2026 17:01
No main or test code calls updateVectorEmbeddingsForOpenSearch. The class
predates VectorEmbeddingHandler, which owns the entity-update write path.
…ectorService

Move the engine-neutral vector index logic into a Template Method base:
the chunk index lifecycle and mapping, chunk writes and deletes, staged
generations and promotion, embedding reuse, parent-grouped search and
the retry on closed segments. OpenSearchVectorService keeps the hybrid
RRF pipeline and supplies six hooks: the raw request, the engine name,
the index settings, the vector field mapping, the kNN search body and
whether a kNN is bounded by k.

The typed mget and getAlias calls become REST JSON through the request
hook (POST /{index}/_mget, GET /{base}/_alias), so the base needs no
OpenSearch client. Requests, mapping and retries are unchanged.

legacyEmbeddingFields moves to VectorDocBuilder, next to the chunk docs
it reads. The unused three-argument searchChunksByParent is removed.
…index

ElasticSearchVectorService extends AbstractVectorIndexService and
supplies only its dialect: the Rest5Client request, the dense_vector
mapping and the native top-level knn search. Elasticsearch gains the
chunk index and its staged recreate, chunk writes and deletes, passage
search by parent, and the provider-availability gate on entity updates.
Stored-embedding reuse now reads with _mget, as OpenSearch does. A
failed request reports "Elasticsearch generic request failed" with the
status and body in the cause, the shape OpenSearch already had.

VectorIndexService declares these capabilities as required methods in
place of no-op defaults, so an engine cannot silently skip them.
search(VectorSearchParameters) becomes the one abstract search and the
positional overloads delegate to it.

Elasticsearch tests that repeated the OpenSearch tests of the now-shared
search grouping are removed. New tests pin the Elasticsearch dialect:
the dense_vector chunk mapping and the knn search filtered to a parent.
…epository

Reindex, the re-embed command, AI context excerpts and the MCP entity tool
asked OpenSearchVectorService.getInstance() for the vector service. That is
null on Elasticsearch, so each of them did nothing there, and re-embed
exited 1 reporting that embeddings were disabled.

They now use SearchRepository.getVectorIndexService(), which holds the
service of whichever engine is configured. SearchRepository is the only
class left in main code that names an engine's vector service.

The two reindex bulk sinks carried separate copies of the embedding step.
Both now call EmbeddingEnricher, which keeps the OpenSearch behaviour. On
Elasticsearch a reindex therefore writes chunk documents, backfills them
for entities whose stored embedding is reused, and during a provider
outage indexes an entity without an embedding instead of counting it as
failed.
The chunk index is shared code, and each engine supplies only its
request dialect. The unit tests mock the HTTP boundary, so they cannot
tell whether a real engine accepts the mapping, the bulk writes, the
kNN search or the alias swap.

VectorChunkIndexIT runs one scenario against a container of each
engine. It writes chunks, reads the passages of one parent and searches
through the alias. Then it stages a full recreate, copies an unchanged
entity into the new generation without a provider call, and promotes
the generation.
Elasticsearch 9.3.0 leaves a dense_vector out of _source unless the
request names the field. The multi-get that reads stored vectors names
it, so reusing a stored vector works on both engines. A comment now
records that. VectorChunkIndexIT fails if the vectors stop coming back.

Also make the totalHits comment engine-neutral.
Add the record for running both search engines on one vector index
service. Amend the two 2026-11-11 records that describe Elasticsearch as
embedding chunk 0 only, and remove a guard test that was deleted.
Promote the java.md return guidance from a preference to a rule, state it in
AGENTS.md, and record the decision.
REVIEW.md still told reviewers that a trailing return was only a preference,
which left the new rule with no enforcement.
…dings

An unwritable chunk index keeps the entity's document embedding on both
engines, which changes earlier OpenSearch behavior. A failed chunk write
during a staged recreate does not block promotion; that gap came from the
OpenSearch implementation and is recorded as a revisit trigger.
…try points

recreateChunkIndexIfFullRun and the reembed command were edited by this
branch, so they follow the one-return rule. reembed moves its setup, batch
scheduling and summary into helpers that share one ReembedRun record.
A failed chunk write, mirror or delete into a staged generation was logged
and the run still promoted the generation once every entity type
finalized, so a rebuild could replace a complete chunk index with one that
had lost chunks. The failing node now sets _meta.incompleteChunkWrites on
that generation's index, and the coordinator reads it before the alias
swap. The flag lives on the cluster, so a participant's failure blocks the
coordinator's promotion and stays tied to the generation it hit.

VectorChunkIndexIT rejects one bulk item on OpenSearch and Elasticsearch,
checks the old chunks stay live, and checks a clean retry promotes.
…pdates

- A live edit whose chunk bulk fails, by HTTP error or by an item error
  in a 200, still refreshes the entity document's embedding. The old chunk
  header stays, so the next update rewrites the chunks.
- A finalized run always goes through promotion, which re-checks the
  failure flags under the lock. A coordinator-side chunk failure now logs
  the blocked promotion and clears the staged state.
- A node that cannot save the incomplete flag retries it when a
  vector-type partition ends and fails the partition if it still cannot,
  so the coordinator fails the entity type and keeps the old chunks.
- isStagedGenerationIncomplete returns once.
A bulk request is not atomic. When chunk 0 was written beside a chunk the
cluster rejected, the header moved forward and the next update skipped
the rewrite, so the missing chunk stayed missing. Chunk 0 is now written
in its own request after every other chunk and delete succeeded.

requireStagedChunkFailuresRecorded is abstract, like the other staging
methods on VectorIndexService. The shared-service ADR records that a live
edit's mirror or delete into a staged generation is covered only in part.
processPartitionInternal had four returns. It now chooses between a
skipped and a started partition, and processStartedPartition returns one
result after reading the range (readPartition) and finishing it
(finishPartition). The moved code is unchanged apart from the counters,
which travel together as PartitionCounts.
reembed and the CLI reindex resolved the embedding provider from
LlmConfigHolder, which only server startup filled. The CLI therefore fell
back to bedrock and refused to embed under any other provider.
@github-actions

Copy link
Copy Markdown
Contributor

UI browser tests

Ran: all test files (no impact map from main yet)

Result: ✅ 1070 passed · 154 skipped

@harshach
harshach marked this pull request as ready for review November 24, 2026 19:29
@harshach
harshach requested a review from a team as a code owner November 24, 2026 19:29
@harshach
harshach requested review from pmbrull and removed request for a team November 24, 2026 19:29
harshach
harshach previously approved these changes Nov 24, 2026
pmbrull
pmbrull previously approved these changes Nov 25, 2026
Base automatically changed from agent/can-you-check-if-we-are-addd to main November 25, 2026 09:00
@manerow
manerow dismissed stale reviews from harshach and pmbrull November 25, 2026 09:00

The base branch was changed.

# Conflicts:
#	docs/decisions/2026-11-20-elasticsearch-and-opensearch-share-one-vector-index-service.md
#	openmetadata-service/src/main/java/org/openmetadata/service/search/vector/AbstractVectorIndexService.java
#	openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java
#	openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java
#	openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorIndexService.java
#	openmetadata-service/src/test/java/org/openmetadata/service/search/vector/ChunkSetBoundTest.java
#	openmetadata-service/src/test/java/org/openmetadata/service/search/vector/ElasticSearchVectorServiceTest.java
@gitar-bot

gitar-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findings

New Elasticsearch vector options change index construction, and engine-specific kNN clauses could change results in caller-built hybrid searches.

Adds engine-neutral hybrid search primitives: SearchClient.getQueryDsl(), a kNN query clause hook in VectorIndexService, SearchRepository.getHybridWeights(), a static assetTypeConfiguration lookup, and pinned Elasticsearch vector index options. The getHybridWeights() NPE when naturalLanguageSearch is unset has been resolved. No open issues remain.

✅ 1 closed
✅ Edge Case: Public getHybridWeights() NPEs when naturalLanguageSearch is unset

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java:1068-1082
getHybridWeights() is now a public accessor meant for downstream hybrid-search callers. It calls getSearchConfiguration().getNaturalLanguageSearch() and then reads nlConfig.getKeywordWeight() without checking for null. Other code in this class treats naturalLanguageSearch as optional and null-checks it, for example isVectorEmbeddingEnabled and resolveKnnNumCandidatesMultiplier. When the old helper was private, only pipeline paths reached it. Now any caller on a deployment without that config block gets a NullPointerException instead of the documented 0.6/0.4 fallback. Fix: treat a null config as absent and fall back to the defaults.

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

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.

Engine-neutral building blocks for hybrid search on OpenSearch and Elasticsearch

4 participants