Smart Composer for Obsidian
repository·main·Indexed 25 days ago
https://github.com/glowingjade/obsidian-smart-composerAn Obsidian plugin that enhances AI-assisted writing by integrating vault content into AI context. It features @file mentions, semantic vault search (RAG), one-click document edits, and support for the Model Context Protocol (MCP). Compatible with various API providers including OpenAI, Anthropic, Gemini, and local LLMs via Ollama or LM Studio.
What's inside Smart Composer
- Smart Composer supports the Model Context Protocol (MCP), allowing you to connect the assistant to external MCP servers. This enables the use of third-party tools and external data sources directly within your chat interface.
Perform Vault Search (RAG) for relevant notes
mainSmart Composer includes a Retrieval-Augmented Generation (RAG) feature that uses semantic search to find relevant notes from your vault to enhance AI responses.
To run a Vault Search answer, use the keyboard shortcut:
Cmd+Shift+Enter
Use Prompt Templates and Custom System Prompts
mainPrompt Templates
Standardize repetitive tasks by creating and reusing templates. In the chat view, type
/to access your templates. You can also create templates from any selected text with one click.Custom System Prompts
You can define your own system prompts in the settings, which will be applied to every chat conversation to guide the AI's behavior.
Apply AI-suggested edits to documents
mainSmart Composer can suggest changes to your current document. When a suggestion is made, you can review the document change recommendations and apply them instantly with a single click.Install and set up Smart Composer
mainTo use Smart Composer in Obsidian, follow these steps:
Install via Community Plugins:
- Open Obsidian Settings.
- Navigate to
Community pluginsand clickBrowse. - Search for
Smart Composerand clickInstall. - Enable the plugin.
Configure AI Providers: You can choose between two connection methods in
Settings > Smart Composer:- Connect subscription (no API key): Use this to connect your Claude or OpenAI accounts directly via an OAuth-style flow.
- Warning: Using subscription OAuth for Claude carries a risk of account restriction/banning per Anthropic's Terms of Service. Use at your own risk.
- API Providers (usage-based billing): Add an API key in
Settings > Smart Composer > Providersfor providers like OpenAI, Anthropic, or Gemini.
- Connect subscription (no API key): Use this to connect your Claude or OpenAI accounts directly via an OAuth-style flow.
Troubleshooting Installation: If the plugin fails to load, ensure your Obsidian installer is up to date. If
Settings > General > Check for updatesdoesn't resolve it, manually download and run the latest installer from obsidian.md.
Use Contextual Chat with @mentions and Multimedia
mainThe Contextual AI Assistant allows you to precisely control the information the AI uses for its responses.
Referencing Vault Content
Use the
@symbol in the chat to select specific context:- Type
@<fname>to choose specific files or folders as your conversation context.
Adding Multimedia Context
You can expand the AI's context by adding non-textual information:
- Websites: Add website links; content is automatically extracted.
- Images: Add images via the upload button, drag & drop, or pasting from the clipboard.
- YouTube: Add YouTube links to include video transcripts as context.
- External Files: Support for PDF and DOCX is planned for a future update.
- Type
Configure custom models and local LLMs
mainYou can customize which AI models power your experience via
Settings > Smart Composer > Providers.Supported API Providers
- OpenAI
- Anthropic
- Google (Gemini)
- Groq
- DeepSeek
- OpenRouter
- Azure OpenAI
- Any other OpenAI-compatible providers
Local Model Support
For complete privacy and offline usage, you can run open-source LLMs and embedding models locally using Ollama, [LM Studio], or [MorphLLM].
Configure Drizzle ORM for PostgreSQL
mainThe project uses Drizzle ORM with a PostgreSQL dialect. The configuration is defined using
defineConfigfromdrizzle-kit. To maintain the database schema, ensure theschemapath points to./src/database/schema.tsand thedialectis set to'postgresql'.import { defineConfig } from 'drizzle-kit' export default defineConfig({ dialect: 'postgresql', schema: './src/database/schema.ts', })Configure Smart Composer settings schema
mainThesmartComposerSettingsSchemadefines the structure and validation for the plugin's configuration. It includes settings for LLM providers, chat models, embedding models, RAG (Retrieval-Augmented Generation) options, MCP (Model Context Protocol) server configurations, and chat behavior. If values are invalid, the schema uses.catch()to revert to safe defaults.Open and interact with the Chat View
mainThe plugin provides several ways to interact with the Chat interface:
openChatView(openNewChat?: boolean): Opens the chat view. IfopenNewChatis true, it starts a fresh session. If an active editor is present, it attempts to include the selected block data in the context.activateChatView(chatProps?: ChatProps, openNewChat?: boolean): Low-level method to ensure the chat leaf is active and set to the correct state.addSelectionToChat(editor: Editor, view: MarkdownView): Specifically targets the current selection in the editor and adds it to the existing chat session, then focuses the message input.
Format LLM messages with formatMessages()
mainUse
formatMessages()to prepare an array ofRequestMessageobjects for LLM API consumption. This function ensures compatibility with providers that require strict alternation betweenuserandassistantroles by merging consecutive messages of the same role.Key behaviors:
- System Message Consolidation: All messages with the
systemrole are collected, concatenated with double newlines, and placed at the very beginning of the message array. - Role Alternation: Consecutive messages with the same role (e.g., two
usermessages in a row) are merged into a single message. - Content Merging: When merging, the function handles both
stringandContentPart[]formats. If all merged parts are text-based, the resulting content is returned as a single concatenatedstring. Otherwise, it returns aContentPart[]array. - Empty Content Filtering: Empty or whitespace-only text parts are filtered out during the merge process.
- System Message Consolidation: All messages with the
Access the Database Manager
mainTheDatabaseManagerhandles the underlying storage. UsegetDbManager()to retrieve the instance. This is an asynchronous operation that initializes the database (using PGLite). If initialization fails due to aPGLiteAbortedException, the plugin will prompt the user to update the installer.