feat: Add vault context system for AI responses with file selection UI#252
feat: Add vault context system for AI responses with file selection UI#252SKYLXN wants to merge 2 commits intoeharris128:mainfrom
Conversation
This PR adds a comprehensive context system that allows the AI to access Obsidian vault files when generating responses. Features Added: - Vault context injection: AI can now access file content from your vault - Automatic context: Include active file and selected text automatically - Manual file selection: UI to select specific files to include in context - Token budget management: Percentage-based allocation (default 70% context, 30% response) - Context persistence: Selected files and context saved in conversation history - Structured format: Context sent as formatted markdown with clear sections New Components: - ContextBuilder service: Handles context collection, formatting, and truncation - FileSelector modal: Searchable UI for selecting vault files - Context Settings UI: Configure context options per view (modal/widget/fab) AI Model Updates: - Added support for 10 new Gemini models (2.0, 2.5, 3.0 series) - Fixed streaming response handling for Gemini and Claude - Added 'thinking' animation during AI generation - Improved token limit defaults (300 -> 8192 for better responses) Technical Changes: - Extended ViewSettings and ChatHistoryItem types with context support - Context injected as first user message in conversation - Truncation uses 1 token ≈ 4 chars estimation - All file types supported (including images via base64) This feature enables more contextual AI responses by providing relevant vault content automatically or through manual selection.
|
Hi there - I am so sorry for the massive delay. I must have missed the notification for this pull request. I will give it a test tomorrow & look to get a release out ASAP if everything looks good. Thank you so much for the contribution @SKYLXN |
|
Thank you so much for this pull request. I really like the initial proof of concept. I am going to rope in the designer & product owner for this project @jsmorabito so he can give it a pass through. One technical bit that I cleaned up on my local testing of the branch was using Likely the further extension of this idea is to default max token count to a number that fits to the respective model...
|
|
Hi @eharris128! Thanks for the feedback and for testing it out. No worries at all about the delay! I agree that implementing dynamic token defaults based on the selected model would be the ideal next step to fully leverage models with larger context windows without breaking older ones. I'll wait for @jsmorabito's feedback on the UI/UX side. Happy to make adjustments if needed :) |
|
Hey @SKYLXN , thank you so much for this PR. I've tested it out and the functionality is very exciting to see! I have only one requested change prior to merging: Please add a toggle to our plugin settings menu to enable/disable the file context feature and set it to
|
- Add enableFileContext boolean to plugin settings (disabled by default) - Add 'Enable File Context' toggle in settings UI below 'Toggle FAB' - Update ChatContainer to check if feature is enabled before building context - Addresses feedback from @jsmorabito to make feature opt-in
|
Hey @jsmorabito! Thanks for the feedback and for testing the PR. I completely understand the need for UX/UI refinements before making this a core feature. I've implemented the requested change, the implementation includes:
|



Add Vault Context System for AI Responses
Overview
This PR adds a comprehensive context system that allows AI models to access Obsidian vault files when generating responses, enabling more contextual and relevant interactions.
Problem Solved
Previously, the AI had no access to vault files, limiting its ability to provide context-aware responses based on your notes. This feature addresses the core request: "l'IA n'a pas accès aux fichiers d'Obsidian, il faut lui rajouter les fichiers pour le contexte!"
Features Added
🎯 Automatic Context Injection
📁 Manual File Selection
⚙️ Token Budget Management
💾 Context Persistence
📝 Structured Format
Context is sent to AI as clean, structured markdown:
New Components
ContextBuilderService (src/services/ContextBuilder.ts)buildContext(): Collects vault context based on settingsformatStructuredContext(): Formats context as structured markdowntruncateToTokenLimit(): Intelligently truncates to fit token budgetbuildFormattedContext(): Complete pipeline from settings to formatted contextcalculateContextTokenBudget(): Computes token allocationFileSelectorModal (src/Plugin/Components/FileSelector.ts)Context Settings UI
Added to
SettingsContainer.ts:AI Model Updates
New Gemini Models Supported (10 models added)
gemini-2.0-flash-exp- Experimental Flash 2.0gemini-2.0-flash-thinking-exp-1219- Thinking modegemini-2.0-flash- Stable Flash 2.0gemini-2.0-flash-lite- Lightweight versiongemini-2.5-pro- Pro tier 2.5gemini-2.5-flash- Flash 2.5gemini-2.5-flash-lite- Lite 2.5gemini-3-pro-preview- Preview of Gemini 3gemini-flash-latest- Latest Flashgemini-flash-lite-latest- Latest LiteImproved Streaming Responses
Technical Changes
Type System Extensions
types.ts:Integration Flow
ChatContainer.handleGenerateClick()ContextBuilder.buildFormattedContext()historyPush(params, vaultContext)Settings Management
defaultSettingsinmain.tsFiles Modified
Core Files (5)
src/main.ts- Added contextSettings to defaultSettings, Gemini model validationsrc/Types/types.ts- Added ContextSettings and VaultContext typessrc/utils/utils.ts- Fixed getViewInfo to include contextSettingssrc/utils/constants.ts- Added 10 new Gemini model constantssrc/utils/models.ts- Added model definitions for new Gemini modelsComponent Files (2)
src/Plugin/Components/ChatContainer.ts- Context building and injection logicsrc/Plugin/Components/SettingsContainer.ts- Context settings UINew Files (2)
src/services/ContextBuilder.ts- Context servicesrc/Plugin/Components/FileSelector.ts- File selection modalStyling (1)
styles.css- Added thinking animation CSSDependencies (1)
package-lock.json- Version bump to 0.19.19Testing Recommendations
Basic Context Testing
Selected Text Testing
Manual File Selection
Token Budget Testing
History Persistence
Breaking Changes
None - all changes are additive and backward compatible.
Migration Notes
Performance Considerations
Future Enhancements
Credits
Developed in response to user request for vault file access in AI conversations.
Related Issues
Closes: (insert issue number if applicable)
Ready for review! Please test with various vault sizes and file types.