feat(documents): return OKF properties and add okf_* filter aliases

SH
3h ago
+632-5

What

Agents using the document tools now see OKF metadata and can filter on it.

  • Fields: search_documents (keyword and semantic) and get_entities on a document return okfProperties: type, status, conceptId, declaredId, description, staleAfter, bundle { location rootPath okfVersion } and frontmatter. The frontmatter comes back as a JSON object. Above OKF_FRONTMATTER_CHAR_LIMIT (4000 chars, env-configurable) it is left out and frontmatterOmitted says why, since cutting JSON short would make it unparseable. Documents without OKF frontmatter get nothing extra (GMS returns okfProperties: null for them).
  • Filter aliases in search_filter_parser.py, all matched with IEQUAL (case-insensitive):
    • okf_type → okfType
    • okf_status → okfStatus
    • okf_bundle → okfBundleLocation
    • okf_id → okfConceptId OR okfDeclaredId
    • okf_stale_after → okfStaleAfter, for >/</IS NULL (epoch ms)
    • A missing status is stable, as OKF specifies. So okf_status = stable (or an IN list containing it) becomes okfStatus IEQUAL stable OR (NOT EXISTS okfStatus AND EXISTS okfConceptId). Every OKF document has a conceptId, so that term keeps non-OKF documents out. okf_status != stable excludes documents without a status. Other values match as written.
    • The descriptions say okf_stale_after IS NULL is not "never stale": it also matches documents whose stale_after value could not be read.
      NOT okf_id = x and okf_id != x work through De Morgan, since the SDK's _Not can't negate a multi-clause OR. IS [NOT] NULL works on every alias.
  • Tool descriptions: search_documents, get_entities and the shared FILTER_DOCS describe the aliases, searching by OKF id (query="guide:mau", Search V3), and that type means entity type, so document types go through subtype / okf_type.

Compatibility

okfProperties exists from DataHub 1.10. Its lines are tagged #[NEWER_GMS]:

  • In the document search queries there are no other tagged fields, so on an older server the fallback drops only OKF.
  • get_entities reads it with its own small GetDocumentOkfProperties query (document URNs only), the same approach as GetAssertionEntity. Adding it to entity_details.gql would cost servers from 1.4 to 1.9 every Document field in GetEntity, because that fallback drops every tagged line at once.

Testing

  • New tests/test_mcp/test_okf_documents.py: compiled filters for each alias, case-insensitive alias names, IN, negation, IS NULL, comparisons, type still meaning entity type, the gql selections and their tags, frontmatter shaping and omission, and get_entities (adds OKF for documents, survives a failed OKF lookup, skips it for other entities).
  • test_gql_schema_compat.py now covers the three changed or new queries: fallback variants validate against the vendored v1.4.0–v1.8.0 schemas.
  • Checked by hand that the full queries validate against the schema on datahub master.
  • make lint and make test: 769 passed.

The same change for datahub-agent-context: datahub-project/datahub#21876.


🤖 Opened with cclaude on behalf of @shirshanka