Repository navigation
feat(documents): return OKF properties and add okf_* filter aliases - #301
shirshanka wants to merge 4 commits into
Conversation
search_documents and get_entities return okfProperties for documents with OKF frontmatter, with the frontmatter parsed and capped in size. get_entities fetches it with its own query so a server without OKF loses only that, not the Document arm of GetEntity. The filter parser gains okf_type, okf_status, okf_bundle and okf_id (concept or declared id), matched with IEQUAL, plus okf_stale_after for comparisons. Tool descriptions document them, searching by OKF id, and that type means entity type.
…status OKF treats a missing status as stable. okf_status = stable (or an IN list containing stable) now also matches OKF documents that declare no status, and its negation excludes them. Tool descriptions say so, and note that okf_stale_after IS NULL also matches unreadable values.
nwadams
left a comment
There was a problem hiding this comment.
Approved. I left four inline comments on frontmatter preservation and OKF filter behavior. The local unit suite, lint, type checks, and wheel build passed. The Cloud integration job returned 401 Unauthorized.
|
|
||
| return graphql_helpers.clean_gql_response(response) | ||
| return graphql_helpers.cap_okf_frontmatter( | ||
| graphql_helpers.clean_gql_response(response) |
There was a problem hiding this comment.
[P2] Preserve frontmatter through the hybrid merge. This parses frontmatter before the hybrid path runs clean_gql_response again. I reproduced keyword search preserving explicit nulls, empty lists, and nested metadata while hybrid search dropped them for the same document. Can we parse frontmatter after the final cleanup or have the cleaner preserve the parsed object?
There was a problem hiding this comment.
🤖 Fixed in 449f4f2. The hybrid path now asks _search_documents_impl to leave the frontmatter as the raw string (shape_okf=False), and parses it after the merged response's last cleanup. Keyword search is unchanged. New test test_keyword_and_hybrid_search_return_the_same_frontmatter checks that both paths return the same frontmatter, with nulls, empty lists and nested empty objects kept.
| if ( | ||
| isinstance(inner, _Or) | ||
| and len(inner.or_) > 1 | ||
| and all(len(c.compile()) == 1 for c in inner.or_) |
There was a problem hiding this comment.
[P2] Handle OKF aliases inside negated groups. NOT (okf_id = x OR okf_type = guide) raises Cannot negate a filter with multiple OR clauses on the locked SDK. okf_id already expands to an OR, so the clause-count guard falls through to _Not. Recursively applying De Morgan’s law would cover the nested case.
There was a problem hiding this comment.
🤖 Fixed in 449f4f2. _negate_filter now applies De Morgan recursively: NOT over OR becomes an AND of negated branches, NOT over a multi-clause AND becomes an OR of them, and NOT NOT cancels. NOT (okf_id = x OR okf_type = guide) and NOT (okf_id = x AND okf_type = guide) now compile; test_negated_group_with_multi_field_alias covers both.
| if normalized == "env": | ||
| return _negate_env_filter(list(values)) | ||
| return F.not_(_make_filter(field, values)) | ||
| return _negate_filter(_make_filter(field, values)) |
There was a problem hiding this comment.
[P2] Scope the negated stable-status filter to OKF documents. The compiled okf_status != stable filter includes a branch for documents without okfConceptId or okfStatus, so ordinary documents can fill the page. The PR description says documents without a status are excluded. Requiring okfConceptId would keep this filter scoped to OKF documents.
There was a problem hiding this comment.
🤖 Fixed in 449f4f2. Negating the stable expansion now gives okfStatus NOT IEQUAL stable AND EXISTS okfStatus AND EXISTS okfConceptId, so it matches only OKF documents that declare another status. Documents without a status and non-OKF documents stay out. The test checks the compiled rules for both != and NOT ... =.
| case-insensitive), e.g. filter="okf_type = guide AND okf_status = stable". | ||
| - okf_id matches the concept id (bundle-relative path without .md, e.g. | ||
| guides/mau) or the frontmatter id (e.g. guide:mau). Ids are scoped to a | ||
| bundle; add okf_bundle to pin one. |
There was a problem hiding this comment.
[P3] Include the bundle root when disambiguating IDs. okf_bundle filters by repository location. Two bundle roots in the same repository can share an ID, so adding this filter can still return both. Could we document how to combine it with okfBundleRootPath, or add a root-path alias?
There was a problem hiding this comment.
🤖 Added an okf_bundle_root alias in 449f4f2. It maps to okfBundleRootPath, case-insensitive like the others. FILTER_DOCS and the search_documents description show pinning a bundle with both, e.g. okf_id = guides/mau AND okf_bundle = \"https://github.com/org/repo\" AND okf_bundle_root = context. The PR description is updated too.
- Hybrid search shapes OKF frontmatter after its final cleanup, so it keeps the same nulls, empty lists and nested values as keyword search. - Negation applies De Morgan recursively, so groups that contain okf_id (which spans two fields) can be negated. - okf_status != stable matches only OKF documents that declare another status. - New okf_bundle_root alias for the bundle root path, documented for use with okf_bundle.
What
Agents using the document tools now see OKF metadata and can filter on it.
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, parsed after the last response cleanup. Keyword and hybrid search therefore return the same values, including nulls and empty lists. 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).search_filter_parser.py, all matched withIEQUAL(case-insensitive):okf_type→okfTypeokf_status→okfStatusokf_bundle→okfBundleLocationokf_bundle_root→okfBundleRootPath. One repository can hold several bundles, so the descriptions show pinning a bundle withokf_bundleandokf_bundle_roottogether.okf_id→okfConceptIdORokfDeclaredIdokf_stale_after→okfStaleAfter, for>/</IS NULL(epoch ms)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 != stable(andNOT okf_status = stable) matches only OKF documents that declare a status other than stable. Other values match as written.okf_stale_after IS NULLis not "never stale": it also matches documents whosestale_aftervalue could not be read.Negation applies De Morgan recursively, so
NOT okf_id = x,okf_id != xand groups such asNOT (okf_id = x OR okf_type = guide)work. Before,_Notrejected them becauseokf_idspans two fields.IS [NOT] NULLworks on every alias.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
okfPropertiesexists from DataHub 1.10. Its lines are tagged#[NEWER_GMS]: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
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.make lintandmake test: 773 passed.The same change for
datahub-agent-context: datahub-project/datahub#21876.🤖 Opened with cclaude on behalf of @shirshanka