🕸 Proposal: a GROBID stage for a corpus-internal citation graph

Status: proposal.

A proposal, not a plan: nothing described here is built, and [grobid] is not a setting that exists. This document argues a case and records what it would cost; the decision has not been taken.

Written for someone weighing whether to add the stage. It assumes ARCHITECTURE.md for the four layers and PDF-PARSER.md for why GROBID was removed from this repository, which this proposal has to answer before it can argue anything else.

🧭 Table of contents

💡 Answering the removal first

GROBID was in this repository and was removed. Any proposal to bring it back has to say what is different, so:

What only GROBID offered was parsing a paper's own reference list into structured author/title/year/DOI records, via the /api/processFulltextDocument endpoint this repo never called. That serves corpus discovery [...] If corpus-growth-by-snowballing later becomes a real workflow, the case to revisit is for /api/processFulltextDocument specifically, not the header endpoint that was here.

From PDF-PARSER.md

This proposal is that revisit. The removed integration called /api/processHeaderDocument for title, authors and abstract, metadata papers/bibliography.bib already supplies for every document, which is why it earned nothing. What is proposed here calls /api/processFulltextDocument for reference lists, which the bib file does not supply and nothing else in the pipeline can derive.

That is a difference in capability. It does not dispose of the operational objection (a pinned JDK 21, a multi-GB Gradle build, and a long-running service), which is unchanged and is the main cost weighed in What it would cost.

🔭 Where the repository stands today

Two layers touch PDFs, and neither produces bibliographic structure:

What neither produces is structured bibliographic metadata and a citation graph. The only metadata source is papers/bibliography.bib itself, parsed by chitragupta/core/corpus/bib_reader.py: whatever your reference manager exported. There are no in-text citation contexts, no resolved reference list per paper, and no way to ask "does paper A cite paper B" within this corpus.

_EXTRACTORS looks like the seam for a new backend, and it is the wrong one. It exists to swap what the corpus layer's plain text is made of: one PDF in, one .txt out. GROBID's TEI is structurally different data (nested XML with header, body and back sections), and forcing it through that table would mean either discarding everything but body text (defeating the point) or making pdf_text/ non-uniform in its return type. The right precedent is docling_parse.py: a corpus-wide stage under chitragupta/core/corpus/enrich/, run from chitragupta/cli/enrich.py, independent of [parser].backend.

⚖ Why GROBID and docling, not GROBID instead of docling

Each is purpose-built for something the other is not:

GROBID docling
Header metadata Purpose-built (title, authors, affiliations, abstract) General layout detection, not citation-schema-aware
References Structured TEI records, ~0.87-0.90 F1 No dedicated citation parser
Body text and sections Adequate; sometimes misses full section isolation Strong; this repo depends on it for reading order
Quotable passages Not its job The .passages.json sidecar a claim is quoted from
Output XML/TEI JSON, Markdown

GROBID answers "what is this paper and what does it cite"; docling answers "what does this paper say".

The cost argument is favourable. A GROBID call does sequence labelling, not layout or OCR inference, so it is orders of magnitude cheaper per document than a docling parse, which PERFORMANCE.md measures at 55m 30s for a serial 501-PDF pass with OCR off, CPU-bound even on a GPU host (~7% SM utilisation on an A40). GROBID writes to a separate artefact, so it does not compete for the same CPU-bound budget.

🏗 Proposed design

📍 Where the stage sits

Diagram: grobid stage

The two new modules are shaded. Both read chitragupta/core/corpus/enrich/corpus.py, which sources the corpus from the ledger and nothing else, so every document GROBID sees is one a draft is allowed to cite. That is a deliberate constraint; see AGENTS.md.

🐍 chitragupta/core/corpus/enrich/grobid_parse.py

Modelled on docling_parse.py: corpus-wide, incremental, self-probing. It calls GROBID's /api/processFulltextDocument per PDF and writes the TEI to content/grobid/<citekey>.tei.xml.

It must follow the same three conventions every stage here follows:

Status vocabulary, matching chitragupta/core/corpus/enrich/stages.py:

Condition Report
[grobid].enabled = false skipped
Service unreachable at [grobid].url service-unavailable
TEI written ok
GROBID returns malformed or empty TEI for one PDF partial, with a warning naming the citekey; one bad document does not fail the corpus

🐍 chitragupta/core/corpus/enrich/citation_graph.py

Parses each TEI's <listBibl>, extracts each referenced work's title/DOI, and resolves it against the ledger's existing citekeys.

Diagram: grobid citation graph

Output is an edge list of citekey -> [citekeys it cites, restricted to this corpus].

Nothing else in the pipeline can fill this gap. BM25 in chitragupta/core/draft/retrieval.py and the embedding index in chitragupta/core/corpus/enrich/embed_index.py both rank on body-text similarity. Neither can answer "what does this corpus treat as foundational" or "cluster these papers by citation structure rather than by topic model", because there is no citation-structure data to answer from.

⚙ Configuration

A new section, following the existing [parser]/[enrich] pattern, each key overridable by an env var of the same name:

[grobid]
enabled = false                  # GROBID_ENABLED
url = "http://localhost:8070"    # GROBID_URL
timeout_seconds = 120            # GROBID_TIMEOUT_SECONDS
consolidate_citations = 1        # GROBID_CONSOLIDATE_CITATIONS
                                 # 0/1/2 -- GROBID's own levels; higher is
                                 # more accurate, slower, and needs
                                 # external lookups

consolidate_citations needs a flag in the requirements table: GROBID's consolidation calls CrossRef to resolve incomplete reference strings, so this stage may need network access per document at parse time. Everything else here needs the network once, for model downloads, and never again.

🐳 Runtime

GROBID runs as a long-lived service rather than an in-process import:

docker run --rm -p 8070:8070 grobid/grobid:0.9.0

That fits the existing container story (DOCKER.md) as a sidecar. Invocation would extend --stages:

.venv-full/bin/python -m chitragupta.enrich --stages grobid,citation_graph

🔑 Respecting the citekey invariant

The hard rule is unchanged and this stage does not get an exception. GROBID's consolidated references routinely resolve to DOIs and titles not in papers/bibliography.bib. Those become edges to external nodes, never new citable claims. citation_graph.py may only ever resolve a reference against an existing ledger citekey; it must never mint one.

Two consequences follow:

⚡ What it would cost

The operational objection that removed GROBID still stands:

Cost Detail
A pinned JDK 21 Its bundled Kotlin compiler cannot parse a JDK 25 version string
A multi-GB, multi-minute build Or accepting the prebuilt Docker image and its footprint
A long-running service on port 8070 The only component here that is not a batch job, a new operational shape
Per-document network With consolidate_citations > 0. New for this pipeline
A new artefact in the reproducibility contract ARCHITECTURE.md is artifact-by-artifact; .tei.xml and citation_graph.json each need a row, and consolidation makes the graph depend on an external service's state, so it is unlikely to be reproducible at all

The case turns on whether snowballing is a real workflow here. If corpus growth stays "notice a paper, catalogue it in Zotero, re-export", the graph is interesting but unused, and this is a service and a JDK for a feature nobody runs. If it becomes routine, this is the only design that supports it without touching the citekey invariant.

🚫 What this does not change

❓ Open questions