Entity graph endpoint — medium/low review findings (post #37) #105
damienriehl
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Entity graph endpoint — medium / low review findings (post #37)
The peer review on #37 surfaced 7 medium and 9 low items in addition to the blocking + high findings already resolved by #104. None are correctness blockers, but several are worth tracking for follow-up. Ordered by severity, then by likely time-to-fix.
Medium
M1 — Use
RETURNINGfrom upsert inupdate_lint_configNote: This was in the #94 review, not #37 — including here only if relevant. (Skip if not applicable.)
M1 (real) — Concurrent first-time PUT on entity graph config
N/A — entity graph endpoint is read-only; nothing to upsert.
M1' —
_child_countre-scans the graph per nodeontokit/services/ontology.py—_child_count(uri)runsgraph.subjects(RDFS.subClassOf, uri)and intersects withOWL.Classtriples for every node invisited. For a 200-node truncation cap with deep ontologies, that's up to 200 reverse triple lookups. Bounded but redundant — could memoize.M2 — Worker fails opaquely if migration hasn't run
Note: This was a #94 finding. If the entity graph endpoint has analogous brittleness on missing schema, file separately.
M3 —
is_rootfield redundant withnode_type ∈ {"root", "secondary_root"}ontokit/schemas/graph.py:GraphNodeexposes both. After the secondary_root reclassification,is_rootno longer maps cleanly. Pick one and drop the other (or rename one todiscovered_via: Literal["primary", "see_also"]).M4 —
total_concept_countis misleadingly namedontokit/schemas/graph.py:EntityGraphResponse.total_concept_count— set tototal_discovered, which is "unique IRIs the BFS attempted to materialize, including those rejected bymax_nodes." Calling it "concept count" implies it's the count of concepts in the ontology. Rename todiscovered_node_countor similar; document that it's the BFS frontier size including truncated nodes.M5 — Edge
iduses string concat with no escapingontokit/services/ontology.py:_add_edge—f"{source}->{target}:{edge_type}". IRIs can theoretically contain:(and rarely->); two distinct edges could collide on the same id, and the dedup check silently drops the second. Use a tuple key(src, dst, edge_type)inedge_idsinstead of a stringified id.M6 — Migration story for the deleted
class-hierarchyendpointThe original PR removed a stub
class_hierarchyendpoint that always raisedNotImplementedError. Removing it is correct, but a one-line note in the PR description would have clarified for OpenAPI consumers that no working API path was deleted.M7 — Three different
seenvariables in same functionbuild_entity_graphhad innerseen: set[str]for the BFS visited tracker, and the seeAlso helpers each had their ownseen: set[URIRef]. After H4's extraction this is partially resolved (helpers are top-level now), but the BFS body still usesseenfor one purpose; consider renaming for clarity.Low
L1 —
_classify_node's third arg_depthis unusedontokit/services/ontology.py:_classify_node(uri, is_focus, _depth). Drop the parameter.L2 — Negative depth convention is undocumented
Ancestors BFS uses negative depths (
-(current_depth + 1)) but the schema fielddepth: int = 0doesn't document this. Either document in the schema docstring or split intoancestor_depth: int | None/descendant_depth: int | None.L3 — seeAlso targets discovered with
depth=0Collides with focus
depth=0. Frontend hasis_focusto disambiguate, but the BFS depth field becomes ambiguous for layout. Worth noting in the schema.L4 —
_get_local_namedoesn't handle empty trailing slashiri.rsplit("/", 1)[-1]returns""if iri ends with/. Edge case.L5 — Double-check depth limits stay in sync if classes.py route is reintroduced
Project route uses
ge=0, le=10; the (now-deleted) classes.py route used the same. If that route is ever re-added, mirror the limits.L6 —
if TYPE_CHECKING:import + runtime import is duplicativefrom ontokit.schemas.graph import EntityGraphResponseis imported both in theTYPE_CHECKINGblock at module top AND inside the function. Withfrom __future__ import annotations, theTYPE_CHECKINGimport alone suffices for annotations.L7 —
EXTERNAL_NAMESPACESis a tuple ✅Verified by grep that it's never mutated. Tuple is correct here. (Already resolved.)
L8 —
_service_with_graph(OntologyService(storage=None))Test relies on
storagebeingNone-allowed. VerifyOntologyService.__init__signature matches.L9 — Test repetition
tests/unit/test_entity_graph.pyhas many tests that call_base_graph()then add 1–2 triples. A small builder pattern (graph_with_chain(["A", "B", "C"])) would compress and improve readability.If anyone wants to pick any of these up, comment below and we can split into individual issues.
Beta Was this translation helpful? Give feedback.
All reactions