Skip to content

PR 2: Canonical KG schema refactor - #3

Merged
mengerj merged 1 commit into
mainfrom
pr2-canonical-kg-schema
Jun 23, 2026
Merged

PR 2: Canonical KG schema refactor#3
mengerj merged 1 commit into
mainfrom
pr2-canonical-kg-schema

Conversation

@mengerj

@mengerj mengerj commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Scope (one roadmap item: PR 2)

Introduce the source-agnostic canonical KG schema and migrate the CELLxGENE builder + tests onto it. No new source; the LLM/narrative path is left in place for PR 3 to remove.

Changes

models/graph_schema.py

  • PublicationNodeStudyNode (study_id, title, source, modality); dropped abstract and experimental_narrative.
  • DatasetNode: uridata_uri, modalityassay. Parent study is an EXTRACTED_FROM edge, not a stored field.
  • SampleNode added — design covariates only (condition, perturbation, timepoint, subject, organism, data_uri; all optional).
  • CellType removed from EntityType (data-inferred annotation → would leak the downstream learning target).
  • KnowledgeGraphOutput.publicationsstudies; added samples.
  • NarrativeOutput kept as a transitional agent schema (PR 3 deletes it).

graph/builder.pybuild_knowledge_graph(paper_data, cellxgene_data) (no narrative arg). Emits canonical nodes; ignores input cell_types; tissueHAS_TISSUE, diseaseHAS_CONDITION, assayMEASURED_WITH, study→species STUDIES. source="CELLxGENE", study modality="scRNA-seq". No SampleNodes yet (Census is dataset-level — see ARCHITECTURE §6).

main.py — step 3 drops the narrative arg; summary prints Studies/Samples. Step 2 (Azure narrative) is retained but its output is now discarded, marked with a comment; PR 3 removes the whole path.

Docs — ARCHITECTURE §4 records the edge-only containment decision; ROADMAP ticks PR 2 and moves ▶ Next up to PR 3.

Design decision

Containment is edge-only. DatasetNode does not store its parent study_id; the EXTRACTED_FROM edge is the single source of truth, avoiding a denormalized FK that can drift.

Deferred to PR 3 (intentionally not done here)

  • models/narrative.py + test_models.py (legacy GEO agent schema) untouched.
  • NarrativeOutput and _build_narrative_prompt (still references cell_types) remain — they're part of the narrative path PR 3 deletes wholesale.

Verification (all four CI gates, run locally)

  • ruff check .
  • ruff format --check .
  • mypy src/parce ✅ (16 files)
  • pytest -m "not integration"52 passed, incl. a hermetic run with .env moved aside (no Settings() constructed unmocked).

No dependency changes.

🤖 Generated with Claude Code

Introduce the source-agnostic canonical schema and migrate the CELLxGENE
builder + tests onto it. No new source.

Schema (models/graph_schema.py):
- PublicationNode -> StudyNode (study_id, title, source, modality); drop
  abstract and experimental_narrative.
- DatasetNode: uri -> data_uri, modality -> assay; parent study is an edge,
  not a stored field.
- Add SampleNode with design covariates only (condition, perturbation,
  timepoint, subject, organism, data_uri; all optional).
- Remove CellType from EntityType (data-inferred -> leakage).
- KnowledgeGraphOutput.publications -> studies; add samples.

Builder (graph/builder.py): build_knowledge_graph(paper_data, cellxgene_data)
emits canonical nodes; ignores input cell_types; tissue=HAS_TISSUE,
disease=HAS_CONDITION, assay=MEASURED_WITH, study->species STUDIES. No samples
yet (Census is dataset-level).

main.py: KG no longer stores a narrative; the Azure narrative step is retained
but its output is discarded until PR 3 removes the path. Updated ARCHITECTURE.md
(edge-only containment decision) and ROADMAP.md (PR 2 done, PR 3 next).

Gates: ruff check, ruff format --check, mypy (16 files), 52 unit tests pass,
hermetic with no .env.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mengerj
mengerj marked this pull request as ready for review June 23, 2026 08:51
@mengerj
mengerj merged commit ee78616 into main Jun 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant