feat(okf): make OKF frontmatter extensions searchable and filterable
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").customPropertieswould 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 aliasesx-datahub-id,x-datahub-ownersandx-datahub-glossary_termsare 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). Amap<string,string>holds one value per key. AMAP_ARRAYfield would allow one value per list item, but it's indexed as an object (okfExtensions.<key>), not askey=value, so it wouldn't filter likecustomProperties. 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
rawandfrontmatter): 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 storeskey=value. Values are up to 1,000 characters, well under GMS's 4,096-characterSEARCH_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 tookf_extensions_droppedin the report. x-datahub-*:x-datahub-id,x-datahub-ownersandx-datahub-glossary_termsare 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 andextensions.rawstays the only source of truth.extensionsis 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, likecustomProperties. - V3:
queryByDefault: falseandcopyToOther: true, likecustomProperties. Values reach full text through the sharedotherfield and stay out of the per-field query list, so the search template golden (field-manifest.json) doesn't change. - Filters:
EQUALonokfExtensionswithx-domain=financeis exact.IEQUALignores case.START_WITHwithx-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 andx-datahub-*aliases left out, the count, length and=caps with one warning.test_github_documents_source.pyand the GitHub and GitLab documents integration goldens: extensions on the imported concept, mapping version 7.SearchDocumentTransformerTest:extensionsis indexed asokfExtensionskey=valueentries.SearchQueryBuilderTest: V2 default query fields includeokfExtensionsandokfExtensions.delimited.V3SearchFieldsTest:okfExtensionsis among the document's V3otherfull-text sources.DocumentMapperTest: GraphQL mapsextensions, and leaves it null when unset.- Smoke test
test_okf_extensions_are_filterable: writes a concept withx-domain, a joined list and a flattened nested key. It finds the concept byEQUALon each one, byIEQUALon both spellings with different case, and bySTART_WITHx-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:testfiltered toSearchTemplateGoldenTest,V3SearchFieldModelTest,V3SearchFieldsTest,SearchQueryBuilderTest,SearchDocumentTransformerTest,MultiEntityMappingsBuilderTestandV2MappingsBuilderTest, plus:datahub-graphql-core:testDocumentMapperTest: all pass. The golden is unchanged.:metadata-ingestion:testSingleon the repository, GitHub and GitLab documents unit and integration tests: 330 pass.:metadata-ingestion:lintis clean for these files.- Docker-free stack (
scripts/dev/datahub-dev.sh start --local --job smoke-test):test_okf_search.pypasses on Search V3. With the V2 index on and V3 keyword reads off, the new extensions test passes too. The live V2 mapping hasokfExtensionsas keyword with.delimited.
Related
- Agent filter alias
okf.<key>: #21888 (stacked on #21876) and acryldata/mcp-server-datahub#303 (stacked on acryldata/mcp-server-datahub#301).
Checklist
- PR title follows the Contributing Guideline
- Tests added/updated
š¤ Opened with cclaude on behalf of @shirshanka