feat(okf): make OKF frontmatter extensions searchable and filterable

SH
1h ago
+497-25

What

An OKF document can now be found by its custom frontmatter keys. A concept with x-domain: finance (OKF 0.3) or domain: finance (earlier bundles) matches the filter okfExtensions = x-domain=finance (or domain=finance) on Search V2 and V3, and its extension values are matched by full-text search.

Until now, keys with no typed field lived only in okfProperties.raw, which isn't indexed, so nobody could search or filter on them.

The field: okfProperties.extensions

A new extensions: optional map[string, string] on okfProperties, indexed as okfExtensions.

  • Name: OKF calls producer-defined keys extensions, and the source docs already use that word ("the optional producer extension id", "version keys remain extensions"). customProperties would be confused with the native aspect of that name.
  • What goes in: every frontmatter key that no field or aspect maps, keyed as written, x- prefix included. Mapped keys (id, type, title, description, status, stale_after, generated, verified, owners, tags, glossary_terms) and the accepted OKF 0.3 aliases x-datahub-id, x-datahub-owners and x-datahub-glossary_terms are left out.
  • Scalars: stored as text; booleans and numbers in their JSON form (true, 2, 0.5). Dates are already strings.
  • Lists of scalars: joined with , ([analysts, engineers] → analysts, engineers). A map<string,string> holds one value per key. A MAP_ARRAY field would allow one value per list item, but it's indexed as an object (okfExtensions.<key>), not as key=value, so it wouldn't filter like customProperties. With joining, a filter matches only the whole list, while full-text search still finds each item.
  • Nested objects: flattened into dotted keys, up to three levels: x-team: {lead: alice} → x-team.lead = alice. OKF 0.3 allows nested custom values, and flattening keeps them filterable. Deeper levels are left out. If a flattened key matches a key written with dots, the first one in the file is kept and the other is reported.
  • Left out silently (they stay in raw and frontmatter): nulls, empty and blank values (empty counts as absent, including blank list items), and lists that contain objects, lists or nulls.
  • Caps: at most 50 entries per concept, in frontmatter order. Keys are up to 100 characters and can't contain =, since search stores key=value. Values are up to 1,000 characters, well under GMS's 4,096-character SEARCH_DOCUMENT_MAX_VALUE_LENGTH, which would otherwise drop longer values from the index without a word. Each file that goes over a cap, or nests too deeply, gets one warning listing the keys, and the count adds to okf_extensions_dropped in the report.
  • x-datahub-*: x-datahub-id, x-datahub-owners and x-datahub-glossary_terms are excluded because they're OKF 0.3 spellings of mapped keys. The mapping itself comes in #21885. Merge this PR after #21885 or together with it: on its own, this PR leaves those keys out of both the mapping and extensions.
  • raw stays the only source of truth. extensions is derived from it at import, like the other typed fields.

Search

The annotation copies customProperties: "/*" map, fieldType: TEXT.

  • V2: each entry is indexed as key=value (keyword plus .delimited) and queried by default, like customProperties.
  • V3: queryByDefault: false and copyToOther: true, like customProperties. Values reach full text through the shared other field and stay out of the per-field query list, so the search template golden (field-manifest.json) doesn't change.
  • Filters: EQUAL on okfExtensions with x-domain=finance is exact. IEQUAL ignores case. START_WITH with x-domain= finds documents that declare the key.

okfProperties schemaVersion goes to 3, as #21877 did for the description. With unknown-data tolerance on, a rolled-back GMS uses the version stamp to treat rows that carry extensions as the newer version's. GraphQL exposes OkfProperties.extensions: [StringMapEntry!].

The ingestion MAPPING_VERSION goes to 7. It feeds the source hash, so the next import rewrites concepts whose files haven't changed and fills extensions without a forced re-run.

Upgrade

The new field is added to the existing mappings, so no reindex is needed. Documents imported before this change have no extensions until they're imported again. Rerun the OKF ingestion recipe once; the mapping-version bump makes it rewrite every concept. RestoreIndices doesn't help here, because the stored aspects have no extensions until re-import.

Example

searchAcrossEntities(input: {
  types: [DOCUMENT], query: "*",
  orFilters: [{ and: [{ field: "okfExtensions", values: ["x-domain=finance"] }] }]
})

The agent filter alias okf.domain = finance (stacked PRs below) sends IEQUAL ["domain=finance", "x-domain=finance"] on this field.

Tests

  • test_okf_metadata.py: scalars, lists, flattening and the depth cap, skipped values, mapped keys and x-datahub-* aliases left out, the count, length and = caps with one warning.
  • test_github_documents_source.py and the GitHub and GitLab documents integration goldens: extensions on the imported concept, mapping version 7.
  • SearchDocumentTransformerTest: extensions is indexed as okfExtensions key=value entries.
  • SearchQueryBuilderTest: V2 default query fields include okfExtensions and okfExtensions.delimited.
  • V3SearchFieldsTest: okfExtensions is among the document's V3 other full-text sources.
  • DocumentMapperTest: GraphQL maps extensions, and leaves it null when unset.
  • Smoke test test_okf_extensions_are_filterable: writes a concept with x-domain, a joined list and a flattened nested key. It finds the concept by EQUAL on each one, by IEQUAL on both spellings with different case, and by START_WITH x-domain=. It also finds it by full text on an extension value, and checks that a wrong value and an undeclared key don't match.

How I tested it locally:

  • :metadata-io:test filtered to SearchTemplateGoldenTest, V3SearchFieldModelTest, V3SearchFieldsTest, SearchQueryBuilderTest, SearchDocumentTransformerTest, MultiEntityMappingsBuilderTest and V2MappingsBuilderTest, plus :datahub-graphql-core:test DocumentMapperTest: all pass. The golden is unchanged.
  • :metadata-ingestion:testSingle on the repository, GitHub and GitLab documents unit and integration tests: 330 pass. :metadata-ingestion:lint is clean for these files.
  • Docker-free stack (scripts/dev/datahub-dev.sh start --local --job smoke-test): test_okf_search.py passes on Search V3. With the V2 index on and V3 keyword reads off, the new extensions test passes too. The live V2 mapping has okfExtensions as keyword with .delimited.

Related

Checklist

  • PR title follows the Contributing Guideline
  • Tests added/updated

šŸ¤– Opened with cclaude on behalf of @shirshanka