How glowingjade/obsidian-smart-composer works
──────────────────────────────
Identifying the Project’s Components
──────────────────────────────
• Project Purpose:
• Smart Composer is designed as an Obsidian plugin that integrates AI-powered contextual chat and editing capabilities.
• It enables you to reference files from your vault during a chat session.
• It allows users to choose from various AI providers (e.g., OpenAI, Anthropic, and notably, Ollama for local models).
• Main Architectural Areas:
a. Frontend UI Components: Mainly implemented in TypeScript/React under the “src/components” folder (e.g., ChatView, ApplyView, settings modals, and various chat-input plugins).
b. Core AI/LLM Integration: In “src/core/llm”, where multiple provider connectors (including Ollama) and the central LLM manager are implemented.
c. Vault Context & Retrieval (RAG): Found in “src/core/rag”, which handles semantic search across your vault content.
d. Database & Settings: Managed in “src/database” and “src/settings”, including schema migrations and settings context, ensuring that things like your API keys and provider configurations are stored and updated.
e. Build & Migration Tools: The “drizzle” folder holds SQL migration scripts that maintain versioning for vector tables and templates, indicating underlying database support for advanced features.
──────────────────────────────
──────────────────────────────
• Frontend (Obsidian Plugin UI):
– ChatView and ApplyView components (interaction layer for user chats, image uploads, code blocks, and templates).
– Chat input plugins (mention, image handling, typeahead menus, etc.) which provide rich-text editing and context selection.
• Core Logic and Service Layer:
– LLM Manager and Provider Connectors: Include modules for OpenAI, Anthropic, Gemini, and the Ollama connector. Note that the “src/core/llm” folder has dedicated files that establish how requests are sent to external or local providers.
– Context and RAG (Retrieval-Augmented Generation) Engine: Illustrate the interaction with “src/core/rag” which takes note content from your vault and enhances context for AI responses.
• Database and Configuration Modules:
– Database Manager and modules from “src/database” (including JSON and module-specific managers for chat and vector data).
– Settings and schema changes stored in “src/settings” (which also maintains your custom system prompts and API key configurations).
• External Services & Local Hosts:
– External API endpoints provided by services like OpenAI, Anthropic, etc.
– Local model support via Ollama: Show that you have a connector in “src/core/llm/ollama.ts” to send requests and receive responses from a locally hosted AI model.
B. Data Flow & Interactions:
– From UI components (ChatView, settings modals) to the LLM Manager in the Core Logic layer.
– From LLM Manager and RAG engine to the Database Managers for retrieving vault notes and persisting conversation history.
– From LLM Manager to external API endpoints or local services (including your Ollama setup) for processing the AI query.
C. Architectural Patterns & Technologies:
• An MVC-like pattern in the plugin (React components as views, context managers and state hooks as controllers, and underlying database modules as the model).
• Plugin’s extensibility: e.g., support for external file types (images, YouTube transcripts, etc.) and multiple provider integrations.
• Integration of custom prompts and template management as additional modules.
• Build tools/scripting components such as “esbuild”, “drizzle”, or configurations (e.g., tsconfig.json).
──────────────────────────────
How to Use the Project for Chatting with Your Obsidian Notes
──────────────────────────────
• Installation & Setup:
1. Install the Smart Composer plugin via Obsidian’s Community Plugins section.
2. You have the latest Obsidian installer, as noted in the README.
3. Once installed, enable the plugin and navigate to its settings to configure your API key(s) for your preferred provider.
• Chat with Obsidian Notes:
1. Open the Chat view within the plugin interface (e.g., ChatView.tsx).
2. Type queries into the chat input; to include specific context from your vault, use the syntax “@<filenameOrFolder>”. This tells the RAG engine to retrieve and include relevant notes.
3. The plugin will use these selections to adjust the context sent to the chosen LLM (via the methods set up in “src/core/rag” and “src/core/llm”).
──────────────────────────────
How to Connect to Ollama for Local Model Support
──────────────────────────────
• Once selected, follow these steps:
1. You have Ollama installed and configured on your local machine.
2. In the settings, enter the necessary connection details — typically an API endpoint/port that corresponds to your local Ollama installation.
3. The connector code in “src/core/llm/ollama.ts” manages the integration. It sends your queries (with the vault context attached when necessary) to the Ollama service and waits for the AI response.
──────────────────────────────