Repository navigation
Fixes #37523: Embed topic schema fields in vector chunk text - #37522
Conversation
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.
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findingsEmbedding 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 ✅ 1 closed✅ Quality: Topic
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
|
🤖 Backport to |
|
🤖 Backport to |
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.
…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>
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.schemaFieldsTextflattens a topic's schema fields depth-first. Nested children become dotted paths (payload.ratio), and each entry isname (description).textToEmbedgetsFields include <fields>, andtextToLLMContextgetscolumns: <fields>. Thecolumns: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.nameWithDescriptionhelper produces the same text.textToEmbedneeds one more chunk thantextToLLMContext; 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.docs/decisions/2026-11-11-chunk-llm-context-lists-child-fields-under-columns.md.Example
textToEmbed:topic Corporate Actions (corporate_actions). Corporate action events… Corporate action events. Fields include event_id (Unique event identifier), payload, payload.ratio (Ratio of the stock split, e.g. 2:1), payload.effective_dateUpgrade: there is no
CHUNK_DOC_VERSIONbump. The fingerprint changes only for topics with schema fields, so only those are re-embedded.topic. A normal, non-recreate run rebuilds the chunk docs.updatedAtfast path reuses the cached embedding (Reindex keeps stale embeddings when embedding text changes but updatedAt does not #37524). ES also embeds chunk 0 only, so fields past ~380 words aren't embedded, the same as wide tables today (Elasticsearch embeds only the first chunk of an entity's text #37525).Type of change:
High-level design:
N/A: one class, its tests, one decision record.
Tests:
Unit tests
VectorDocBuilderTopicFieldsTest(6) and extendedVectorDocBuilderTest(+5).VectorDocBuilder*Test: 68 run, 0 failures; spotless clean.columnsToStringbyte-identical tomain(expected values produced bymain's classes).field_376 is not embedded), and disabling the overflow fix fails the overflow tests.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
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 includelabel. A simulated run with text identical to the current output gave the same result.UI screen recording:
Not applicable: backend-only.
Open questions for reviewers
updatedAtfast path incachedStateMatches. 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.columns:vs a dedicatedschemaFields:marker. The reuse is recorded in the ADR; a new marker would need a client change.dashboardDataModelcolumns;containerdataModel.columns;searchIndexfields;apiEndpointrequest/response schemas;mlmodelfeatures;columnsToStringdoesn't recurse).Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge.🤖 Generated with Claude Code
https://claude.ai/code/session_01M4KprTP2zUa4XSmwLndLFc