Skip to content

docs(ai/imports): import pipeline architecture reference - #13004

Merged
mekarpeles merged 3 commits into
masterfrom
docs/ai/imports-update
Jun 23, 2026
Merged

docs(ai/imports): import pipeline architecture reference#13004
mekarpeles merged 3 commits into
masterfrom
docs/ai/imports-update

Conversation

@mekarpeles

@mekarpeles mekarpeles commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds docs/ai/imports/index.md β€” a system reference for AI agents and contributors working on the Open Library import pipeline.

This file was authored during the ITAN import pipeline work and captures the architecture knowledge needed to work in this area without re-reading all the source files from scratch.

What it covers

  • Architecture overview β€” four import paths: IA imports, MARC imports, batch/partner source imports, and the FastAPI preview endpoint
  • Key files table β€” every file that matters in the import domain with a one-line description
  • API endpoints β€” all import-related endpoints including the FastAPI GET/POST /import/preview.json (added in PR migrate import_preview_json to FastAPIΒ #12745, previously undocumented here)
  • Validation gate β€” explains the two-model CompleteBook / StrongIdentifierBook logic in import_validator.py, including the known gap for IA items with no publisher and no ISBN/LCCN (issue IA import fails due to missing publisherΒ #10756)
  • Common failure modes β€” not-differentiable, MARC load failures, validation errors

Related

@hornc

hornc commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This document does not mention the bulk MARC import pipeline, and local_id barcode metadata imports, which are the main source of usable records for archive.org's scanning metadata:

This was previously documented in these locations:

I know this PR was LLM generated too. I don't necessarily expect an on-point response, just making a note for the record.

@mekarpeles

Copy link
Copy Markdown
Member Author

Hi @hornc; these are both great points. And the point specifically of docs/ai/* are for AIs (so we can train code-owners / domain experts to help with reviews, etc).

They are by no means perfect yet, it will take many rounds of docs before we get there. I'll have Impa (the Import PIpeline agent) add marc + local_id to the docs and will do a rebase + resolve merge conflicts

Adds docs/ai/imports/index.md β€” a system reference for AI agents and
contributors working on the Open Library import pipeline.

Covers:
- Architecture overview (IA import, MARC, batch, partner sources)
- Key files with descriptions and links
- API endpoints including FastAPI /import/preview.json (PR #12745)
- Validation gate: CompleteBook / StrongIdentifierBook two-model logic
- Common failure modes including not-differentiable (issue #10756)
- Open issues and roadmap items
@mekarpeles
mekarpeles force-pushed the docs/ai/imports-update branch from dc7ba22 to 48885a7 Compare June 23, 2026 07:49
@mekarpeles

mekarpeles commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

These are a handful directional goals that we're trying to pursue:

  • We want to continue importing from MARC
  • We import from promise items
  • We want to stage amazon for import/enrichment since we fetch them anyway
  • We want to continue monthly BWB bulk imports (ideally we'd import those covers as well as part of that monthly process)
  • We want to build a registry of OPDS feeds and tail/follow these and import them (this registry pattern may be useful for many partners)
  • We want to streamline the approach for adding new micro-feeds (ITAN, cita press, etc) into Open Library
  • We want to support more Trusted Book Providers (including web books)
  • We want to enable anyone with an account (s3/logged-in) to submit a batch of records that then get staged for review
  • We also want to explore assistive technologies (e.g. AI) to safely, meaningfully, reliably enrich the content of high demand book pages to be more useful.
  • We want to improve openlibrary-client to help serve some of these functions, like submit bulk batch
  • We want import pipelines to work on dev instances and be e2e testable
  • We want our current import catalog system to work more reliably (author resolution, work resolution, etc) and when manage-imports.py results in a failure,
    we want to know exactly why (not just internal-error).
  • We want safety so bots don't overwhelm Open Library with direct requests to our /api endpoints (as much as possible goes through batch imports)

@mekarpeles

Copy link
Copy Markdown
Member Author

Thanks @hornc β€” both omissions were genuine blind spots. The wiki and docs.openlibrary.org links you referenced were the right pointers; I used them (plus reading importapi/code.py directly) to add the missing content.

This version now covers:

  • Bulk MARC import β€” the POST /api/import?bulk_marc=true&identifier=ocaid/file:offset:len flow, the ocaid/filename:offset:length locator format, get_from_archive_bulk(), and the next_record_offset/next_record_length response fields for sequential file walking
  • local_id β€” how /local_ids/{name} documents map barcode types to MARC subfields, the urn:prefix:id format written to edition["local_id"], and the side effect of force_import = True
  • MARC parsing stack β€” catalog/get_ia.py, marc/marc_binary.py, marc/marc_xml.py, marc/parse.py are now in the Key Files table
  • get_marc_record_from_ia() β€” the per-item MARC fetch ({ocaid}_meta.mrc β†’ {ocaid}_marc.xml fallback) is now described under the IA import section

The document is meant as an internal AI agent reference, so it tries to be accurate about how the code actually works rather than aspirational. If there is anything still inaccurate or missing β€” particularly around the local_id MARC subfield extraction logic or the BWB batch flow β€” I would welcome a correction.

Break the 460-line index.md into five focused files:
- index.md: architecture overview, key files, cross-links, open PRs
- api.md: endpoints, bulk MARC, local_id, batch import, IA import
- validation.md: validation gate, required fields, not-differentiable gap
- adding-sources.md: adapter pattern, identifier registration, PR review expectations
- debugging.md: known limitations, debug playbook

Roadmap content removed from contributor docs β€” lives in agent-land
(~/.cmux/impa/notes/import-roadmap.md, pm/workflows/import_workflow.md).
@mekarpeles
mekarpeles merged commit 2b52604 into master Jun 23, 2026
7 checks passed
@mekarpeles
mekarpeles deleted the docs/ai/imports-update branch June 23, 2026 08:13
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.

2 participants