Skip to content

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

Open
shirshanka wants to merge 4 commits into
mainfrom
okf-agent-tools
Open

shirshanka wants to merge 4 commits into
mainfrom
okf-agent-tools

Conversation

@shirshanka

@shirshanka shirshanka commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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, parsed after the last response cleanup. Keyword and hybrid search therefore return the same values, including nulls and empty lists. 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_bundle_root → okfBundleRootPath. One repository can hold several bundles, so the descriptions show pinning a bundle with okf_bundle and okf_bundle_root together.
    • 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 (and NOT okf_status = stable) matches only OKF documents that declare a status other than stable. 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.
      Negation applies De Morgan recursively, so NOT okf_id = x, okf_id != x and groups such as NOT (okf_id = x OR okf_type = guide) work. Before, _Not rejected them because okf_id spans two fields. 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: 773 passed.

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


🤖 Opened with cclaude on behalf of @shirshanka

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 nwadams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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_)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cclaude Opened from a cclaude box

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants