Skip to content

Fixes #37523: Embed topic schema fields in vector chunk text - #37522

Merged
fmcardoso merged 4 commits into
mainfrom
fmcardoso/topic-fields-vector
Nov 12, 2026
Merged

fmcardoso merged 4 commits into
mainfrom
fmcardoso/topic-fields-vector

Conversation

@fmcardoso

@fmcardoso fmcardoso commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #37523

Semantic/hybrid search and Ask Collate could not find a Kafka topic when the answer lives only in its schema fields: topic chunk docs carried the name and description but none of messageSchema.schemaFields. A topic whose only mention of stock splits is a field description (or a nested field under a struct) was missed.

  • VectorDocBuilder.schemaFieldsText flattens a topic's schema fields depth-first. Nested children become dotted paths (payload.ratio), and each entry is name (description).
  • textToEmbed gets Fields include <fields>, and textToLLMContext gets columns: <fields>. The columns: marker is the one tables use, and the AI platform's hybrid search already parses it for any entity type, so no client change is needed.
  • Topics without a schema keep their exact body and fingerprint. Table output is unchanged: a shared nameWithDescription helper produces the same text.
  • Embedded text is no longer dropped when textToEmbed needs one more chunk than textToLLMContext; the last doc gets the overflow (semanticChunkFor). Without this, a topic ending exactly on the 380-word boundary lost its last field, and containers lost their "Contains …" child names after a long description.
  • Decision record: docs/decisions/2026-11-11-chunk-llm-context-lists-child-fields-under-columns.md.

Example textToEmbed:

  • before: topic Corporate Actions (corporate_actions). Corporate action events
  • after: … Corporate action events. Fields include event_id (Unique event identifier), payload, payload.ratio (Ratio of the stock split, e.g. 2:1), payload.effective_date

Upgrade: there is no CHUNK_DOC_VERSION bump. The fingerprint changes only for topics with schema fields, so only those are re-embedded.

Type of change:

  • Improvement

High-level design:

N/A: one class, its tests, one decision record.

Tests:

Unit tests

  • Added VectorDocBuilderTopicFieldsTest (6) and extended VectorDocBuilderTest (+5). VectorDocBuilder*Test: 68 run, 0 failures; spotless clean.
  • Covered:
    • top-level and nested fields reach both texts;
    • schema-less topics are unchanged;
    • a nested description change changes the fingerprint;
    • a 300-field schema keeps every field across chunks;
    • the exact 380-word boundary;
    • container overflow;
    • table text, fingerprint and columnsToString byte-identical to main (expected values produced by main's classes).
  • Each fix has a test that fails without it: the boundary test failed on the first commit (field_376 is not embedded), and disabling the overflow fix fails the overflow tests.

Backend integration tests

  • Not applicable. No endpoint, search field, mapping or refresh mechanism changes; only the text written into existing fields. Existing docs refresh through the unchanged fingerprint → REEMBED path, which the live reindex below exercised.

Ingestion integration tests

  • Not applicable.

Playwright (UI) tests

  • Not applicable.

Manual testing performed

Ran a local stack with this change, on a synthetic catalog of ~900 assets (807 topics), and asked Ask Collate 22 questions × 2 reps. The live run used the first commit's Schema fields include label. A simulated run with text identical to the current output gave the same result.

before this change
answer names the right topic 18/22 22/22
answer cites the matching field 14/20 20/20
mean rank in first search 4.1 1.7
searches per run 1.45 1.09
  • Questions answered only by a nested field went from never found to rank 1.
  • Control questions (answer in a description or a table column) were unchanged.
  • A normal reindex re-embedded 807/807 topics, with 0 failures.

UI screen recording:

Not applicable: backend-only.

Open questions for reviewers

  1. Stale entity-doc embedding. The OpenSearch reindex rebuilds the chunk index, but the embedding copy on the topic entity doc keeps the old text until the topic is edited, because of the updatedAt fast path in cachedStateMatches. Fixing it changes the reuse design for every entity type, so it is left to Reindex keeps stale embeddings when embedding text changes but updatedAt does not #37524.
  2. No cap on flattened fields. Tables have none either. Providers with short input limits (Bedrock Cohere, 2,048 chars) already truncate long chunks for every entity type.
  3. columns: vs a dedicated schemaFields: marker. The reuse is recorded in the ADR; a new marker would need a client change.
  4. Same gap elsewhere (follow-ups):
    • dashboardDataModel columns;
    • container dataModel.columns;
    • searchIndex fields;
    • apiEndpoint request/response schemas;
    • mlmodel features;
    • nested table columns (columnsToString doesn't recurse).

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> 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 schema changes.)
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M4KprTP2zUa4XSmwLndLFc

Topic chunks carried only the topic description, so a question answered by a
schema field (top-level or nested) could neither find the topic semantically
nor quote the matching field. Flatten messageSchema.schemaFields depth-first
as dotted paths in the table-column format: "Schema fields include ..." in
textToEmbed and a "columns: ..." section in textToLLMContext, which CAIP's
HybridSearchTool already parses. Topics without fields keep their body and
fingerprint; topics with fields get a new fingerprint and are re-embedded by
the next reindex.
The topic label "Schema fields include" made the semantic body one word
longer than the context body. A doc is written per context chunk, so when the
context body ended exactly on a 380-word boundary the overflowing semantic
chunk, and the last field in it, was never embedded. Use the two-word "Fields
include" label, and let the last chunk doc carry any semantic overflow so the
boundary cannot lose text again (this also stops dropping container child
names after a long description).

Pin table chunk text and fingerprints to their origin/main values, assert
every field of a wide topic, and record the shared columns: format in an ADR.
@fmcardoso fmcardoso changed the title Embed topic schema fields in vector chunk text Fixes #37523: Embed topic schema fields in vector chunk text Nov 11, 2026
@fmcardoso fmcardoso added the To release Will cherry-pick this PR into the release branch label Nov 11, 2026
@fmcardoso
fmcardoso marked this pull request as ready for review November 11, 2026 08:21
@fmcardoso
fmcardoso requested a review from a team as a code owner November 11, 2026 08:21
@fmcardoso
fmcardoso requested a review from IceS2 November 11, 2026 08:21
@gitar-bot

gitar-bot Bot commented Nov 12, 2026

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

Embedding flattened topic schema fields changes search ranking, and long schemas could consume chunk capacity or crowd out other searchable text.

Embeds Kafka topic schema fields in vector chunk text, so semantic and hybrid search can find topics whose only match is a schema field or nested field description. The topic columns: chunk contract with ai-platform is now documented in a decision record, addressing that finding. No open issues found.

✅ 1 closed
✅ Quality: Topic columns: chunk contract with ai-platform has no decision record

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorDocBuilder.java:761-767 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorDocBuilder.java:946-949 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorDocBuilder.java:1066-1080
This PR sets a format that another repository has to follow. A topic's textToLLMContext now carries its flattened schema fields (dotted paths, name (description)) under the columns: label, and the PR says that label was chosen so ai-platform's HybridSearchTool keeps that section when it trims hits, with no client change. Nothing in docs/decisions/ records this. The only note is a code comment at VectorDocBuilder.java:761-763, and the repo squash-merges, so the description's reasoning won't reach git log. That reasoning includes skipping the CHUNK_DOC_VERSION bump and leaving existing Elasticsearch topics to refresh only when edited.

The record would say something like: "A topic's chunk body lists its message-schema fields, nested ones flattened to dotted paths as name (description), under the same columns: label as table columns, because ai-platform's hybrid-search trimming keys on that label. Topics without fields keep their prior body and fingerprint. Adding the fields changes the fingerprint, so chunkRefresh() re-embeds only topics that have fields, and CHUNK_DOC_VERSION stays the same." Without it, someone could later rename the label (for example to schema fields:) or bump the doc version and silently break ai-platform's trimming or force every topic to re-embed.

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

@fmcardoso
fmcardoso merged commit 3ea4bcf into main Nov 12, 2026
66 checks passed
@fmcardoso
fmcardoso deleted the fmcardoso/topic-fields-vector branch November 12, 2026 08:48
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.0 opened as #37642 (clean cherry-pick). It merges itself once the checks pass.

fmcardoso added a commit that referenced this pull request Nov 12, 2026
Brings in #37522 (topic schema fields in the vector text). The only
conflict was VectorDocBuilderTest's imports; both sides are kept.

Amends #37522's decision record (v2): with fingerprint-only reuse,
Elasticsearch topics with schema fields refresh on the next reindex
instead of only when edited. The reuse record now names the topic
re-embed as the upgrade cost #37522 brings.
gh-bot-collate Bot added a commit that referenced this pull request Nov 12, 2026
…37642)

* Fixes #37523: Embed topic schema fields in vector chunk text (#37522)

* Embed topic schema fields in vector chunk text

Topic chunks carried only the topic description, so a question answered by a
schema field (top-level or nested) could neither find the topic semantically
nor quote the matching field. Flatten messageSchema.schemaFields depth-first
as dotted paths in the table-column format: "Schema fields include ..." in
textToEmbed and a "columns: ..." section in textToLLMContext, which CAIP's
HybridSearchTool already parses. Topics without fields keep their body and
fingerprint; topics with fields get a new fingerprint and are re-embedded by
the next reindex.

* Keep every topic field in the embedded chunk text

The topic label "Schema fields include" made the semantic body one word
longer than the context body. A doc is written per context chunk, so when the
context body ended exactly on a 380-word boundary the overflowing semantic
chunk, and the last field in it, was never embedded. Use the two-word "Fields
include" label, and let the last chunk doc carry any semantic overflow so the
boundary cannot lose text again (this also stops dropping container child
names after a long description).

Pin table chunk text and fingerprints to their origin/main values, assert
every field of a wide topic, and record the shared columns: format in an ADR.

(cherry picked from commit 3ea4bcf)

* Use the raw EntityInterface on 2.0

---------

Co-authored-by: Felipe Maciel Cardoso <felipe.cardoso@getcollate.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic search and Ask Collate miss topics whose match is only in schema fields

3 participants