feat(documents): return OKF properties and add okf_* filter aliases
SH
3h ago+632+632+012345678901234567890123456789-5-5-0123456789
What
Agents using the document tools now see OKF metadata and can filter on it.
- Fields:
search_documents(keyword and semantic) andget_entitieson a document returnokfProperties:type,status,conceptId,declaredId,description,staleAfter,bundle { location rootPath okfVersion }andfrontmatter. The frontmatter comes back as a JSON object. AboveOKF_FRONTMATTER_CHAR_LIMIT(4000 chars, env-configurable) it is left out andfrontmatterOmittedsays why, since cutting JSON short would make it unparseable. Documents without OKF frontmatter get nothing extra (GMS returnsokfProperties: nullfor them). - Filter aliases in
search_filter_parser.py, all matched withIEQUAL(case-insensitive):okf_type→okfTypeokf_status→okfStatusokf_bundle→okfBundleLocationokf_id→okfConceptIdORokfDeclaredIdokf_stale_after→okfStaleAfter, for>/</IS NULL(epoch ms)- A missing status is stable, as OKF specifies. So
okf_status = stable(or anINlist containing it) becomesokfStatus 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 != stableexcludes documents without a status. Other values match as written. - The descriptions say
okf_stale_after IS NULLis not "never stale": it also matches documents whosestale_aftervalue could not be read.
NOT okf_id = xandokf_id != xwork through De Morgan, since the SDK's_Notcan't negate a multi-clause OR.IS [NOT] NULLworks on every alias.
- Tool descriptions:
search_documents,get_entitiesand the sharedFILTER_DOCSdescribe the aliases, searching by OKF id (query="guide:mau", Search V3), and thattypemeans entity type, so document types go throughsubtype/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_entitiesreads it with its own smallGetDocumentOkfPropertiesquery (document URNs only), the same approach asGetAssertionEntity. Adding it toentity_details.gqlwould cost servers from 1.4 to 1.9 every Document field inGetEntity, 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,typestill meaning entity type, the gql selections and their tags, frontmatter shaping and omission, andget_entities(adds OKF for documents, survives a failed OKF lookup, skips it for other entities). test_gql_schema_compat.pynow 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 lintandmake test: 769 passed.
The same change for datahub-agent-context: datahub-project/datahub#21876.
🤖 Opened with cclaude on behalf of @shirshanka