feat(download-ref): store arXiv LaTeX sources as KB full text - #28
Open
chenpeizhi wants to merge 14 commits into
Open
feat(download-ref): store arXiv LaTeX sources as KB full text#28chenpeizhi wants to merge 14 commits into
chenpeizhi wants to merge 14 commits into
Conversation
…or in find_main_tex
…tions All post-cache operations (flatten, write_text, copy_figures) are now guarded by a comprehensive try/except that degrades to 'miss' for any exception. This ensures one bad paper does not abort the entire batch fetch in fetch_metadata.py. Added test_fetch_arxiv_source_flatten_error_miss to verify OSError in flatten() degrades gracefully to 'miss' rather than propagating.
…urces Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ng cache sentinel Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…preprint Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Store flattened e-print LaTeX as the full-text body for arXiv refs (full_text: latex), PDF->Markdown retained as fallback and for DOIs. Papis integration evaluated and deferred (see Non-goals). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Neither skill invokes fetch_metadata.py directly, so only download-ref/SKILL.md needed the --download-arxiv-source flag. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- tex_source module docstring covers the DOI-preprint destination overrides - fetch_arxiv_source reuses an already-fetched arXiv copy (tex + figures) when the same paper appears both as an arXiv entry and a DOI preprint, instead of downloading twice - SKILL.md done checklist covers the DOI-preprint .tex case - drop unused capsys fixture in test_index Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
@GiggleLiu Any comments? |
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.
Motivation
The knowledge base's rendered
.mdfiles are the agent-facing text: advisor subagents,survey-writer, andpaper-reviewerall Read/Grep them, andINDEX.md/references.bibare derived from them. Today those bodies come from PDF-to-Markdown conversion (pymupdf4llm), which is lossiest exactly where physics/math papers carry their content — equations, operators, sub/superscripts come out garbled, and two-column layouts shred sentence flow.For arXiv papers the author's LaTeX source is available and is ground truth for the math and structure. LLM agents read raw LaTeX natively, so no conversion step is needed — the fidelity is free. In practice most KB refs are arXiv papers or journal articles with arXiv preprints, so following
externalIds.ArXivfor DOI entries extends the benefit to journal-DOI bibs without giving up journal-grade metadata.Deliberate scoping decisions (recorded in the spec):
.mdwrapper stays canonical. The file-type contract (frontmatter,<id>_<slug>.mdnaming,INDEX.mdregeneration, downstream skill globs, and the vendored-helper family in quantum.harness/init-harness) is untouched — only the body's source changes, marked by the newfull_text: latexvalue..raw/storage backend would diverge the layout shared with the harness family. See the spec's Non-goals.Summary
Store arXiv e-print LaTeX sources as the full-text body of rendered knowledge-base entries, instead of PDF-to-Markdown conversion. PDF rendering (pymupdf4llm) remains the fallback for refs without source.
Design spec:
docs/specs/2026-08-03-arxiv-latex-source-design.md(included in this PR).What changed
skills/download-ref/helpers/tex_source.py(stdlib-only): e-print download, payload detection (tarball / single-file / PDF-only submissions / withdrawn-paper HTML), path-traversal-safe tar extraction, main-file discovery,\input/\includeflattening (latexpandwhen installed, built-in Python inliner otherwise), figure copying into.figures/, and thefetch_arxiv_sourceorchestrator (statusesok/cached/pdf-only/miss; all failures degrade, one bad paper never aborts a batch).fetch_metadata.py: new--download-arxiv-sourceflag. Fetches source for arXiv manifest entries and for DOI entries whose Semantic Scholar record names an arXiv preprint (externalIds.ArXiv) — mirroring the existing arXiv-PDF paywall fallback. When the same paper appears both as an arXiv entry and as a DOI preprint, the already-fetched source is reused (tex + figures copied) instead of downloaded twice.render.py:render_arxivandrender_doiprefer the flattened.tex(full_text: latex, raw LaTeX under## Full Text (LaTeX source)); PDF path unchanged otherwise.index.py:full_text: latexcounts as full text.skills/download-ref/SKILL.md(preflight, Step 4/5, owns-list, checklist, common mistakes) andCLAUDE.md.The KB contract is unchanged: same
<id>_<slug>.mdfilenames, frontmatter keys,INDEX.mdregeneration,references.bibflow, and.raw//.figures/layout —full_textgains the valuelatexadditively, so existing KBs and the quantum.harness/init-harness vendored-helper family are unaffected (theirmd_to_bibtex.pyshould learnlatexis truthy on their next helper sync).Testing
tests/test_tex_source.py,tests/test_render_tex.py,tests/test_index.py): real tar/gzip payloads, network mocked only aturlopen; covers traversal, broken symlinks, permission errors, PDF-only submissions, withdrawn papers, flatten crashes, destination overrides, and both render paths.main(missingskills/ideas/SKILL.md, unrelated) are unchanged.full_text: latex), INDEX, and idempotent(cached)re-runs verified against the real endpoints.Review follow-ups
The three cosmetic items flagged in review (arXiv-centric module docstring, arXiv/DOI double fetch for papers listed both ways, done-checklist wording) are addressed in the final commit.
🤖 Generated with Claude Code