Repository navigation
fix(search): index all body chunks for semantic retrieval (backport collate#4789) to 1.13 - #29850
Conversation
…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]>
❌ PR checklist incompleteThis 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 |
| if (domain.getName() != null) { | ||
| domains.add(Map.of("name", domain.getName())); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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)); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Code Review ✅ Approved 2 resolved / 2 findingsEnables 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
✅ Performance: updateEntityEmbeddings re-embeds all chunks when only entity doc is stale
OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
The Python checkstyle failed. Please run You can install the pre-commit hooks with |
|
🟡 Playwright Results — all passed (19 flaky)✅ 3667 passed · ❌ 0 failed · 🟡 19 flaky · ⏭️ 26 skipped
🟡 19 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |



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
VectorIndexServiceintentionally diverges from upstream by one method: thepreference/7-argsearchoverload (from #29503, multi-node search) is omitted because #29503 is not on 1.13. Only the chunk methods are added.Tests
VectorDocBuilderChunkTest(asserts a long body yields multiple chunk docs — fails without the fix).VectorEmbeddingHandlerTest,OpenSearchBulkSinkBehaviorTest.openmetadata-servicemain + tests compile clean locally against the full shaded build.