PR 2: Canonical KG schema refactor - #3
Merged
Merged
Conversation
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
marked this pull request as ready for review
June 23, 2026 08:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pyPublicationNode→StudyNode(study_id,title,source,modality); droppedabstractandexperimental_narrative.DatasetNode:uri→data_uri,modality→assay. Parent study is anEXTRACTED_FROMedge, not a stored field.SampleNodeadded — design covariates only (condition,perturbation,timepoint,subject,organism,data_uri; all optional).CellTyperemoved fromEntityType(data-inferred annotation → would leak the downstream learning target).KnowledgeGraphOutput.publications→studies; addedsamples.NarrativeOutputkept as a transitional agent schema (PR 3 deletes it).graph/builder.py—build_knowledge_graph(paper_data, cellxgene_data)(nonarrativearg). Emits canonical nodes; ignores inputcell_types;tissue→HAS_TISSUE,disease→HAS_CONDITION,assay→MEASURED_WITH, study→speciesSTUDIES.source="CELLxGENE", studymodality="scRNA-seq". NoSampleNodes yet (Census is dataset-level — see ARCHITECTURE §6).main.py— step 3 drops thenarrativearg; summary printsStudies/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.
DatasetNodedoes not store its parentstudy_id; theEXTRACTED_FROMedge 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.NarrativeOutputand_build_narrative_prompt(still referencescell_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.envmoved aside (noSettings()constructed unmocked).No dependency changes.
🤖 Generated with Claude Code