Zotero Chunk RAG
Enables passage-level semantic search over a Zotero library by extracting, chunking, and embedding PDF text using Gemini and ChromaDB. It provides MCP tools to perform topical searches and retrieve specific document passages with surrounding context.
README
DeepZotero
Semantic search over a Zotero library. PDFs are extracted (text, tables, figures), chunked, embedded, and stored in ChromaDB. An MCP server exposes the index to Claude Code (or any MCP client) as 13 tools for semantic search, boolean search, table/figure search, context expansion, citation graph lookup, indexing, and cost tracking.
What it extracts
- Text — section-aware chunks with overlap, classified by document section (abstract, methods, results, etc.)
- Tables — vision-based extraction via Claude Haiku 4.5. Each table is rendered to PNG and transcribed to structured markdown (headers, rows, footnotes). Falls back to PyMuPDF heuristics if vision is disabled.
- Figures — detected with captions, extracted as PNGs, searchable by caption text.
Requirements
- Python 3.10+
- A Gemini API key for embeddings (unless using
embedding_provider: "local") - An Anthropic API key for vision-based table extraction (optional but recommended)
- A Zotero installation with PDFs in
storage/
Install
python -m venv .venv
.venv/Scripts/python.exe -m pip install -e .
For vision table extraction:
.venv/Scripts/python.exe -m pip install -e ".[vision]"
Setup
1. Configuration
mkdir -p ~/.config/deep-zotero
cp config.example.json ~/.config/deep-zotero/config.json
Edit ~/.config/deep-zotero/config.json:
{
"zotero_data_dir": "~/Zotero",
"chroma_db_path": "~/.local/share/deep-zotero/chroma",
"gemini_api_key": "YOUR_GEMINI_KEY",
"anthropic_api_key": "YOUR_ANTHROPIC_KEY"
}
All other fields have sensible defaults. You can also set GEMINI_API_KEY and ANTHROPIC_API_KEY as environment variables instead.
2. API keys
Gemini (required for default embeddings):
Get a key at aistudio.google.com/app/apikey. Set it as gemini_api_key in config or GEMINI_API_KEY env var. If you don't want to use Gemini, set "embedding_provider": "local" to use ChromaDB's built-in all-MiniLM-L6-v2 model (no API key needed, lower quality).
Anthropic (required for vision table extraction):
Get a key at console.anthropic.com. Set it as anthropic_api_key in config or ANTHROPIC_API_KEY env var. Without this key, tables are still extracted via PyMuPDF heuristics but accuracy on complex tables is lower. Vision extraction uses the Anthropic Batch API with Claude Haiku 4.5 — cost is roughly $0.016 per table, with prompt caching reducing cost on large batches.
To disable vision extraction entirely:
{
"vision_enabled": false
}
3. Index your library
deep-zotero-index -v
To test with a subset first:
deep-zotero-index --limit 10 -v
This reads the Zotero SQLite database (read-only, safe while Zotero is open), extracts text/tables/figures from each PDF, chunks the text, embeds via Gemini, and stores everything in ChromaDB.
CLI options:
| Flag | Description |
|---|---|
--force |
Delete and rebuild index for all matching items |
--limit N |
Only index N items |
--item-key KEY |
Index a single Zotero item |
--title PATTERN |
Regex filter on title (case-insensitive) |
--no-vision |
Skip vision table extraction for this run |
--config PATH |
Use a different config file |
-v |
Debug logging |
The indexer is incremental — it only processes items not already in the index. Use --force after changing chunk_size, embedding_dimensions, or ocr_language.
You can also trigger indexing from the MCP client via the index_library tool.
4. Register the MCP server
Add to your Claude Code settings (~/.claude/settings.json):
{
"mcpServers": {
"deep-zotero": {
"command": "/path/to/.venv/bin/python",
"args": ["-m", "deep_zotero.server"]
}
}
}
On Windows:
{
"mcpServers": {
"deep-zotero": {
"command": "C:\\path\\to\\.venv\\Scripts\\python.exe",
"args": ["-m", "deep_zotero.server"]
}
}
}
Restart Claude Code. All 13 tools will be available.
Configuration reference
Zotero
| Field | Default | Description |
|---|---|---|
zotero_data_dir |
~/Zotero |
Path to Zotero's data directory (contains zotero.sqlite and storage/) |
chroma_db_path |
~/.local/share/deep-zotero/chroma |
Where the ChromaDB index is stored on disk |
Embedding
| Field | Default | Description |
|---|---|---|
embedding_provider |
"gemini" |
"gemini" for Gemini API, "local" for ChromaDB's built-in all-MiniLM-L6-v2 (no key needed) |
embedding_model |
"gemini-embedding-001" |
Gemini model name (only used when provider is "gemini") |
embedding_dimensions |
768 |
Output vector dimensions. gemini-embedding-001 supports 64-3072. Changing requires --force re-index |
gemini_api_key |
null |
Falls back to GEMINI_API_KEY env var |
embedding_timeout |
120.0 |
Timeout in seconds for embedding API calls |
embedding_max_retries |
3 |
Max retries for failed embedding calls |
Chunking
| Field | Default | Description |
|---|---|---|
chunk_size |
400 |
Target chunk size in tokens (~4 chars/token). Changing requires --force re-index |
chunk_overlap |
100 |
Overlap between consecutive chunks in tokens |
Vision
| Field | Default | Description |
|---|---|---|
vision_enabled |
true |
Enable vision table extraction during indexing |
vision_model |
"claude-haiku-4-5-20251001" |
Anthropic model for table transcription |
anthropic_api_key |
null |
Falls back to ANTHROPIC_API_KEY env var |
Reranking
| Field | Default | Description |
|---|---|---|
rerank_enabled |
true |
Enable composite score reranking |
rerank_alpha |
0.7 |
Similarity exponent (0-1). Lower = more metadata influence |
rerank_section_weights |
null |
Override default section weights |
rerank_journal_weights |
null |
Override default journal quartile weights |
oversample_multiplier |
3 |
Oversample factor before reranking |
oversample_topic_factor |
5 |
Additional factor for search_topic |
stats_sample_limit |
10000 |
Max chunks sampled for get_index_stats |
OCR
| Field | Default | Description |
|---|---|---|
ocr_language |
"eng" |
Tesseract language code for scanned pages ("fra", "deu", etc.). Changing requires --force re-index |
OpenAlex
| Field | Default | Description |
|---|---|---|
openalex_email |
null |
Email for OpenAlex polite pool (10 req/s vs 1 req/s). Falls back to OPENALEX_EMAIL env var |
MCP tools
Semantic search
search_papers — Passage-level semantic search. Returns matching text with surrounding context, reranked by composite score (similarity × section weight × journal weight). Supports required_terms for combining semantic search with exact word matching — each term must appear as a whole word in the passage.
Parameters: query, top_k (1-50), context_chunks (0-3), year_min, year_max, author, tag, collection, chunk_types (text/figure/table), section_weights, journal_weights, required_terms (list of words that must appear in passage).
search_topic — Paper-level topic search, deduplicated by document. Groups chunks by paper, scores by average and best composite relevance.
Parameters: query, num_papers (1-50), year_min, year_max, author, tag, collection, chunk_types, section_weights, journal_weights.
search_tables — Semantic search over table content (headers, cells, captions). Returns tables as markdown.
Parameters: query, top_k (1-30), year_min, year_max, author, tag, collection, journal_weights.
search_figures — Semantic search over figure captions. Returns figure metadata and paths to extracted PNGs.
Parameters: query, top_k (1-30), year_min, year_max, author, tag, collection.
Boolean search
search_boolean — Exact word matching via Zotero's native full-text index. Returns papers (not passages) matching AND/OR word queries. No phrase search, no stemming.
Parameters: query (space-separated terms), operator (AND/OR), year_min, year_max.
Context expansion
get_passage_context — Expand context around a passage from search_papers. For table results, pass table_page and table_index to find body text citing the table.
Parameters: doc_id, chunk_index, window (1-5), table_page, table_index.
Citation graph (OpenAlex)
Requires the document to have a DOI in Zotero.
find_citing_papers — Papers that cite a given document. Parameters: doc_id, limit (1-100).
find_references — Papers a document cites. Parameters: doc_id, limit (1-100).
get_citation_count — Citation and reference counts. Parameters: doc_id.
Index management
index_library — Trigger indexing from the MCP client. Parameters: force_reindex, limit, item_key, title_pattern, no_vision.
get_index_stats — Document/chunk/table/figure counts, section coverage, journal coverage.
get_reranking_config — Current reranking weights and valid override values.
get_vision_costs — Vision API batch usage and cost summary. Parameters: last_n (recent entries to show).
Reranking
Search results are scored:
composite_score = similarity^alpha * section_weight * journal_weight
Default section weights:
| Section | Weight |
|---|---|
| results | 1.0 |
| conclusion | 1.0 |
| table | 0.9 |
| methods | 0.85 |
| abstract | 0.75 |
| background | 0.7 |
| unknown | 0.7 |
| discussion | 0.65 |
| introduction | 0.5 |
| preamble | 0.3 |
| appendix | 0.3 |
| references | 0.1 |
Default journal weights: Q1=1.0, Q2=0.85, Q3=0.65, Q4=0.45.
Override per-call via section_weights and journal_weights parameters. Set a section to 0 to exclude it. Disable reranking entirely with "rerank_enabled": false.
Shared filter parameters
| Parameter | Type | Description |
|---|---|---|
author |
string | Case-insensitive substring match against author names |
tag |
string | Case-insensitive substring match against Zotero tags |
collection |
string | Case-insensitive substring match against collection names |
year_min / year_max |
int | Publication year range |
section_weights |
dict | Override section weights for this call |
journal_weights |
dict | Override journal quartile weights |
required_terms |
list | Exact whole-word matches required in passage (search_papers only) |
Debug viewer
tools/debug_viewer.py is a PyQt6 browser for inspecting the ChromaDB index — view papers, tables (rendered markdown vs PDF), figures, and individual chunks.
.venv/Scripts/python.exe tools/debug_viewer.py
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。