---
name: zotero-rag
description: Semantic search across your project's local library (library/markdown/). Index papers, search by meaning, find similar passages, and get expanded context. Replaces the deprecated Zotero RAG integration.
title: zotero-rag
canonical_url: https://skilld.dev/gh/nealcaren/social-data-analysis/zotero-rag
last_updated: 2026-10-16T23:11:35.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/ingest.py](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/zotero-rag/scripts/ingest.py), [scripts/rag.py](https://skilld.dev/api/skills-raw/nealcaren/social-data-analysis/zotero-rag/scripts/rag.py).
>
> If the user asked to install this Skill, run `npx skilld install nealcaren/social-data-analysis/zotero-rag`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/zotero-rag`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/nealcaren/social-data-analysis/zotero-rag) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/zotero-rag`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/zotero-rag --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/zotero-rag --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Library RAG: Semantic Search

Script paths below are relative to this skill's base directory (`$SKILL_DIR`), which Claude Code reports when the skill loads.

Semantic search over your local library of markdown-converted papers using sentence-transformers embeddings and ChromaDB.

## Prerequisites

- **uv** installed (standard in this project)
- Papers ingested via `ingest.py` (which converts to markdown, organizes files, and adds metadata to `references.bib`)
- `references.bib` with `md_path` fields linking citation keys to markdown files

**Important**: Only files registered in `references.bib` are indexed. Loose markdown files in `library/markdown/` without a bib entry will be flagged as "unlinked" during indexing. Run `ingest.py` to register them.

## Quick Start

```bash
# Index your library (first time or after adding papers)
uv run "$SKILL_DIR"/scripts/rag.py index

# Search by meaning
uv run "$SKILL_DIR"/scripts/rag.py search "cultural capital and educational attainment"
```

## Script Location

All commands use:
```
uv run "$SKILL_DIR"/scripts/rag.py <command>
```

Dependencies (`sentence-transformers`, `chromadb`) are auto-installed by `uv` on first run via PEP 723 inline metadata. No manual installation needed.

## Commands

### Index

Build or update the vector index from `library/markdown/` files.

```bash
# Index all markdown files (incremental — skips unchanged files)
uv run "$SKILL_DIR"/scripts/rag.py index

# Index specific citation keys only
uv run "$SKILL_DIR"/scripts/rag.py index --keys Smith2020_Cultural Jones2019_Institutional
```

The index is stored at `library/.rag-index/`. First run downloads the `all-MiniLM-L6-v2` embedding model (~80MB, cached by sentence-transformers).

**Run this after adding new papers** to keep the index current.

### Search

Semantic search across all indexed documents. Returns JSON lines ranked by similarity.

```bash
uv run "$SKILL_DIR"/scripts/rag.py search "social movements and collective identity"
uv run "$SKILL_DIR"/scripts/rag.py search "interview methodology" --top-k 5
uv run "$SKILL_DIR"/scripts/rag.py search "Bourdieu field theory" --min-score 0.3
```

Each result includes: `chunk_id`, `citation_key`, `section_title`, `score`, `text` (truncated), plus `title`, `author`, `year` from `references.bib`.

### Similar

Find passages similar to a given chunk (from search results).

```bash
uv run "$SKILL_DIR"/scripts/rag.py similar <chunk_id>
uv run "$SKILL_DIR"/scripts/rag.py similar abc123def456 --top-k 5
```

Use this to explore thematic connections: find a relevant passage via `search`, then use `similar` to discover related content across other papers.

### Context

Show the full context around a chunk — the target chunk plus surrounding chunks from the same document.

```bash
uv run "$SKILL_DIR"/scripts/rag.py context <chunk_id>
uv run "$SKILL_DIR"/scripts/rag.py context abc123def456 --window 3
```

Returns the target chunk and neighboring chunks (default: 2 on each side), so you can read the passage in its original context.

### Status

Show index statistics: number of documents, chunks, and last modified time.

```bash
uv run "$SKILL_DIR"/scripts/rag.py status
```

### List

List all indexed documents with chunk counts.

```bash
uv run "$SKILL_DIR"/scripts/rag.py list
```

### Remove

Remove a document from the index by citation key.

```bash
uv run "$SKILL_DIR"/scripts/rag.py remove Smith2020_Cultural
```

## Typical Workflows

### First-time setup
1. Ensure papers are in `library/markdown/` (run `ingest.py` for each PDF/EPUB)
2. Run `uv run rag.py index` to build the index
3. Search with `uv run rag.py search "your topic"`

### Adding new papers
1. Ingest the paper: `uv run "$SKILL_DIR"/scripts/ingest.py --file paper.pdf`
2. Update the index: `uv run "$SKILL_DIR"/scripts/rag.py index`

### Adding a PDF for a paper already in references.bib
1. Ingest with update: `uv run "$SKILL_DIR"/scripts/ingest.py --file paper.pdf --citekey ExistingKey2022 --update`
2. Update the index: `uv run "$SKILL_DIR"/scripts/rag.py index`

### Deep exploration
1. **Search** for a topic: `search "concept or question"`
2. **Read context** of a promising hit: `context <chunk_id>`
3. **Find similar** passages across other papers: `similar <chunk_id>`
4. **Read the full paper** if needed: open the `source_file` path from results

## When to Use RAG vs. Grep

| Need | Tool |
|------|------|
| **Conceptual/semantic search** (find passages about a concept even if they don't use the exact words) | `rag.py search` |
| **Exact keyword/phrase search** (find specific terms, author names, method names) | `grep library/markdown/` |
| **Metadata search** (by author, year, journal) | `grep references.bib` |

Both approaches complement each other. Use semantic search for exploratory discovery and grep for precise retrieval.

## Technical Details

- **Embedding model**: `all-MiniLM-L6-v2` (384 dimensions, same as old Zotero RAG)
- **Vector store**: ChromaDB with file-based persistence at `library/.rag-index/`
- **Chunking**: Split by `##` headers (section-level); fallback to ~512-token fixed chunks for headerless documents
- **Incremental indexing**: Content hashes stored in metadata; unchanged files are skipped on re-index
- **Output format**: JSON lines for easy parsing by Claude or other tools
