Skip to content
ย 
ย 

Latest commit

ย 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

RefSense - AI Metadata Extractor for Zotero

A powerful Zotero 7 plugin that extracts bibliographic metadata from PDF files using AI (OpenAI GPT or local Ollama models) and intelligently manages parent items.

โœจ Features

๐Ÿ”˜ PDF Reader Integration

  • Floating Button: "๐Ÿ“„ RefSense" button automatically appears in PDF reader
  • Keyboard Shortcut: Ctrl+Shift+E for quick access
  • Auto-Detection: Automatically detects PDF reader windows

๐Ÿ“‹ Item List Context Menu

  • Smart Menu: Right-click context menu for PDFs without parent items
  • Contextual Display: "๐Ÿ“„ RefSense: Extract Bibliographic Info" menu appears only for applicable PDFs
  • Multi-Selection: Supports selecting from multiple PDFs when multiple items are chosen
  • Unified Workflow: Same extraction process as PDF reader integration

๐Ÿค– AI-Powered Extraction

  • OpenAI GPT-4 Turbo: High-precision metadata extraction
  • Local Ollama Models: Privacy-focused local processing
  • Smart Prompting: Optimized prompts for academic paper analysis
  • Robust Error Handling: Retry logic with exponential backoff

๐Ÿ“„ Advanced PDF Processing

  • Multi-Method Text Extraction: 6 different extraction methods for maximum compatibility
  • Quality Validation: Binary filtering and academic content scoring
  • Flexible Page Selection: First page, current page, or custom range
  • Fallback System: Comprehensive text extraction with quality verification

๐Ÿง  Intelligent Parent Item Management

  • Smart Button Display: RefSense button only appears for PDFs without parent items
  • Duplicate Detection: Checks for existing parent items using DOI and title matching
  • Smart Update Options: 3-choice dialog (Update/Create New/Cancel) when parent exists
  • Field-by-Field Comparison: Visual side-by-side metadata comparison with color coding
  • Selective Updates: Choose which fields to update with radio buttons
  • Batch Operations: "Select All Existing" or "Select All New" options
  • Fallback System: Native dialog support when DOM access fails

๐Ÿ“ฅ Seamless Zotero Integration

  • Automatic Parent Creation: Generate Zotero items with extracted metadata
  • PDF Linking: Establish proper parent-child relationships
  • Transaction Management: Database integrity with rollback support
  • Field Mapping: Complete mapping to Zotero fields (title, authors, year, journal, DOI, etc.)

โš™๏ธ Comprehensive Settings

  • CSP-Compatible Settings: Prompt-based configuration system that works with Zotero's security policies
  • Dynamic UI: Backend-specific settings sections that show/hide based on selection
  • API Key Management: Secure Base64 encoding, masking, and preservation of existing values
  • Connection Testing: Validate API connectivity and model availability
  • Model Selection: Choose from available AI models with automatic detection
  • Step-by-Step Configuration: User-friendly guided setup process

๐Ÿš€ Quick Start

Installation

  1. Download the latest .xpi file from the releases page
  2. In Zotero 7, go to Tools โ†’ Add-ons
  3. Click the gear icon and select "Install Add-on From File"
  4. Select the downloaded .xpi file
  5. Restart Zotero

Configuration

  1. Go to Tools โ†’ Add-ons โ†’ RefSense โ†’ Options (or Tools โ†’ RefSense Settings)
  2. The settings dialog will guide you through configuration:
    • Choose your AI backend (OpenAI or Ollama)
    • Enter API keys (securely masked and encoded)
    • Select models from available options
    • Configure page extraction preferences
  3. Each setting includes validation and helpful prompts
  4. Test connection to ensure everything works

Basic Usage

Method 1: PDF Reader

  1. Open a PDF in Zotero's PDF reader (must be a PDF without existing parent item)
  2. Look for the RefSense button (๐Ÿ“„) in the top-right corner, or press Ctrl+Shift+E
  3. Click the button - AI processing will start automatically
  4. Wait for extraction - the plugin uses 6 different methods to extract text and validate quality
  5. Review metadata - a preview dialog shows the extracted bibliographic information
  6. Confirm creation - a new parent item will be created and linked to your PDF

Method 2: Item List Context Menu

  1. Right-click a PDF in Zotero's item list (must be a PDF without existing parent item)
  2. Select "๐Ÿ“„ RefSense: Extract Bibliographic Info" from the context menu
  3. Choose PDF if multiple PDFs are selected (selection dialog appears)
  4. Wait for extraction - same AI processing as PDF reader method
  5. Review and confirm - create parent item without opening the PDF

Note: RefSense options only appear for PDFs that don't already have parent items, keeping your interface clean and focused.

๐Ÿ”ง Advanced Features

Field-by-Field Metadata Comparison

When a PDF already has a parent item (rare cases where button appears), RefSense shows a detailed comparison dialog:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Metadata comparison selection                           โ”‚
โ”‚                                                         โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Field   โ”‚ Existing Value  โ”‚ New Extracted Value     โ”‚ โ”‚
โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚
โ”‚ โ”‚ Title   โ”‚ โ—‹ Old Title     โ”‚ โ— New Extracted Title   โ”‚ โ”‚
โ”‚ โ”‚ Authors โ”‚ โ—‹ John Doe      โ”‚ โ— Jane Smith, Bob Lee   โ”‚ โ”‚
โ”‚ โ”‚ Year    โ”‚ โ—‹ 2023          โ”‚ โ— 2024                  โ”‚ โ”‚
โ”‚ โ”‚ Journal โ”‚ โ—‹ (empty)       โ”‚ โ— Nature Science        โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                         โ”‚
โ”‚ [Select All Existing] [Select All New]                  โ”‚
โ”‚                           [Apply Selected] [Cancel]     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Supported AI Models

OpenAI:

  • GPT-4 Turbo (recommended)
  • GPT-4
  • GPT-3.5 Turbo

Ollama (local):

  • LLaVA models
  • Llama models with vision capabilities
  • Custom local models

๐Ÿ› ๏ธ Development

Containerized Build (no local Node required)

If you donโ€™t want Node.js or npm on your machine, build inside a container.

  • Requirements: Docker or Podman installed
  • Output: build/refsense-YYYYMMDD.HHMM.xpi

Using Make (recommended):

# With Docker
make build-xpi

# With Podman
CONTAINER=podman make build-xpi

This uses a local directory .node_modules/ (bind-mounted) so node_modules/ does not clutter your repo and avoids Docker Desktop volume permission issues on WSL.

Manual commands (alternative):

# Docker (bind-mount a local .node_modules directory)
mkdir -p .node_modules
docker run --rm \
  -u $(id -u):$(id -g) \
  -v "$PWD":/workspace \
  -v "$PWD/.node_modules":/workspace/node_modules \
  -w /workspace \
  node:18-bullseye sh -c "npm ci && npm run build"

# Podman
mkdir -p .node_modules
podman run --rm \
  -u $(id -u):$(id -g) \
  -v "$PWD":/workspace \
  -v "$PWD/.node_modules":/workspace/node_modules \
  -w /workspace \
  docker.io/library/node:18-bullseye sh -c "npm ci && npm run build"

Optional: build and use a local image

# Build local image
make docker-image

# Build .xpi using the local image
make build-xpi-image

Troubleshooting (WSL + Docker Desktop)

  • If you see EACCES errors for /workspace/node_modules, ensure .node_modules/ exists and is writable in your WSL filesystem (not a Windows mount). The Makefileโ€™s prepare step handles this.
  • If Docker is not detected in WSL, enable WSL integration in Docker Desktop settings or use CONTAINER=podman with Podman installed in WSL.

Prerequisites

  • Node.js 16+
  • npm or yarn

Setup

# Clone the repository
git clone https://github.com/your-username/zotero-refsense.git
cd zotero-refsense

# Install dependencies (local build only)
npm install

# Build the plugin (local build only)
npm run build

# Development build with watching
npm run dev

Project Structure

zotero-refsense/
โ”œโ”€โ”€ manifest.json              # Zotero 7 Extension manifest
โ”œโ”€โ”€ package.json              # npm package configuration
โ”œโ”€โ”€ bootstrap.js              # Main plugin file
โ”œโ”€โ”€ build.js                  # XPI build script
โ”œโ”€โ”€ ai/                       # AI communication modules
โ”‚   โ”œโ”€โ”€ openai.js            # OpenAI API integration
โ”‚   โ””โ”€โ”€ ollama.js            # Ollama API integration
โ”œโ”€โ”€ config/                   # Configuration system
โ”‚   โ”œโ”€โ”€ settings.js          # Settings management
โ”‚   โ””โ”€โ”€ prefs.xhtml          # Settings UI
โ”œโ”€โ”€ build/                    # Build output
โ”‚   โ””โ”€โ”€ refsense.xpi         # Installable XPI package
โ””โ”€โ”€ CLAUDE.md                 # Development documentation

๐Ÿ“‹ Configuration Options

AI Backend Settings

{
  "ai_backend": "openai",               // "openai" or "ollama"
  "openai_api_key": "sk-...",          // OpenAI API key
  "openai_model": "gpt-4-turbo",       // OpenAI model
  "ollama_model": "llava:13b",         // Ollama model
  "ollama_host": "http://localhost:11434", // Ollama server
  "default_page_source": "first",      // "first", "current", "range"
  "page_range": "1โ€“2"                  // Page range for extraction
}

Page Extraction Options

  • First Page: Extract from the first page (default, recommended for papers)
  • Current Page: Extract from currently viewed page
  • Page Range: Extract from specified page range (e.g., "1-3")

๐Ÿ” How It Works

  1. Smart UI Logic: Only displays RefSense options (button/menu) for PDFs without existing parent items
  2. Dual Access Methods:
    • PDF Reader floating button with keyboard shortcut
    • Item list context menu for direct PDF processing without opening
  3. PDF Text Extraction: Uses 6 different methods including Zotero's Fulltext API, cache files, and database queries
  4. Quality Validation: Filters binary content and scores academic relevance to ensure good text quality
  5. AI Processing: Sends optimized prompts to chosen AI backend (OpenAI GPT-4 or local Ollama)
  6. Metadata Parsing: Converts AI JSON response to Zotero fields with validation and error handling
  7. Parent Creation: Creates new parent items and establishes proper PDF relationships
  8. Database Integration: Uses Zotero's transaction system for data integrity with rollback support

๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ†˜ Support

  • Issues: Use the GitHub issue tracker
  • Documentation: See CLAUDE.md for detailed development info
  • Discussions: GitHub Discussions for questions and ideas

๐Ÿ”’ Privacy & Security

  • OpenAI: Only sends PDF text content (first page typically contains public bibliographic info)
  • Ollama: Completely local processing, no data transmitted externally
  • API Keys: Stored locally with Base64 encoding
  • No Tracking: No usage analytics or data collection

๐ŸŽฏ Status & Roadmap

โœ… Current Status: Production Ready

RefSense is a complete, fully functional plugin with all core features implemented:

  • End-to-end PDF โ†’ AI โ†’ Parent item workflow
  • Robust error handling and fallback systems
  • CSP-compatible settings system
  • Smart UI that adapts to PDF status
  • Production-ready stability and performance

๐Ÿ”ฎ Future Enhancements (Optional)

  • Additional error handling and user experience improvements
  • Batch processing for multiple PDFs
  • Advanced duplicate detection across entire library
  • Custom field mapping options
  • Integration with additional AI providers
  • Multi-language interface support

RefSense - Making academic research more efficient with AI-powered metadata extraction.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages