Skip to main content

CiteIndex

Ingest PDFs, web pages, audio, video, Office documents, and DjVu

Verify CSL JSON and trace quotations to a page, section, or timestamp

Use the same pipelines from the Python CLI or an agent through MCP

CiteIndex turns original sources into citation records and quotation evidence that research tools can reuse. It supports CJK OCR for scanned pages and records Merkle hashes for integrity checks. An agent in Codex, Claude Code, OpenCode, Pi, or OMP can call the MCP server to ingest or check a source.

PyPI Downloads

Quickstart

pip install citeindex
citeindex paper.pdf

Outputs land next to where you run it: corpus/<doc-id>/ (CSL JSON, Merkle manifest, ingestion log), library/<doc-id>.md, and logs/. See Install for OCR/media/browser extras and CLI for every flag.

What's new in 0.17.0

  • Local PaddleOCR backend and the ancient-cjk default: vertical columns, line geometry, no API key.
  • End-of-book colophon fallback for Chinese, Japanese, and Korean books (牌記 / 奥付 / 간기).
  • Missing-field recovery in the bundled citation-verification skill.
  • Local media ingestion is opt-in (--media); the media extra no longer pulls WhisperX.
  • URL author names keep surname particles and use the publisher citation line.

How it works

flowchart LR
    CLI["CLI"] --> Core["Shared ingestion pipelines"]
    MCP["MCP"] --> Core
    Core --> Record["CSL JSON and quotation locators"]
    Record --> Audit["Source and citation review"]
    Audit -->|Several quotation matches| Choose["User chooses the occurrence"]
    Choose -->|Selected locator| Audit
    Audit -->|Supported correction| Core
  1. Ingest the source. CiteIndex picks the extraction pipeline and saves the record with the source coordinates it can recover.
  2. Check a CSL field or quotation against the record. An agent can inspect the original and use its browser to resolve missing or disputed evidence.
  3. If a quotation occurs in several places, choose from the matches and verify the selected locator. If the evidence supports a correction, submit a repair proposal to regenerate the record.

For pipeline and storage details, see the architecture notes.

Reproduce the citation benchmark on a checkout (reviewed local gold manifest required — model output is never gold):

python benchmarks/citations/run.py manifest.jsonl predictions.jsonl

See benchmarks/citations/README.md.

Run the ancient-Chinese OCR golden page (fixture and provider setup in benchmarks/ocr/golden/README.md):

python benchmarks/ocr/golden/run.py --provider kandian

Install

pip install citeindex
# Add only the engines you use, for example:
pip install 'citeindex[ocr-mineru,layout]'

The default install handles digital PDFs and ordinary HTML URLs. For HTML URLs, Highwire Press, Dublin Core, OpenGraph, and Schema.org JSON-LD metadata is extracted deterministically from the page <head> without any external service. Scanned PDFs need ocr-mineru (MinerU's pipeline backend) or ocr-paddle with --ocr-engine glm-ocr. Cloud OCR backends (Kandian, Gujicool, Google, Azure, OpenAI, Ollama) are optional and selected with --ocr-engine; Google needs ocr-google. Copy .env.example to .env for provider credentials; .env is gitignored and loaded at import time. Local audio/video is opt-in: pass --media. The media extra installs only the probe and download tools (pymediainfo, yt-dlp); transcription with WhisperX needs the heavier media-asr, and the separate Wenbi environment needs only media-wenbi here. JavaScript-rendered pages need web-browser plus playwright install chromium, while --all-url-article needs crawl. The legacy OCR helpers need ocr-legacy. Enhanced PDF layout extraction uses layout; otherwise it falls back to the built-in heuristic. The optional MCP server needs mcp. Install several extras together as needed.

Docker

docker build -t citeindex .
docker run --rm -v "$PWD:/data" citeindex /data/paper.pdf

The image installs the base package (digital PDFs and HTML URLs) and writes corpus outputs under /data/corpus on the mounted directory. Add the extras you need to the pip install line in the Dockerfile for OCR or media.

CLI

# Ingest a PDF
citeindex paper.pdf

# Structured logs: one JSON object per line on stderr
citeindex paper.pdf --log-format json

# Ingest a scanned PDF with the default MinerU backend
citeindex scanned.pdf --ocr-engine mineru

# Opt in to local media, then choose Wenbi raw ASR with an explicit provider
citeindex lecture.mp4 --media --media-asr-backend wenbi --wenbi-asr-provider funasr

# Or keep Wenbi dependencies isolated in Wenbi's own environment
citeindex lecture.mp4 --media --media-asr-backend wenbi --wenbi-asr-provider funasr \
  --wenbi-python ../wenbi/.venv/bin/python

# Use the optional GLM-OCR backend via local Ollama
citeindex scanned.pdf --ocr-engine glm-ocr --ocr-model glm-ocr:latest

# Vertical ancient Chinese: top-to-bottom columns, right-to-left reading order
citeindex ancient.pdf --ocr-engine glm-ocr --text-direction vertical --vertical-lang ch

# Ingest a URL
citeindex https://example.com/article

# Crawl and ingest all articles from a site
citeindex https://example.com/articles --all-url-article --crawl-depth 2

# Crawl and re-ingest only changed pages
citeindex https://example.com/articles --update-url-article

# Options
citeindex paper.pdf --llm ollama/qwen3 --type thesis --is-primary
citeindex paper.pdf --text-direction vertical --vertical-lang ch
citeindex scanned.pdf --ocr-engine mineru --lang auto --page-range "1-10"
citeindex paper.pdf --no-layout  # disable column/footnote detection
citeindex paper.pdf --force-ocr  # override PDF classification
citeindex -q paper.pdf           # disable default debug logging

# Evidence-backed citation verification (Crossref exact DOI lookup)
citeindex paper.pdf --verify-citations --registry-contact-email you@example.org

# Ask a stronger provider-qualified model only to resolve remaining conflicts
citeindex paper.pdf --verify-citations --citation-verifier-model openai/gpt-5

# Explicit alternative engine for digital PDFs; requires a running GROBID service
citeindex paper.pdf --citation-engine grobid

Verification is opt-in. Crossref receives only an exact DOI, never document text. A model correction is accepted only when it supplies a matching source quote and stable locator; unavailable models leave the record unchanged for review. Use --no-crossref to disable registry lookup or --offline-verification to disable registry and verifier-model requests.

An independent harness audit is available only through an explicit Codex, Claude Code, OpenCode, or Pi skill/command; running citeindex directly does not auto-trigger one.

MCP server (optional)

Run CiteIndex as a local MCP server so agent harnesses call tools directly instead of shelling out:

pip install 'citeindex[mcp]'
citeindex-mcp --corpus-root corpus                      # stdio
citeindex-mcp --http 127.0.0.1:8765 --corpus-root corpus  # shared Streamable HTTP
# or without a global install:
uvx --from 'citeindex[mcp]' citeindex-mcp --corpus-root corpus

ingest_source uses the same pipelines as the CLI for PDFs, Office, DjVu, media, and public URLs. Enable writes with --allow-write or CITEINDEX_MCP_ALLOW_WRITE=1. Enable local inputs with repeatable --input-root /path/to/sources options. Poll ingestion_status with the returned job ID. Job handles are retained in the server process. The older ingest_url tool keeps its deterministic HTML defaults and also returns a job ID if ingestion is still running.

For citation-only ingestion, call ingest_source with tool arguments like {"input_ref": "/path/to/sources/paper.pdf", "output_mode": "csl_only"}. Both ingestion tools accept full (default), csl_evidence, and csl_only. Read the citation from the completed job’s csl field. Citation-only mode still saves the run summary, and URL or media records may retain source snapshots. Re-ingesting an existing full record in this mode can remove its full-output artifacts.

Use citation_verify with the exact record ID to check CSL fields or a supplied quotation, with an optional locator to narrow the check. It reports agreement with stored extraction and, when available, checks the original bytes against the recorded digest. The reverify-citation prompt guides the agent host through inspecting the original and using its web or browser tools to resolve missing evidence. Record the supporting quote, locator and URL, and confirm the edition. Registry corroboration has its own status. Apply requested corrections through a repair proposal and the standard ingestion path.

Full and CSL-with-evidence outputs persist quotation_locators.json for extracted PDF, HTML, and media spans. A PDF locator carries the physical page and, when available, the printed label and its provenance. The MCP returns context and exact coordinates when several occurrences match. The host asks the user to choose and submits the selected locator for verification.

Use Shutong for corpus discovery and research questions. Pass the CiteIndex record ID to library_get or citation_verify for evidence. The server also exposes CSL, manifests, verification reports, and the citation verification skill as resources. library_list and library_search remain available for existing clients.

Client registration snippets for OpenCode, Codex, Pi, and OMP: docs/2026-11-17-citeindex-mcp-plan.html.

Benchmarking

The pilot benchmark measures extraction and evidence verification only; it does not evaluate document question answering. Keep reviewed source manifests, predictions, reports, and copied source files local because they may contain private or licensed material.

# First create candidate rows; this does not invent gold labels.
python benchmarks/citations/prepare_manifest.py \
  /home/ajiap/Downloads/Orthodox-China \
  benchmarks/citations/manifest.jsonl --limit 40

# Run all manifest rows serially; every attempted source becomes a prediction row.
python benchmarks/citations/ingest.py benchmarks/citations/manifest.jsonl \
  benchmarks/citations/predictions/dspy.jsonl

# Score host metadata against the human-reviewed labels.
python benchmarks/citations/run.py benchmarks/citations/manifest.jsonl \
  benchmarks/citations/predictions/dspy.jsonl

The 40-source pilot composition, annotation contract, modality-specific controls, and reporting gates are documented in docs/plans/2026-09-14-multimodal-citation-benchmark.md. Validate independent reviewers before scoring with python benchmarks/citations/validate_manifest.py manifest.jsonl; create a reproducible split with python benchmarks/citations/split.py manifest.jsonl split-manifest.jsonl; compare saved reports with python benchmarks/citations/compare.py baseline.json candidate.json. The reviewed 40-source pilot has 36 citations with usable gold metadata (16 digital PDFs, 12 scanned PDFs, 8 URLs). The original 2026-09-24 cloud run scored 6/36 exact records (16.7%) under the earlier scorer, with 3 scanned-PDF timeouts and 4 media failures. A later sampled run completed all 36 PDF/URL sources. Under scorer host-v4-run-accessed-equivalence, which uses the actual retrieval date and rejects redirect-only article snapshots, it scores 3/36 strict records (8.3%); two GCDFL snapshots are redirect-only. These are development results, not a production accuracy estimate.

The repaired 40-source cloud candidate completed all 28 PDFs, 8 URLs and 4 media files. On the 36 reviewed PDF/URL citations, strict record accuracy is 4/36 (11.1%) and separately defined bibliographic equivalence is 9/36 (25.0%). By modality, equivalent record accuracy is 2/16 digital PDFs, 1/12 scanned PDFs and 6/8 URLs. The candidate follows both GCDFL redirects to final articles, so its URL snapshots differ from the old baseline; do not treat the aggregate as a same-snapshot causal comparison. The four media files returned empty transcripts and explicit incomplete citation status without guessed metadata; they remain unscored, as requested. The 90% production target is not met for this multimodal pilot. Predictions and source review are local ignored artifacts under benchmarks/citations/predictions/ and benchmarks/citations/reports/.

Digital PDF two-category core-requirement benchmark (2026-09-26)

A focused 16-source digital-PDF slice was re-benchmarked against the re-reviewed digital-16-2026-09-26-gold-v2 manifest under the two-category citation model (article = cited with page numbers; book = cited without) and a category-aware core-requirement metric with equivalence-normalized matching:

  • book core: type, author/editor/translator, title, publisher, issued
  • article core: type, author, title, container/journal, number, page range
  • fields not printed in the supplied PDF (for example a volume number absent from an article offprint) are marked outside_scope and are not required

Result: 15/16 core records (93.75%), title F1 0.875, type F1 1.0. The single miss is a work whose author and editor are printed only in Latinized form (GREGORII NYSSENI, WERNERUS JAEGER). Trajectory under this metric: 11/16 → 13/16 → 12/16 (one intermediate regression from over-constrained prompt rules) → 15/16, after moving deterministic normalization (OCR numeral repair, CIP author/translator role parsing) out of the prompt and into code.

Scope and caveats: this covers 16 digital PDFs only; the scanned/URL/media slices above are not measured by this metric, so the multimodal pilot statement stands. With n=16 single-run variance is material, and the two confirming runs were replays of the same cached model responses, not independent samples. Reviewed labels, predictions, and reports stay local under benchmarks/citations/predictions/.

Scanned PDF two-category core-requirement benchmark (2026-09-26)

A focused 12-source scanned-PDF slice was re-benchmarked against the re-reviewed scanned-12-2026-09-26-gold-v2 manifest under the same two-category citation model and core-requirement metric as the digital slice. Scanned sources run the full ingestion pipeline; only the page sampler is narrowed (1-10, -3) and page-index/layout are disabled.

Result: 12/12 core records (100%) — every scanned core field recovered. Against the pre-review frozen labels the same run scores 8/12, and every per-source flip from the baseline is forward (no regressions). Four sources needed label re-review where the frozen labels asked for something the scan cannot support (an OCR-omitted title; name forms printed only in catalog or CIP shape); the diff is in docs/2026-09-26-scanned-gold-v2-diff-for-signoff.md.

The work moved scanned title/credit recovery out of prompts and into gated deterministic seeds — heading-based title/subtitle, imprint publisher, and copyright-year branch priority, plus translator/editor credits and Roman-numeral imprint years — each verified against an offline OCR probe before any model run. One deliberately non-obvious case: a publisher that is garbled on the title page is still printable cleanly on a sampled tail page, so the imprint seed reads whichever copy is intact rather than trusting the first occurrence.

Python API

Optional translation plugin

Install Fanyi into the same environment to add on-demand translation of an already ingested PDF corpus. Fanyi may be a private local checkout:

python -m pip install -e /path/to/citeindex -e /path/to/fanyi
citeindex-plugin list

Save translation settings as fanyi-options.json:

{"target_lang": "ZH", "engine": "dspy", "format": "mdx"}
citeindex-plugin run fanyi corpus/Author_Title_hash \
  --options fanyi-options.json --output translations/Author_Title_hash/zh
# Optional: --timeout 7200 for a long document.

The plugin reads the completed corpus without re-ingesting or requiring the original PDF. It writes bilingual MDX, aligned JSON, copied image assets, and plugin_result.json provenance into a separate output directory. The destination must be absent or empty. Partial translations go into <output>.partial and return a nonzero exit status; failed runs do not replace earlier output. Translations are derived text, not original-source quotation evidence.

Plugins register a callable in the citeindex.plugins.v1 Python entry-point group. citeindex.plugins.run_plugin(name, document_path, output_dir=..., options={...}, timeout=3600) is the equivalent Python API. The selected callable receives a version-1 dictionary with document_path, output_dir, and options, and returns protocol_version, status, relative artifacts paths, QA details, errors/warnings, and optional sanitized manifest_options. Only explicitly requested plugins execute, in a child process using the same Python environment. Installed plugins are trusted code; this process boundary is not a sandbox.

python -m pip uninstall fanyi
citeindex-plugin list

Removing Fanyi detaches translation while preserving CiteIndex and existing corpora/output. CiteIndex's base installation has no Fanyi dependency. See the implementation plan for the contract and supported workflow.

Ingestion

from citeindex import ingest, IngestionConfig, IngestionFailure, PipelineResult

# Simple
result = ingest("paper.pdf")
print(result["status"])  # "ok"

# With config
config = IngestionConfig(
    llm_model="ollama/qwen3",
    text_direction="vertical",
    is_primary=True,
)
result = ingest("paper.pdf", corpus_root="my_corpus", config=config)

Code Structure

  • citeindex/cli.py maps CLI options into IngestionConfig.
  • citeindex/ingestion/master.py detects input types, routes pipelines, verifies metadata, and persists results.
  • citeindex/ingestion/pipelines/ contains the digital PDF, scanned PDF, URL, media, GROBID, PageIndex, and metadata-extraction implementations.
  • citeindex/ingestion/storage.py and markdown_export.py write corpus artifacts and companion library Markdown.
  • citeindex/mcp/ serves citation verification, shared ingestion, and the bundled host audit skill.
  • .agents/, .claude/, .codex/, .opencode/, and .pi/ expose the optional citation-evidence audit to supported agent harnesses.

Ingestion Pipelines

CiteIndex automatically detects the input type and routes to the correct pipeline:

PDF routing is based on usable existing text, not whether the file was born digital. Searchable scans with readable text layers use the digital pipeline, including invisible OCR text over full-page images. At least 90% of nonblank pages must have usable text; up to 10% may be image-only or sparse pages (such as illustrations or title pages). For example, 91 text pages and 9 image-only pages use the digital pipeline. Those image-only pages are kept in the document but are not OCR'd; text contained only in their images is not extracted. Completely blank pages do not count against the threshold.

Clearly garbled text still triggers OCR. These local quality checks cannot detect every transcription error; use --force-ocr when the existing text is wrong, or --force-digital to explicitly reuse it. Digital layout extraction also disables automatic OCR in PyMuPDF4LLM.

Digital PDF

PDF → PyMuPDF4LLM layout/text (PyMuPDF fallback) + image extraction
    → page-paragraph document structure → DSPy citation extraction
    → PageIndex tree (default) → optional explicit GROBID engine
    → Merkle tree → section_tree + heading injection
    → store document.json and library Markdown
  • PyMuPDF4LLM performs layout-aware extraction when enabled; raw PyMuPDF is the fallback
  • DSPy is the default citation metadata engine for digital PDFs
  • GROBID is an explicitly selected alternative requiring a separate service
  • Builds page-based document structure and augments it with PageIndex section headings
  • PageIndex builds LLM-driven section hierarchy, persists it to corpus, and feeds library markdown headings

Scanned PDF

PDF → scanned backend selector
    → MinerU (default), local PaddleOCR for ancient CJK, GLM-OCR + PaddleOCR,
      or a cloud OCR adapter
    → normalized content_list / markdown / extracted figures
    → reading order (horizontal, auto, or vertical right-to-left)
    → pattern extraction with DSPy-priority metadata
    → document structure → Merkle tree → PageIndex tree (default)
    → store only CiteIndex-native artifacts to corpus/
  • MinerU is the default scanned backend for modern printed pages
  • PaddleOCR is the local default for the ancient-cjk profile: vertical columns, line polygons, no API key
  • GLM-OCR is an optional backend that runs through local or cloud Ollama using the native /api/generate endpoint
  • PP-DocLayout_plus-L (a PaddleOCR layout model) supplies external region proposals for GLM-OCR from the start
  • Kandian, Gujicool, Google Document AI, Azure Document Intelligence, and OpenAI are opt-in cloud adapters
  • Scanned PDFs do not use GROBID; metadata is extracted from structured backend output via DSPy-backed extraction
  • DSPy is allowed to overwrite pattern-extracted metadata fields for scanned documents
  • PageIndex runs by default for scanned PDFs, just like digital PDFs
  • Only extracted figures / illustrations are exported into the corpus images/ folder; raw backend artifacts are not preserved
  • --text-direction vertical gives top-to-bottom columns and right-to-left reading order for ancient CJK pages

Scanned PDF Backend Selection

Scanned PDFs support a profile for the common path:

# Standard profile: MinerU, horizontal reading order
citeindex scanned.pdf --ocr-profile standard

# Ancient Chinese profile: local PaddleOCR, vertical reading order
citeindex ancient.pdf --ocr-profile ancient-cjk

ancient-cjk defaults to:

  • ocr_engine=paddleocr
  • ocr_model= (PaddleOCR's bundled recognition model)
  • text_direction=vertical

It runs locally on CPU, needs no API key, and returns line polygons, so the vertical layout pass can group columns right-to-left, mark short top/bottom blocks as header/footer, and mark small or interlinear blocks as notes. Install the optional dependency:

pip install 'citeindex[ocr-paddle]'

Models download once to ~/.paddlex (about 220 MB) and are reused offline. Each page is rendered to a 2400 px long side before recognition, which is the resolution the dense-column benchmark used. Expect roughly a minute per dense page on a 16-thread CPU.

For a text-only cloud path without local models, --ocr-engine gujicool-chat remains available.

Explicit flags override the profile. For example:

citeindex ancient.pdf --ocr-profile ancient-cjk \
  --ocr-engine gujicool-chat --ocr-model extract_text --ocr-punctuate

All scanned backends feed the same content_list, DSPy citation extraction, PageIndex, Merkle, and corpus pipeline. Cloud backends upload page images; they are opt-in and never the default.

PaddleOCR (local, default for ancient CJK)

pip install 'citeindex[ocr-paddle]'
citeindex ancient.pdf --ocr-profile ancient-cjk
# equivalent explicit form
citeindex ancient.pdf --ocr-engine paddleocr --text-direction vertical
  • Runs PaddleOCR in-process on CPU. PADDLEOCR_DEVICE=gpu:0 uses a GPU.
  • PADDLEOCR_DET_MODEL overrides the detection model (default PP-OCRv5_server_det). --ocr-model selects the recognition model.
  • Returns line polygons, so --text-direction vertical can order columns right-to-left and feed header/footer/note classification.
  • OneDNN is disabled by default because paddle 3.3.1 crashes with PIR plus oneDNN on CPU. Set PADDLE_PDX_ENABLE_MKLDNN_BYDEFAULT=1 only on a paddle build that is known to work.
  • The first run downloads the detection and recognition models; later runs are offline.

MinerU (default, local)

pip install 'citeindex[ocr-mineru]'
citeindex scanned.pdf --ocr-engine mineru
  • Runs MinerU as a local subprocess. CPU works; a GPU speeds it up.
  • --mineru-backend selects the MinerU backend (pipeline by default).
  • --mineru-chunk-pages and --mineru-timeout control large PDFs.

GLM-OCR (local or Ollama Cloud)

pip install 'citeindex[ocr-paddle]'
ollama pull glm-ocr:latest
citeindex scanned.pdf --ocr-engine glm-ocr --ocr-model glm-ocr:latest
  • Uses PaddleOCR PP-DocLayout_plus-L for region boxes and GLM-OCR for each crop.
  • For Ollama Cloud, set the host and key:
export OLLAMA_API_KEY=your-key
citeindex scanned.pdf --ocr-engine glm-ocr \
  --ocr-model deepseek-v4.1-flash:1017 \
  --ollama-host https://ollama.com
  • This is crop recognition, not a full-page parser. It still needs the PaddleOCR layout dependency.

Kandian / 看典古籍 (ancient Chinese)

export KANDIAN_TOKEN=your-token
export KANDIAN_EMAIL=your-account
citeindex ancient.pdf --ocr-engine kandian --text-direction vertical
  • Specialized for vertical ancient Chinese, variant characters, interlinear notes, and per-character confidence.
  • Returns line positions, per-character confidence, and layout classes.
  • Use --text-direction vertical for top-to-bottom columns and right-to-left reading order.
  • API quota: 500 calls/day for a normal account; shared monthly quota 2,000 calls, with OCR default 800. Extra calls are ¥0.015 each. Confirm the current split in the Kandian console.

Gujicool / 古籍酷 (ancient Chinese)

export GUJICOOL_ACCESS_TOKEN=your-token
citeindex ancient.pdf --ocr-engine gujicool --text-direction vertical
  • Specialized vertical ancient-Chinese endpoint with per-character coordinates and confidence.
  • The default endpoint is https://ap2.jzd.cool:9043/ocr_pro. GUJICOOL_OCR_URL overrides it if your account uses a different host.
  • Use --text-direction vertical for right-to-left columns.
  • This OCR API needs an access_token from /ocr_login. A Chat API key will return HTTP 422 Signature verification failed.
  • Set GUJICOOL_APIID and GUJICOOL_PASSWORD to let CiteIndex log in automatically, or set GUJICOOL_OCR_ACCESS_TOKEN / GUJICOOL_ACCESS_TOKEN directly. GUJICOOL_REFRESH_TOKEN is used for retry after expiry.

Gujicool Chat (OpenAI-compatible)

export GUJICOOL_CHAT_BASE_URL=https://api.jzd.cool:9011
export GUJICOOL_CHAT_API_KEY=your-chat-key
citeindex ancient.pdf --ocr-engine gujicool-chat --text-direction vertical

# Readable output with punctuation
citeindex ancient.pdf --ocr-engine gujicool-chat --ocr-model extract_text --text-direction vertical
citeindex ancient.pdf --ocr-engine gujicool-chat --ocr-punctuate --text-direction vertical
  • Uses the Chat Base URL and API key from the Gujicool account page.
  • Model defaults to ocr; override with GUJICOOL_CHAT_MODEL or --ocr-model.
  • --ocr-model extract_text uses PaddleOCR-VL 1.6 and returns punctuation and line breaks.
  • --ocr-punctuate adds a separate Gujicool Chat punctuate pass. The raw OCR text and locators stay unchanged; readable text is stored in document.json metadata as punctuated_text.
  • Returns page-level text, not character coordinates. Use the OCR API when block geometry is required.
  • Do not send a Chat API key to /ocr_pro.

Google Document AI

pip install 'citeindex[ocr-google]'
export GOOGLE_CLOUD_PROJECT=your-project
export GOOGLE_CLOUD_LOCATION=us
export GOOGLE_DOCUMENTAI_PROCESSOR_ID=your-processor
citeindex scanned.pdf --ocr-engine google-docai
  • Create an Enterprise Document OCR processor in Google Cloud first.
  • Uses Application Default Credentials or GOOGLE_APPLICATION_CREDENTIALS.
  • Returns paragraphs with positions and confidence. Good for modern Chinese and English; verify rare or variant characters on your own pages.
  • The adapter currently maps paragraph text and positions; table structure is not yet wired into CiteIndex.

Azure Document Intelligence

export AZURE_DOCINT_ENDPOINT=https://your-resource.cognitiveservices.azure.com
export AZURE_DOCINT_KEY=your-key
citeindex scanned.pdf --ocr-engine azure-docint
  • Uses prebuilt-layout by default. Set AZURE_DOCINT_MODEL=prebuilt-read for plain text.
  • AZURE_DOCINT_API_VERSION overrides the REST API version.
  • Read is cheaper; Layout returns tables and document structure at a higher price. The adapter currently maps line-level text and positions; table structure is not yet wired into CiteIndex.

OpenAI vision

export OPENAI_API_KEY=your-key
citeindex scanned.pdf --ocr-engine openai --ocr-model gpt-4.1-mini
  • Text-first fallback. Bounding boxes are requested from the model but are best effort.
  • Set OPENAI_OCR_MODEL or --ocr-model; the default is gpt-4.1-mini.
  • OPENAI_BASE_URL supports compatible gateways.
  • Use Kandian, Google, or Azure when citation locators need reliable block geometry.

Ollama full-page vision

export OLLAMA_API_KEY=your-key
citeindex scanned.pdf --ocr-engine ollama \
  --ocr-model deepseek-v4.1-flash:1017 \
  --ollama-host https://ollama.com

# Local Ollama vision model; OLLAMA_OCR_MODEL overrides --ocr-model
OLLAMA_OCR_MODEL=inkling-2-small:cloud \
  citeindex ancient.pdf --ocr-engine ollama --text-direction vertical
  • Sends the whole page to one vision model and returns page-level text.
  • No block bounding boxes. Use glm-ocr or a cloud parser when block geometry matters.
  • OLLAMA_HOST overrides --ollama-host; OLLAMA_OCR_MODEL overrides --ocr-model.

Common options

  • --text-direction horizontal|auto|vertical|vertical-rl controls scanned reading order. vertical and vertical-rl mean top-to-bottom columns, right-to-left.
  • --pages '1-6' limits extraction and cloud cost. A scoped record is anchored to the file digest plus the page window.
  • --ocr-max-cloud-pages N refuses cloud OCR when the selected page count exceeds N.
  • --ocr-cache / --no-ocr-cache caches cloud page results by source digest, page, provider, model, and reading order. The default cache root is ~/.cache/citeindex/ocr; set CITEINDEX_OCR_CACHE_DIR to move it. The cache contains OCR text; disable it for sensitive sources.
  • Cloud credentials come from environment variables, not CLI flags, so they do not appear in shell history.

URL Article

URL → Playwright/requests (fetch) → HTML head metadata (deterministic)
    → trafilatura/readability (content)
    → Zotero / in-page citation guidance (candidates) → web-specific DSPy + source evidence
    → _field_evidence binding → snapshot SHA-256
    → section-hierarchical paragraphs → PageIndex tree (optional)
    → hashes → Merkle tree → store to corpus/
  • Playwright renders JavaScript-heavy pages (fallback to requests)
  • Deterministic HTML head parsing runs before any LLM call and extracts structured metadata from:
    • Highwire Press / Google Scholar tags (citation_title, citation_doi, citation_author multi-value, citation_journal_title, citation_volume, citation_issue, citation_firstpage/lastpage, citation_publisher, citation_issn, citation_isbn)
    • Dublin Core (dc.title, dc.creator, dc.date, dc.publisher, dc.identifier)
    • OpenGraph (og:title, og:site_name, article:published_time, article:author)
    • Prism (prism.doi, prism.publicationname, prism.publicationdate)
    • Schema.org JSON-LD inline scripts (ScholarlyArticle, Article, NewsArticle, BlogPosting, Book, Chapter)
  • trafilatura extracts clean markdown with heading structure (fallback to readability-lxml); trafilatura is an optional dependency — the base pipeline works without it
  • Zotero extracts citation metadata via translation-server (title, authors, date, DOI)
  • Discovers in-page citation guidance: 若要引用 / 引用格式 / Cite this / Zitierweise / Pour citer
  • Web-specific DSPy uses original HTML text/metadata, preserves bibliographic subtype and date precision, and requires field quotations.
  • Extracted HTML-head metadata fields are automatically bound to source_blocks as _field_evidence with block ID, quote, and locator; source_snapshot_digest (SHA-256 of the fetched HTML) is stored in csl.json extra data alongside source_snapshot_path.
  • Regex/provider candidates remain unverified without evidence; access and revision dates are not publication dates.
  • Supports batch crawling with --all-url-article and --update-url-article

Media

Recognized media URL/local file → yt-dlp or local copy → ffmpeg (audio) → WhisperX (transcription)
        → pyannote (diarization, optional) → media-specific DSPy + source evidence → CSL JSON
        → chunking → hashes → Merkle tree → store to corpus/
  • yt-dlp downloads from YouTube, Vimeo, podcasts, etc.
  • Local files are opt-in: pass --media (or media_enabled=True). Remote media URLs still route automatically.
  • WhisperX transcribes with word-level timestamps
  • pyannote speaker diarization (optional)
  • Local-file citations are often incomplete. A container tag can supply a title, and performer can supply a contributor; without tags the title falls back to the filename and is marked provisional-filename, while author stays missing, so _citation_status remains incomplete. A recording carries no title page or publisher metadata; prefer a catalogue page or PDF record when one exists.
  • Preserves speaker/interviewee, interviewer, host, director and producer roles; uploader is not automatically author, nor platform publisher.
  • Recording duration (dimensions) is separate from quotation timestamps. Failed transcription leaves an empty transcript, not invented quotation text.
  • Each web/media extraction uses one bounded DSPy call (12,000 source-text characters); unsupported metadata stays missing or unverified. No live accuracy claim follows from this contract.
  • Supports audio (.mp3, .wav, .m4a) and video (.mp4, .mkv, .webm)
  • Remote media routing recognizes YouTube, Vimeo, podcast, SoundCloud, and youtu.be hosts; other URLs use the article pipeline

Office & DJVU

Office documents (.docx, .doc, .rtf, .odt, .pptx, .ppt, .odp) are converted to PDF via LibreOffice, and DJVU (.djvu) via ddjvu, then routed to the digital or scanned PDF pipeline. Default DJVU conversion is limited to the first 10 pages.

Citation Enrichment Cascade

For digital PDF inputs, CiteIndex uses DSPy citation extraction by default. A separately installed GROBID service is available only when explicitly selected with --citation-engine grobid; it is never an automatic fallback.

Extraction targets the ingested source's own citation metadata—not works cited inside it. DSPy uses original source blocks and validates quote spans; this does not by itself prove correct work/edition attribution. PDF metadata remains a last-resort, unverified identity hint.

Scanned PDFs do not use GROBID. Their structured OCR output is parsed with document-specific patterns, then DSPy values take priority when available.

With --verify-citations, the finalized draft follows this additional evidence-first stage before CSL IDs, hashes, filenames, and Markdown are written:

candidate CSL → DOI extraction → exact Crossref lookup
              → source quote + page/paragraph or URL snapshot evidence
              → deterministic reconciliation → optional conflict model
              → standardized CSL + verification report

Registry-only values are never applied automatically. They must also appear in the original source evidence; otherwise CiteIndex records needs_review.

Configuration Reference

Option CLI Flag Default Description
llm_model --llm ollama/deepseek-v4.1-flash:cloud LLM model (ollama/name or gemini/name)
ocr_engine --ocr-engine mineru Scanned PDF OCR backend: mineru, glm-ocr, kandian, gujicool, gujicool-chat, google-docai, azure-docint, openai, or ollama
ocr_profile --ocr-profile standard standard or ancient-cjk. The ancient profile defaults to local PaddleOCR and vertical reading order
ocr_model --ocr-model glm-ocr:latest Model name for model-backed OCR engines such as GLM-OCR or OpenAI
ollama_host --ollama-host http://localhost:11434 Ollama base URL for GLM-OCR; https://ollama.com with OLLAMA_API_KEY selects Ollama Cloud
ocr_max_cloud_pages --ocr-max-cloud-pages unlimited Refuse cloud OCR when the selected page count exceeds this value
ocr_cache --ocr-cache / --no-ocr-cache enabled Cache cloud page results; set CITEINDEX_OCR_CACHE_DIR to move the cache
ocr_punctuate --ocr-punctuate disabled Add a Gujicool Chat punctuation pass; raw OCR evidence stays unchanged
mineru_backend --mineru-backend pipeline Backend value forwarded to the MinerU CLI
mineru_timeout --mineru-timeout 3600 MinerU subprocess timeout in seconds, up to 3600
mineru_chunk_pages --mineru-chunk-pages auto Split large PDFs into adaptive MinerU chunks; use a page count to override or 0 to disable
text_direction --text-direction, -td horizontal Reading order for scanned PDFs: horizontal, auto, vertical, or vertical-rl (top-to-bottom, right-to-left)
vertical_lang --vertical-lang ch CJK language: ch (Chinese) or japan
lang --lang, -l auto OCR language (auto-detect or Tesseract code)
page_range --page-range, --citation-pages, -p 1-7 DSPy citation search window: 1-based physical PDF pages; -3 means the last three pages. When the window starts at page 1, the locator also reads the last three pages for end-of-book CJK colophons (奥付/牌記/판권). Marker-scan hits outside the window are still considered. Does not limit full-document ingestion or the separately selected GROBID engine.
doc_type_override --type, -t auto book, thesis, journal, or bookchapter
use_layout_analysis --no-layout True Disable column/footnote detection
is_primary --is-primary False Line-level granularity (vs paragraph-level)
use_pageindex --no-pageindex True PageIndex hierarchy is enabled by default; pass --no-pageindex to disable it
use_llm_metadata (API/MCP only) True Disable DSPy web metadata extraction for deterministic offline runs; MCP ingest_url sets False by default
pageindex_model --pageindex-model ollama/deepseek-v4.1-flash:cloud LLM for PageIndex tree building
force_pdf_kind --force-ocr, --force-digital auto Override automatic PDF classification
verify_citations --verify-citations False Enable evidence-backed metadata verification
citation_verifier_model --citation-verifier-model none Provider-qualified model used only for unresolved conflicts
crossref_enabled --no-crossref True Disable exact DOI Crossref lookup
offline_verification --offline-verification False Block Crossref and verifier-model requests (not normal ingestion fetching)
registry_contact_email --registry-contact-email none Optional polite Crossref contact email; not persisted
citation_style (API only) chicago-author-date CSL citation style for output
corpus_root --corpus-root corpus Output directory for ingested artifacts
schema_version --schema-version 1.0.0 Output schema version tag
(CLI only) --crawl-depth 2 Max BFS crawl depth for --all-url-article
(CLI only) --crawl-max-pages 100 Max pages for --all-url-article
(CLI only) --verbose, -v on Enable verbose/debug logging
(CLI only) --quiet, -q off Disable verbose/debug logging

Output

Each ingestion produces a content-addressed corpus folder (for example, corpus/Author_2024_Title_a1b2c3d4e5f6/) and a companion library Markdown file.

Corpus artifacts (corpus/Author_2024_Title_<12-char-hash>/)

File Description
csl.json Citation metadata (CSL-JSON with CiteIndex fields: content_hash, merkle_root, source_type, ingestion_timestamp)
csl-export.json CSL item array for processors; supported fields at top level, internal/unsupported data under custom, subtitle composed into title
source_blocks.json Web/media evidence blocks with source coordinates
web_metadata.json, retrieval_metadata.json Provider candidates and observed retrieval metadata, when applicable
quotation_locators.json Extracted PDF, HTML, and media quotation spans with the final citation ID and source coordinates
document.json Structured document tree — pages, paragraphs, and section_tree for URL articles and PageIndex-augmented PDFs
pageindex_tree.json Persisted CiteIndex/PageIndex hierarchy with page ranges and summaries when PageIndex runs
merkle.json SHA-256 Merkle tree for integrity verification
transcript.json Timestamped transcript with speaker segments (media only)
media_metadata.json Source media metadata (media only)
ingestion_output.json Full ingestion result with all pipeline outputs
citation_verification.json Evidence, Crossref provenance/digest, accepted corrections, and needs_review items (when verification is enabled)
source.html Fetched HTML snapshot used as URL evidence (URL articles only)
source.media Retained downloaded media asset for remote media, when available
images/ Extracted figures and illustrations when available

Library markdown (library/Author_2024_Title_<12-char-hash>.md)

Human-readable markdown with YAML front-matter, inline citation, page/section/timestamp headers with CSL-level detail, full extracted text, and footnotes. When PageIndex is available, digital PDFs emit section headings into the markdown instead of only flat page labels. Written to library/ (sibling of corpus/).

Agent-harness final audit

Codex, OpenCode, Claude Code, and Pi can load the shared citation-verification skill after ingestion. The audit reads the original source and citation_verification.json, then returns quotation-backed repair recommendations. It never edits persisted csl.json directly.

The CLI itself always performs the core verification when --verify-citations is supplied. The additional agent audit runs only through an explicit harness workflow (for example OpenCode /ingest-verified); a raw citeindex subprocess cannot detect or launch an agent harness.

Online enrichment (opt-in)

citeindex paper.pdf --online-enrich
citeindex paper.pdf --online-enrich --online-enrich-ai-fallback --online-enrich-ai-provider openai

Digital and scanned PDFs share this order: source extraction, optional quotation-backed repair, registry enrichment, then final CSL identifiers, artifact copies and Chicago Markdown rendering. Accepted Crossref/DataCite DOI records (T1) and OpenLibrary ISBN editions (T2) can automatically overwrite existing fields, including source repairs. The audit sidecar online_enrichment.json retains values, identity checks and provenance. Ambiguous matches abstain. Converted non-PDF inputs are outside this first release.

AI discovery requires --online-enrich-ai-fallback and an explicit provider: claude (ANTHROPIC_API_KEY), gemini (GEMINI_API_KEY), or openai (OPENAI_API_KEY). Each uses its native online search tool; search execution and cited identifier evidence are required. The discovered DOI/ISBN must independently resolve in a registry before T4 can fill missing fields. AI cannot overwrite fields. Supported model defaults and allowlisted source domains can be selected with --online-enrich-ai-model and --online-enrich-ai-domains.

Requests share a default 20-second budget, at most 12 attempts, five seconds per request, and a 2 MiB response limit. Registry caching lives in corpus/.registry-cache. --offline-verification blocks verification and enrichment network requests; --no-online-enrich disables automatic discovery. A supplied --enrich-proposal still requires fresh registry validation and is rejected in offline mode. With --online-enrich, validated proposals run first, then discovery considers remaining missing fields. Source repair proposals remain source-only.

Enrichment stays disabled by default until independent held-out release gates pass. See the implementation plan and benchmark instructions. Live provider checks are separate from fixture tests and require CITEINDEX_AI_LIVE_SMOKE=1 plus credentials.

Ingestion log (corpus/ingestion_log.jsonl)

Appended on every ingestion with input_ref, resource_type, csl_id, merkle_root, and ingestion_timestamp.

URL content hashes (corpus/_url_content_hashes.json)

Persisted URL → content-hash mapping used by --update-url-article for change detection.

Return Value

The ingest() function returns a dict:

{
    "schema_version": "1.0.0",
    "status": "ok",                    # "ok" or "blocked"
    "document_path": "corpus/Author_2024_Title",
    "standardized_csl_json": { ... },  # Full CSL-JSON with ci_ extensions
    "sub_pipeline_outputs": { ... },   # Raw pipeline results
    "ingestion_log_entry": { ... },     # Log entry with merkle_root
    "library_md_path": "library/Author_2024_Title.md",
}

# On failure:
{
    "status": "blocked",
    "source_id": "unknown",
    "stage": "detect_resource_type",
    "error_code": "unsupported_input",
    "error_message": "Unsupported input: ...",
    "next_action": "Provide PDF, URL, or media file",
}

Batch URL Ingestion Return

The ingest_all_urls() method (triggered by --all-url-article / --update-url-article) returns:

{
    "status": "ok",
    "root_url": "https://example.com/articles",
    "discovered": 25,      # total article URLs found
    "ingested": 20,        # newly ingested
    "updated": 2,           # re-ingested (content changed)
    "skipped": 3,           # unchanged (--update-url-article only)
    "failed": 0,            # errors
    "results": [            # per-URL status list
        {"url": "...", "status": "ok"},
        {"url": "...", "status": "unchanged"},
        ...
    ]
}

Supported Formats

Format Extension / Protocol
Digital PDF .pdf (with embedded text)
Scanned PDF .pdf (image-based, OCR applied)
URL Article http:// / https://
Media .mp3, .wav, .m4a, .mp4, .mkv, .webm
Office .docx, .doc, .rtf, .odt, .pptx, .ppt, .odp
DJVU .djvu

Citation

If you use CiteIndex in your work, please cite it:

APA:

ajia. (2026). CiteIndex: Ingest sources with proper citation (Version 0.17.0). MIT. https://github.com/Areopaguaworkshop/citeindex

BibTeX:

@software{citeindex2025,
  author  = {Yongjia, Yuan},
  title   = {CiteIndex: Ingest sources with proper citation},
  version = {0.17.0},
  year    = {2026},
  license = {MIT},
  url     = {https://github.com/Areopaguaworkshop/citeindex},
}

Status (2026-11-29)

  • Tests: 733 passing, 6 skipped in the full local suite; CI (ruff + mypy + pytest) on Python 3.12/3.13 (.github/workflows/tests.yml). MCP tests are skipped when the optional mcp extra is absent. Branch-coverage gate at ~40%, ratcheting toward 85% as legacy modules gain tests.
  • PyPI: citeindex 0.17.0 published 2026-11-29; the optional [mcp] extra and bundled citation-verification skill are included in the release.
  • MCP server: optional citeindex[mcp] extra and citeindex-mcp entry point expose library search/read, citation_verify, citation_format, and write-gated ingest_url over stdio or Streamable HTTP. The citation-verification skill is served as citeindex://skills/citation-verification and embedded in the cite-this-source / ingest-verified prompts.
  • HTML URL pipeline: deterministic HTML head metadata extraction added (Highwire Press, Dublin Core, OpenGraph, Prism, Schema.org JSON-LD); evidence binding and source_snapshot_digest now recorded without requiring Zotero or trafilatura. Page ranges bind to joined first/last-page metadata spans, and CNKI/Wanfang GB/T 7714 guidance strings ("引用本文:…"), gcdfl/ctcfol copyright preambles, and title-matched unlabeled GB/T self-citations are parsed into CSL fields. Dedicated tests cover these paths (tests/test_html_article_pipeline.py). A live 20-URL, no-LLM benchmark lives in benchmarks/html/README.md.
  • Scale benchmark (default pipeline, digital PDFs, 3 workers): 10,052 pages across 14 volumes at 44.1 ok-pages/min wall; per-document results and failure modes in benchmarks/scale/README.md.
  • Docker: 494 MB image (python:3.12-slim, non-root); the Quickstart flow is verified.
  • PyPI downloads: 8,614 total / 1,951 last 30 days (pepy.tech snapshot 2026-10-16).

License

MIT

Metadata

Release files for citeindex 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for citeindex 0.17.0
File Size Uploaded Provenance Actions
citeindex-0.17.0.tar.gz 334.4 kB Without provenance Details for citeindex-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for citeindex 0.17.0
File Interpreter ABI Platform Actions
citeindex-0.17.0-py3-none-any.whl Python 3 none any Details for citeindex-0.17.0-py3-none-any.whl

Total release size: 689.9 kB

Release files / citeindex-0.17.0.tar.gz

Download URL citeindex-0.17.0.tar.gz
Size 334.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b239ba7ad1d2cd78845f9df75b8ff96d9612bb9525ce23f57db9c250706774d0
BLAKE2b-256 checksum
How to use checksums
eb5cc564c31141ad28ccf811e3f608e6d10346c66dba26cb678749ecc86b1ed3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / citeindex-0.17.0-py3-none-any.whl

Download URL citeindex-0.17.0-py3-none-any.whl
Size 355.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30dd7269a226de99ed1af265638a7f4467682ea148f5cc7609e52e31afb84c65
BLAKE2b-256 checksum
How to use checksums
6fcef06dc1958ae83a70de1ca358dbff92b001d344877fcc666190c4bc6250f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for citeindex 0.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page