Skip to content

feat(pdf): CORE fallback + Unpaywall oa_locations fix + .env support#1

Open
Navier8 wants to merge 6 commits into
kuff:mainfrom
Navier8:feat/pdf-cascade-improvements
Open

feat(pdf): CORE fallback + Unpaywall oa_locations fix + .env support#1
Navier8 wants to merge 6 commits into
kuff:mainfrom
Navier8:feat/pdf-cascade-improvements

Conversation

@Navier8

@Navier8 Navier8 commented May 1, 2026

Copy link
Copy Markdown

Problem

The S2 API's openAccessPdf field returns null for some papers even when free copies exist. Example: Position based fluids (Corpus ID 611962) — Unpaywall's best_oa_location is also empty, and ACM returns 403.

Changes

  • Unpaywall: now scans all oa_locations[], not just best_oa_location
  • CORE aggregator added as a new cascade step after Unpaywall/publisher — searches by DOI then title; successfully retrieves the above paper (2.6 MB, confirmed 200 OK). CORE aggregator often has author-hosted preprints not in Unpaywall
  • Google Scholar last resort using the existing _fetch_scholar_page / _parse_scholar_results infrastructure
  • .env support via python-dotenv (optional dep, gracefully skipped if absent); adds .env.example template

New cascade order

S2 OA → ArXiv → Unpaywall → Publisher → CORE → Google Scholar

Navier8 added 6 commits May 1, 2026 21:17
PDF cascade improvements for papers where the S2 API openAccessPdf field
is null despite open-access copies existing (e.g. ACM papers with
author-hosted preprints).

Changes:
- _unpaywall_pdf_url: scan all oa_locations[], not just best_oa_location,
  so author-hosted PDFs in secondary locations are not silently missed
- Add _core_pdf_url: queries the CORE aggregator (core.ac.uk) by DOI
  then title; honours optional CORE_API_KEY env var for higher rate limits
- Add _scholar_pdf_url_for_title: searches Google Scholar as a last resort,
  matching by Jaccard title similarity (>= 0.85) to avoid wrong-paper hits
- Wire both into _download_pdf_bytes cascade:
    S2 OA -> ArXiv -> Unpaywall -> Publisher -> CORE -> Google Scholar

Tested against 'Position based fluids' (Corpus ID 611962), which has
openAccessPdf=null in the S2 API but a freely downloadable preprint on
CORE (578097143.pdf, 2.6 MB, confirmed 200 OK).
Makes it easier to configure API keys without setting system environment
variables. A .env file in the project root (or any parent directory) is
loaded at server startup before any os.environ lookups.

Changes:
- Add python-dotenv>=1.0.0 to dependencies
- Load .env in server.py with a try/except so the server still works if
  python-dotenv is not installed (plain env vars remain supported)
- Add CORE_API_KEY to the documented env vars in the server docstring
- Add .env.example template covering all four supported keys:
    VIBESCHOLAR_DATA_DIR, S2_API_KEY, VIBESCHOLAR_EMAIL, CORE_API_KEY
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