# Paperqa Local RAG

> Run PaperQA2 locally on a folder of scientific PDFs to get high-accuracy, fully-cited answers. Self-hosted, open-source RAG (Apache-2.0) — needs only an LLM key (OpenAI/Anthropic/local), no FutureHouse credits. Use when the user has a local corpus of papers and wants grounded answers, or wants to avoid the hosted Crow/Falcon for privacy / cost reasons.

- Skill: `qhjqhj00/paperqa-local-rag` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds add qhjqhj00/paperqa-local-rag`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/paperqa-local-rag/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/paperqa-local-rag

---


# PaperQA2 — Local Scientific RAG

PaperQA2 is the open-source, self-hostable engine that powers FutureHouse's Crow agent. It does retrieval-augmented generation over a local folder of PDFs / Office docs / source code, with metadata enrichment from Crossref + Semantic Scholar + Unpaywall and per-chunk LLM re-ranking. State-of-the-art on scientific QA benchmarks (LitQA2, WikiCrow assessment).

Use this skill when the user wants:

- Q&A over a private / local PDF corpus (no upload to a SaaS)
- Cited answers without paying per-call platform credits
- Full control over models, prompts, indexing, and storage
- Programmatic / batch operation

For one-shot questions over the public literature with zero setup, use the sibling `crow-literature-qa` skill instead.

## Install

```bash
pip install "paper-qa>=5"
```

Python ≥ 3.11 required. PaperQA2 uses LiteLLM for model routing — set the appropriate key:

```bash
export OPENAI_API_KEY=sk-...           # default
# or
export ANTHROPIC_API_KEY=sk-ant-...    # configure model in Settings
```

For large corpora (100+ papers), also export `CROSSREF_API_KEY` and `SEMANTIC_SCHOLAR_API_KEY` to avoid rate limits during metadata fetch.

## Quickstart — CLI

```bash
mkdir my_papers && cd my_papers
# drop some PDFs in, then:
pqa ask 'What does the literature say about CAR-T persistence in solid tumors?'
```

PaperQA2 will index the folder, fetch metadata, chunk + embed, and answer with inline citations. Index is cached in `~/.pqa/` and reused on subsequent calls.

Useful CLI commands:

```bash
pqa view                            # show all current settings
pqa -s fast view                    # show "fast" preset
pqa --temperature 0.3 ask '...'     # one-off override
pqa -s mine --llm gpt-4o save       # save your own preset called "mine"
pqa -i answers search 'CAR-T'       # search prior answers
```

## Quickstart — Library

```python
from paperqa import Settings, ask

answer = ask(
    "What does the literature say about CAR-T persistence in solid tumors?",
    settings=Settings(temperature=0.3, paper_directory="./my_papers"),
)
print(answer.formatted_answer)
```

Async / multi-question:

```python
import asyncio
from paperqa import Docs

async def main():
    docs = Docs()
    for f in ["paper1.pdf", "paper2.pdf"]:
        await docs.aadd(f)
    ans = await docs.aquery("What dose was used in study 2?")
    print(ans.formatted_answer)

asyncio.run(main())
```

## Recipes

### Use Anthropic Claude as the answer model
```python
from paperqa import Settings, ask
ans = ask("...", settings=Settings(
    llm="claude-opus-4-5",
    summary_llm="claude-opus-4-5",
    paper_directory="./my_papers",
))
```

### Local embeddings (no OpenAI key)
```python
from paperqa import Settings
s = Settings(
    embedding="sentence-transformers/all-MiniLM-L6-v2",
    paper_directory="./my_papers",
)
```

### Build & reuse an index for a large corpus
```bash
pqa -i my_corpus index ./my_papers       # build once
pqa -i my_corpus ask 'question 1'        # then query repeatedly
pqa -i my_corpus ask 'question 2'
```

### Generate Wikipedia-style articles (the WikiCrow recipe)
PaperQA2 was used to generate the [wikicrow.ai](https://wikicrow.ai) gene articles. The recipe is sectioned querying:

```python
from paperqa import Docs
sections = ["Function", "Structure", "Clinical significance", "Interactions"]
docs = Docs()
# … add a corpus of papers about your gene of interest …
article = []
for s in sections:
    a = docs.query(f"Write a Wikipedia-style '{s}' section for gene FOO based on the literature.")
    article.append(f"## {s}\n\n{a.formatted_answer}\n")
print("\n".join(article))
```

### Multimodal: figures, tables, equations
PaperQA2 v5 (Dec 2025+) supports tables, figures, and math via Docling / Nemotron readers. Install with:

```bash
pip install "paper-qa[docling]"
# or
pip install "paper-qa[nemotron]"
```

## Demo-friendly first call

```bash
mkdir demo && cd demo
curl -o paperqa.pdf https://arxiv.org/pdf/2409.13740
pqa ask 'What is PaperQA2 and what makes it different from PaperQA1?'
```

Expected output: a paragraph-length answer with `[Author Year]`-style inline citations and a reference list at the bottom.

## Costs

- LLM costs only — no FutureHouse credits.
- A typical answer on a 50-paper corpus costs $0.10–$1 with GPT-4o-class models, or $0 with a local LLM.

## Caveats

- First indexing of a large corpus can take 5–30 min as PaperQA2 fetches metadata from Crossref / Semantic Scholar. Subsequent queries are fast.
- Quality of answers depends heavily on the LLM used — `gpt-4o` / `claude-opus` produce the cleanest citations; smaller models may hallucinate references.
- For best results, ensure your PDFs are text-PDFs (not scanned). For scanned PDFs, install with the Docling extra.

