Skip to content

fix(search): index all body chunks for semantic retrieval (backport collate#4789) to 1.13 - #29850

Merged
pmbrull merged 1 commit into
1.13from
backport/multichunk-4789-1.13
Jul 9, 2026
Merged

pmbrull merged 1 commit into
1.13from
backport/multichunk-4789-1.13

Conversation

@tomasmontielp

@tomasmontielp tomasmontielp commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Backport: multi-chunk embeddings (open-metadata/openmetadata-collate#4789) to 1.13

Backports the vector-pipeline half of #29678 to 1.13.

Fixes open-metadata/openmetadata-collate/issues/4789

Note for review

VectorIndexService intentionally diverges from upstream by one method: the preference/7-arg search overload (from #29503, multi-node search) is omitted because #29503 is not on 1.13. Only the chunk methods are added.

Tests

  • New VectorDocBuilderChunkTest (asserts a long body yields multiple chunk docs — fails without the fix).
  • Updated VectorEmbeddingHandlerTest, OpenSearchBulkSinkBehaviorTest.
  • openmetadata-service main + tests compile clean locally against the full shaded build.

…4789)

Backport the multi-chunk embedding fix from #29678 to 1.13, vector-pipeline
only. Excludes the AI Context Platform (REST /context, MCP tools,
AIContextBuilder, metric assets), which depends on 2.0-only server features
(Context Center, metric->asset edge).

VectorDocBuilder previously embedded only chunk 0 (~380 words) of an entity's
body, so long Knowledge Articles were not semantically retrievable past their
opening. VectorDocBuilder.fromEntity now emits one embedding document per body
chunk into a dedicated data_asset_embeddings_chunks index (deterministic
{parentId}_{chunkIndex} ids), dual-writing chunk 0 to the legacy entity-doc
embedding so hybrid search is unchanged and there is no migration cliff. Stale
chunks are cleaned on hard/soft delete, restore, and body shrink; a reindex
backfills existing entities (missing chunk header -> re-embed, fingerprint-skip
on subsequent runs).

The read side (RagHitProcessor top-N chunk merge in ai-platform) already ships
on 1.13 and lights up once the chunk index is populated.

VectorIndexService intentionally diverges from upstream by one method: the
preference/7-arg search overload (from #29503) is omitted because #29503 is not
on 1.13; only the #4789 chunk methods are added.

Fixes: open-metadata/openmetadata-collate#4789

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Jul 8, 2026
Comment on lines +258 to +259
if (domain.getName() != null) {
domains.add(Map.of("name", domain.getName()));

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.

P1 Domain Filter Uses Short Names

When semantic search is filtered by a domain FQN such as parent.analytics, chunk docs only contain domains.name from domain.getName(). The existing filter convention uses the domain fully-qualified name, so matching entities can lose all multi-chunk hits once their relevant content lives in the chunk index.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think this one holds — the vector query builder filters domains on domains.name (VectorSearchQueryBuilder, case "domains" -> appendFlat(sb, "domains.name", values)), and chunk docs write exactly domains.name. So the filter matches.

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.

You're correct — I verified VectorSearchQueryBuilder and it filters on domains.name (not FQN), which matches exactly what domainNameObjects writes. My original comment was wrong. Apologies for the noise.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

Comment on lines +214 to +233
private static void addFilterFields(
Map<String, Object> fields, EntityInterface entity, String entityType) {
fields.put("entityType", entityType);
fields.put("deleted", Boolean.TRUE.equals(entity.getDeleted()));
putIfPresent(fields, "name", entity.getName());
putIfPresent(fields, "fullyQualifiedName", entity.getFullyQualifiedName());
putIfPresent(fields, "displayName", entity.getDisplayName());
List<Map<String, Object>> tags = tagFqnObjects(entity);
if (!tags.isEmpty()) {
fields.put("tags", tags);
}
List<Map<String, Object>> domains = domainNameObjects(entity);
if (!domains.isEmpty()) {
fields.put("domains", domains);
}
String tier = extractTierLabel(entity);
if (tier != null) {
fields.put("tier", Map.of("tagFQN", tier));
}
}

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.

P1 Chunk Docs Miss Search Filters

The chunk index is queried through the same vector search path as legacy embedding docs, but chunk docs only write entityType, deleted, tags, domains, and tier. Requests that filter by supported fields like owners, serviceType, service, database, databaseSchema, certification, or primaryEntityId can match the legacy entity doc while silently dropping the relevant body chunks, so filtered semantic retrieval misses the content this PR is trying to expose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The mechanism is real but not reachable in our read paths. The only consumers that hit the chunk index are the RAG vector path (CompanyContextFetcher, which filters on entityType only — materialized on chunk docs) and searchChunksByParent (filters parentId only — also materialized). In hybrid search the chunk docs are excluded regardless because HybridSearchTool drops any hit without a _source.id, which chunk docs don't have. So nothing filters the chunk index by owners/service/certification today. Also unchanged from #29678. If a future caller needs those filters we'll materialize them then.

Main goal is to backport #29678 so we shouldn't enhance in this pr things that are already in main

Comment on lines +523 to +530
if (chunkDocExists(indexName, parentId + "_1")) {
LOG.warn("Healing orphan chunk docs for parent {} with missing chunk-0 header", parentId);
String body =
"{\"query\":{\"term\":{\"parentId\":\""
+ VectorSearchQueryBuilder.escape(parentId)
+ "\"}}}";
executeGenericRequest(
"POST", "/" + indexName + "/_delete_by_query?conflicts=proceed", body);

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.

P2 security Orphan Probe Misses Later Chunks

When chunk 0 is missing, cleanup only checks whether <parentId>_1 exists before running the delete-by-query. If a partial bulk failure or delete leaves chunks 2+ behind while chunks 0 and 1 are gone, this path skips cleanup and stale chunk text can remain searchable for a deleted or replaced entity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged — this exact edge case is called out in the method's own comment. It needs a partial bulk failure that loses both chunk 0 and chunk 1 while leaving later chunks, and the next successful full write overwrites those ids anyway. Very low likelihood, self-healing, and unchanged from #29678 on main. Leaving as-is for the backport; can harden on main separately if we care.

@gitar-bot

gitar-bot Bot commented Jul 8, 2026 •

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

Enables semantic retrieval for long Knowledge Articles by indexing all body chunks into a dedicated collection, ensuring parity with the existing RAG hit processor. No issues found.

✅ 2 resolved
✅ Quality: Cluster-alias prefix casing differs between chunk index and read alias

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:191-201 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:901-911
The newly added getChunkIndexName() lowercases the cluster-alias prefix (clusterAlias.toLowerCase(Locale.ROOT) + "_" + CHUNK_INDEX_BASE), while getSearchAlias() (used to build/attach the read alias for the same chunk index) does NOT lowercase the prefix (clusterAlias + "_" + VECTOR_EMBEDDING_ALIAS). For any cluster alias containing uppercase characters this produces an inconsistently cased index-name prefix vs. alias-name prefix. OpenSearch requires alias names to be lowercase, so createChunkIndexIfAbsent() -> PUT /<index>/_alias/<getSearchAlias()> could be rejected, and reads via the alias would then silently skip chunk docs. Cluster aliases are usually lowercase so impact is limited, but the new code should apply the same toLowerCase(Locale.ROOT) normalization the chunk-index name uses, for consistency.

✅ Performance: updateEntityEmbeddings re-embeds all chunks when only entity doc is stale

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:215-229
In updateEntityEmbeddings, chunkDocs = VectorDocBuilder.fromEntity(...) is built whenever entityDocStale || chunksStale, and fromEntity issues one embedding call per body chunk. When the chunk index is already current (chunksStale == false) but the entity-doc fingerprint diverges (entityDocStale == true) — e.g. a prior partial-update to the entity index failed while the chunk write succeeded — the code pays N embedding calls just to splice chunk 0 into the entity doc, discarding chunks 1..N-1. In the common case both fingerprints flip together so cost is correct, but when they diverge the recovery path is more expensive than necessary. Consider reading chunk 0's stored embedding fields from the chunk index (already fetched context) to refresh the entity doc without re-embedding when only the entity doc is stale.

Options

Display: compact → Showing less information.

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

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@tomasmontielp tomasmontielp changed the title fix(search): index all body chunks for semantic retrieval (backport #4789) to 1.13 fix(search): index all body chunks for semantic retrieval (backport collate#4789) to 1.13 Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (19 flaky)

✅ 3667 passed · ❌ 0 failed · 🟡 19 flaky · ⏭️ 26 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 2 735 0 2 7
🟡 Shard 3 779 0 2 2
🟡 Shard 4 754 0 3 9
🟡 Shard 5 692 0 1 0
🟡 Shard 6 707 0 11 8
🟡 19 flaky test(s) (passed on retry)
  • Features/BulkEditEntity.spec.ts › Database Schema (shard 2, 1 retry)
  • Features/Glossary/GlossaryWorkflow.spec.ts › should display correct status badge color and icon (shard 2, 1 retry)
  • Features/Permissions/GlossaryPermissions.spec.ts › Team-based permissions work correctly (shard 3, 1 retry)
  • Features/Table.spec.ts › Tags term should be consistent for search (shard 3, 1 retry)
  • Pages/CustomProperties.spec.ts › Set & Update all CP types on apiCollection (shard 4, 1 retry)
  • Pages/Domains.spec.ts › Rename domain with deeply nested subdomains (3+ levels) verifies FQN propagation (shard 4, 1 retry)
  • Pages/Entity.spec.ts › Tag and Glossary Term preservation in column detail panel (shard 4, 1 retry)
  • Pages/EntityDataSteward.spec.ts › User as Owner Add, Update and Remove (shard 5, 1 retry)
  • Pages/Glossary.spec.ts › Add, Update and Verify Data Glossary Term (shard 6, 1 retry)
  • Pages/InputOutputPorts.spec.ts › Bulk delete shows warning listing only assets in output ports (shard 6, 2 retries)
  • Pages/InputOutputPorts.spec.ts › No warning when data product has no output ports (shard 6, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab IS visible for supported type: searchIndex (shard 6, 1 retry)
  • Pages/ODCSImportExport.spec.ts › Multi-object ODCS contract - object selector shows all schema objects (shard 6, 1 retry)
  • Pages/ServiceEntity.spec.ts › Team as Owner Add, Update and Remove (shard 6, 1 retry)
  • Pages/TestSuite.spec.ts › Logical TestSuite (shard 6, 1 retry)
  • Pages/UserDetails.spec.ts › Admin user can edit teams from the user profile (shard 6, 1 retry)
  • Pages/Users.spec.ts › Permissions for table details page for Data Consumer (shard 6, 1 retry)
  • Pages/Users.spec.ts › User Performance across different entities pages (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@pmbrull
pmbrull merged commit 5dd4c08 into 1.13 Jul 9, 2026
62 of 88 checks passed
@pmbrull
pmbrull deleted the backport/multichunk-4789-1.13 branch July 9, 2026 06:18

This branch was previously deployed

1 inactive deployment
test — ba21113a Deployed Jul 8, 2026 by tomasmontielp via playwright-ci-postgresql (2, 6) #55383
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.

2 participants