diff --git a/codex/ingest.py b/codex/ingest.py index a6e7ff6..72d2deb 100644 --- a/codex/ingest.py +++ b/codex/ingest.py @@ -139,6 +139,8 @@ def ingest_paper( if suffix == ".tex": text = latex_to_text(Path(source_path).read_text()) + elif suffix == ".txt": + text = Path(source_path).read_text(encoding="utf-8", errors="replace") elif suffix == ".pdf": text = pdf_to_markdown(source_path) # Also extract GROBID refs @@ -176,7 +178,10 @@ def ingest_paper( # --------------------------------------------------------------- api_citations: list[Citation] if paper.openalex_id: - api_citations = openalex.fetch_citations(paper.openalex_id) + raw = openalex.fetch_citations(paper.openalex_id) + # OpenAlex returns citing_id=openalex_id, but papers.id uses the DOI. + # Rewrite citing_id to paper.id so the FK constraint is satisfied. + api_citations = [Citation(citing_id=paper.id, cited_id=c.cited_id, context=c.context) for c in raw] else: api_citations = semanticscholar.fetch_references(paper_id)