Ollama Chat Plugin for Obsidian

A plugin that integrates Ollama with Obsidian to create a chat interface that can access your vault content contextually.

Features

  • Chat with local AI models — Interact with Ollama models directly in Obsidian's sidebar
  • Vault context search — The assistant automatically searches your notes using weighted scoring (headings, frontmatter titles/tags, content)
  • Tool integration — AI can create files in your vault via the create_file tool
  • Streaming responses — Real-time token streaming for a responsive chat experience
  • Configurable settings — Customize model, URL, search limits, and message history

Installation

From Source

  1. Clone this repository into your Obsidian vault's .obsidian/plugins/ folder:
    cd .obsidian/plugins
    git clone <repo-url> obsidian-ollama
    cd obsidian-ollama
    npm install
    npm run build
    
  2. Enable the plugin in Obsidian: Settings → Community plugins → Ollama Plugin

Prerequisites

  1. Install Ollama: Follow the instructions at ollama.ai
  2. Start Ollama: ollama serve
  3. Pull a model: ollama pull llama3 (or any model you prefer)

Configuration

Open Settings → Ollama Plugin to configure:

Setting Default Description
Ollama URL http://localhost:11434 Your Ollama instance URL
Model llama3 Model to use for chat

Internal Settings

Setting Default Description
Vault Search Limit 3 Max notes returned for context
Max Message History 50 Messages kept in conversation context

Usage

  1. Click the chat icon in the left ribbon to open the chat view
  2. Type your message and press Enter or click Send
  3. Click New Chat to start a fresh conversation

Vault Context

When you send a message, the plugin automatically searches your vault for relevant notes and includes them as context. The search uses weighted scoring:

  • Headings — 5x weight
  • Frontmatter title — 3x weight
  • Frontmatter tags — 2.5x weight
  • First paragraph — 1.5x weight
  • General content — 1x weight

Tools

The plugin exposes a create_file tool that allows the AI to create new markdown files in your vault. Paths are validated for safety (no .obsidian/.git access, no path traversal).

Supported Models

Any Ollama-supported model works. Popular choices:

Model Best For
llama3 General chat
mistral Fast responses
codellama Code assistance
gemma Lightweight local use

Development

npm install          # Install dependencies
npm run build        # Compile TypeScript
npm run watch        # Watch mode for development
npm test             # Run tests (Jest)
npm run lint         # Lint with ESLint
npm run format       # Format with Prettier

Project Structure

src/
├── main.ts           # Plugin entry point and settings
├── chat-view.ts      # Chat UI and message handling
├── ollama-client.ts  # Ollama API communication
├── vault-indexer.ts  # Vault search and scoring
├── tool-executor.ts  # Tool execution (create_file)
├── error-handler.ts  # Centralized error handling
├── utils.ts          # Validation and logging utilities
├── types.ts          # TypeScript type definitions
└── constants.ts      # Default configuration

Testing

The project includes tests for all major components. Run with:

npm test

Troubleshooting

Issue Solution
Connection refused Ensure Ollama is running (ollama serve)
Model not found Pull the model first (ollama pull <model>)
Permission errors Check vault write permissions
Empty responses Try a different model or check Ollama logs

Security

  • File paths are validated to prevent access to .obsidian/ and .git/ directories
  • Path traversal attempts (..) are blocked
  • Absolute paths and Windows drive letters are rejected
  • Maximum path length is enforced (200 characters)

License

MIT

S
Description
No description provided
Readme 7.6 MiB
Languages
JavaScript 59.5%
TypeScript 39.5%
CSS 0.7%
Shell 0.3%