OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

Chunk documents carry a denormalized columns array that nothing reads

Open fmcardoso opened this issue 2 months ago • 0 comments

VectorDocBuilder.buildDenormalizedFields copies a table's entire columns array onto every chunk document of that entity:

if (entity instanceof Table table) {
  List<Map<String, Object>> columns = columnNameObjects(table.getColumns());
  if (!columns.isEmpty()) {
    fields.put("columns", columns);
  }
}

The denormalized field map is built once per entity and shallow-copied onto each chunk, so on a multi-chunk entity the array is stored once per chunk. Entity documents are unaffected — this is the chunk path only.

Why it matters

1. It costs storage and indexing for a field nothing reads. Consumers project a fixed set of display fields that does not include columns, and downstream search excludes it from _source, so it is never returned. Roughly half the cost is the stored _source and half the inverted index — query-time _source filtering recovers neither, since that is fetch-phase only.

2. The stated purpose is not achievable. The javadoc says columns.name is denormalized "so the shard-fair keyword clauses match on the best-semantic chunk, not only on chunk 0's spliced entity doc." Because every chunk carries every column, the clause matches every chunk of an entity identically and cannot single one out. textToEmbed — mapped text, already indexed, and built from buildSemanticBodyText which emits every column for a Table — is what actually provides that discrimination.

3. The mapping indexes the same terms twice. columns.name is keyword and also carries a columns.name.keyword sub-field, itself keyword.

What this is not

Not a bug. Nothing produces a wrong result: callers get identical results either way, entity docs still carry columns, and the clause contributes the same score to every chunk of an entity, so it cannot reorder anything within the group. The non-discrimination above means the field buys nothing, not that it breaks something. This is a cleanup, not a defect.

Proposed change

  1. Remove the instanceof Table columns block from buildDenormalizedFields.
  2. CHUNK_DOC_VERSION 3 → 4 so existing chunks are recognised as stale.
  3. Leave columnsMapping() in buildChunkProperties(). A field cannot be removed from a live mapping, and mapped-but-unwritten is harmless, so the change stays purely additive and applyChunkMappingUpgradeIfStale's PUT _mapping stays valid.

Migration

The bump does not rewrite anything on deploy. The mapping upgrade applies on the next write; the document backfill is lazy. A full-coverage reindex stages a new chunk generation and rewrites everything in one run, reusing the live generation's stored vectors when the fingerprint is unchanged (no re-embedding); a partial reindex rewrites only the entities it touches.

Rejected alternative

Carrying only the chunk's slice of columns. Chunking runs on a text blob (TextChunkManager.chunk(buildBodyText(...))), so there is no column→chunk mapping to slice by without restructuring the chunker — and textToEmbed already provides the discrimination the slice would buy.

fmcardoso avatar Sep 04 '26 13:09 fmcardoso