RAG (Retrieval Augmented Generation) system for Trilium Notes that enables semantic search and LLM integration with your personal knowledge base.
┌────────────────────────────┐
│ Trilium │
│ SQLite Database │
│ (notes, tree, tags, attrs) │
└────────────┬───────────────┘
│
Full/Incremental Extract
│
▼
┌────────────────────────────┐
│ Trilium Indexer Service │
│ │
│ - Reads SQLite │
│ - Chunks notes │
│ - Generates embeddings │
│ - Syncs Weaviate │
└────────────┬───────────────┘
│
Vector + Metadata
│
▼
┌────────────────────────────┐
│ Weaviate │
│ │
│ - Vector index │
│ - Metadata filtering │
│ - Hybrid search │
└────────────┬───────────────┘
│
Semantic retrieval (Top-K)
│
▼
┌────────────────────────────┐
│ LLM Gateway │
│ │
│ - Prompt assembly │
│ - Context injection │
│ - Model calls (GPT/Claude) │
└────────────┬───────────────┘
│
▼
Natural-language answer
- Web Interface: Modern, responsive web UI for easy querying
- REST API: Programmatic access via FastAPI endpoints
- Semantic Search: Vector-based search across all your Trilium notes
- Incremental Indexing: Efficiently sync only changed notes
- Hybrid Search: Combine keyword and semantic search for better results
- Multi-LLM Support: Works with OpenAI GPT, Anthropic Claude, and Google Gemini
- Note Links: Direct links to notes in your Trilium instance
- Hierarchical Context: Includes note paths for better semantic search
- Sentence-Based Chunking: Intelligent text splitting at sentence boundaries
- Metadata Filtering: Search by tags, attributes, and note hierarchy
- Flexible Embeddings: Support for multiple embedding providers
- Python 3.12+
- uv - Fast Python package manager
- Docker (for running Weaviate locally)
- Trilium Notes with access to its SQLite database
curl -LsSf https://astral.sh/uv/install.sh | shgit clone git@github.com:MrDesjardins/trilium-ai.git
cd trilium-ai
uv synccd docker
docker compose up -dcp .env.example .envQuick Setup with Environment Variables:
Edit .env and set your LLM provider, model, and API key:
# Example: Using Gemini 2.5 Flash (fast and cost-effective)
LLM_PROVIDER=gemini
LLM_MODEL=gemini-2.5-flash
GEMINI_API_KEY=your-api-key-hereSupported Providers:
- OpenAI:
gpt-4o,gpt-4-turbo,gpt-3.5-turbo,gpt-5-mini - Anthropic:
claude-3-5-sonnet-20241022,claude-3-opus-20240229 - Gemini:
gemini-2.5-flash(recommended),gemini-1.5-pro,gemini-1.5-flash
See docs/MODEL_SETUP.md for detailed model configuration guide.
You'll also need to configure your Trilium database path in config/config.yaml.
uv run trilium-ai index --fullCommand Line:
uv run trilium-ai query "What are my notes about Python?"Web Interface:
# Start the web server
uv run trilium-ai web
# Or with auto-reload for development
uv run trilium-ai web --reloadThen open http://localhost:3000 in your browser.
uv sync --all-extrasuv run pytest# Format code
uv run black src/ tests/
# Lint
uv run ruff check src/ tests/
# Type check
uv run mypy src/trilium-ai/
├── src/trilium_ai/
│ ├── indexer/ # SQLite reader, chunker, embedder
│ ├── gateway/ # LLM integration and retrieval
│ ├── web/ # FastAPI web interface
│ │ ├── static/ # CSS, JavaScript
│ │ └── templates/ # HTML templates
│ ├── shared/ # Shared utilities (Weaviate client, config)
│ └── cli/ # CLI commands
├── tests/ # Test suite
├── config/ # Configuration files
├── docker/ # Docker Compose for Weaviate
└── scripts/ # Deployment scripts
# Full reindex
uv run trilium-ai index --full
# Incremental sync
uv run trilium-ai index --incremental
# Watch mode (continuous sync)
uv run trilium-ai index --watch# Query with default settings
uv run trilium-ai query "your question"
# Query with custom top-k
uv run trilium-ai query "your question" --top-k 10
# Query specific model
uv run trilium-ai query "your question" --model gpt-4-turbo# Start web server
uv run trilium-ai web
# Custom port
uv run trilium-ai web --port 8080
# Development mode with auto-reload
uv run trilium-ai web --reload# Check index status
uv run trilium-ai status
# Reset index
uv run trilium-ai resetThe easiest way to configure Trilium AI is using environment variables in .env:
# LLM Configuration (override config.yaml)
LLM_PROVIDER=gemini # openai, anthropic, or gemini
LLM_MODEL=gemini-2.5-flash # See MODEL_SETUP.md for all options
LLM_TEMPERATURE=0.7 # 0.0-1.0 (optional)
LLM_MAX_TOKENS=2000 # Max response tokens (optional)
# API Keys
GEMINI_API_KEY=your-key-here # For Gemini models
OPENAI_API_KEY=sk-... # For OpenAI models
ANTHROPIC_API_KEY=sk-ant-... # For Claude modelsSee docs/MODEL_SETUP.md for the complete model configuration guide.
See config/config.yaml for all available configuration options.
Key configuration sections:
- trilium: Database path and sync settings
- weaviate: Vector database connection
- embeddings: Embedding model and parameters
- chunking: Text chunking strategy
- llm: LLM provider and model settings (can be overridden by env vars)
- retrieval: Search parameters
For production deployment on Ubuntu Server with automated setup and systemd services:
# Clone repository
cd /opt
sudo git clone https://github.com/mrdesjardins/trilium-ai.git
sudo chown -R $USER:$USER trilium-ai
cd trilium-ai
# Run automated setup
./scripts/setup.sh
# Install systemd services
sudo ./scripts/install-service.shSee DEPLOYMENT.md for comprehensive production deployment guide including:
- Automated setup scripts
- Systemd service installation (sync + web)
- Auto-start on boot
- Update procedures
- Monitoring and troubleshooting
- Security best practices
See WEB.md for web interface documentation including:
- Development and production setup
- API endpoints and examples
- Security considerations
- Customization guide
MIT