feat(agent-context): return OKF document properties and add okf_* filter aliases

SH
3h ago
+479-6

What

Agents using the datahub-agent-context document tools now see OKF metadata and can filter on it. The same change for the standalone MCP server is in acryldata/mcp-server-datahub#301. The two keep separate copies of the tools.

  • 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. Documents without OKF get nothing extra (DocumentMapper returns null for them).
  • Filter aliases in the shared parser (metadata-ingestion/src/datahub/cli/search_filter_parser.py, which agent-context re-exports and datahub search --where also uses), all matched with IEQUAL:
    • 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 negate both fields (De Morgan), since _Not can't negate a multi-clause OR. IS [NOT] NULL works on every alias.
      As a side effect, NOT (a = x OR b = y) over plain custom fields now compiles to a != x AND b != y. It used to raise "Cannot negate a filter with multiple OR clauses".
  • Docs: FILTER_DOCS and the search_documents / get_entities descriptions cover 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.

Why it sits where it does

  • The aliases belong in the shared CLI parser. It is the one parser behind agent-context and datahub search --where, so both pick them up.
  • get_entities reads OKF with its own small GetDocumentOkfProperties query and does not add it to GetEntity. GetEntity's Document arm is a #[NEWER_GMS] block, which is off on non-Cloud servers, so OKF placed there would never reach OSS.
  • The new selections are untagged. strip_unsupported_fields=True projects them away on servers before okfProperties existed.

Testing

  • metadata-ingestion/tests/unit/cli/test_search_filter_parser.py, next to the parser: each alias, okf_id and its negation, IS [NOT] NULL, okf_stale_after comparisons, and type still meaning entity type. Every new parser line is covered.

  • New test_okf_documents.py: the gql selections, frontmatter parse and omission, and get_entities (adds OKF for documents, survives a failed lookup, skips other entities).

  • Checked by hand that the three queries validate against this branch's GraphQL schema.

  • :datahub-agent-context:lint passes, and :datahub-agent-context:testFull passes (689 passed).

  • :metadata-ingestion:testSingle on tests/unit/cli/test_search_filter_parser.py passes (28 passed).

  • :metadata-ingestion:lint: ruff passes. mypy reports errors only in azure_data_factory files this PR doesn't touch.

  • PR title follows the format

  • Tests added

  • Docs (tool descriptions) updated

  • No breaking changes


🤖 Opened with cclaude on behalf of @shirshanka