feat: increase vault context limits and make them configurable
- Replace hardcoded 2000-char context limit with configurable maxContextLength setting (default: 8000 characters) - Increase vaultSearchLimit default from 3 to 5 notes - Add 'Max Context Length' setting to plugin settings UI - Update README with new defaults - Update chat-view tests for new setting
This commit is contained in:
@@ -106,7 +106,8 @@ Open **Settings → Ollama Settings** to configure the plugin.
|
||||
|---------|---------|-------------|
|
||||
| Ollama URL | `http://localhost:11434` | Base URL of your Ollama instance |
|
||||
| Model | `llama3` | Model used for chat responses |
|
||||
| Vault Search Limit | `3` | Maximum number of vault entries to include in context |
|
||||
| Vault Search Limit | `5` | Maximum number of vault entries to include in context |
|
||||
| Max Context Length | `8000` | Maximum characters of vault content sent to the AI per message |
|
||||
| Max Message History | `50` | Maximum number of messages kept in conversation history |
|
||||
| **Enable Vault Semantic Index** | Off | Index vault notes into a vector DB for semantic/RAG search |
|
||||
| Vault Index ChromaDB URL | `http://localhost:8000` | URL of your ChromaDB instance for the vault index |
|
||||
|
||||
@@ -9320,7 +9320,7 @@ var ChatView = class extends import_obsidian3.ItemView {
|
||||
if (!userMessage) {
|
||||
return;
|
||||
}
|
||||
const MAX_CONTEXT_LENGTH = 2e3;
|
||||
const maxContextLength = this.settings.maxContextLength;
|
||||
const tools = this.getTools();
|
||||
const messageId = crypto.randomUUID();
|
||||
const userMessageId = `${messageId}-user`;
|
||||
@@ -9365,7 +9365,7 @@ var ChatView = class extends import_obsidian3.ItemView {
|
||||
parts.push(entry.title);
|
||||
parts.push(entry.content);
|
||||
return parts.join("\n");
|
||||
}).join("\n\n").slice(0, MAX_CONTEXT_LENGTH);
|
||||
}).join("\n\n").slice(0, maxContextLength);
|
||||
const userMessageWithContext = context ? `Relevant vault context:
|
||||
${context}
|
||||
|
||||
@@ -9430,8 +9430,9 @@ var MAX_TOOL_CALLS = 5;
|
||||
var DEFAULT_SETTINGS = {
|
||||
ollamaUrl: "http://localhost:11434",
|
||||
model: "llama3",
|
||||
vaultSearchLimit: 3,
|
||||
vaultSearchLimit: 5,
|
||||
maxMessageHistory: 50,
|
||||
maxContextLength: 8e3,
|
||||
lastIndexTime: 0,
|
||||
cacheConfig: {
|
||||
enabled: false,
|
||||
@@ -10456,7 +10457,7 @@ var OllamaSettingTab = class extends import_obsidian5.PluginSettingTab {
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
new import_obsidian5.Setting(containerEl).setName("Vault Search Limit").setDesc("Maximum number of vault entries to include in context (default: 3)").addText(
|
||||
new import_obsidian5.Setting(containerEl).setName("Vault Search Limit").setDesc("Maximum number of vault entries to include in context (default: 5)").addText(
|
||||
(text) => text.setValue(String(this.plugin.settings.vaultSearchLimit)).onChange(async (value) => {
|
||||
const parsed = parseInt(value);
|
||||
if (!isNaN(parsed) && parsed > 0) {
|
||||
@@ -10467,6 +10468,17 @@ var OllamaSettingTab = class extends import_obsidian5.PluginSettingTab {
|
||||
}
|
||||
})
|
||||
);
|
||||
new import_obsidian5.Setting(containerEl).setName("Max Context Length").setDesc("Maximum characters of vault content to send to the AI per message (default: 8000)").addText(
|
||||
(text) => text.setValue(String(this.plugin.settings.maxContextLength)).onChange(async (value) => {
|
||||
const parsed = parseInt(value);
|
||||
if (!isNaN(parsed) && parsed > 0) {
|
||||
this.plugin.settings.maxContextLength = parsed;
|
||||
await this.plugin.saveSettings();
|
||||
} else {
|
||||
new import_obsidian5.Notice("Max context length must be a positive integer.");
|
||||
}
|
||||
})
|
||||
);
|
||||
new import_obsidian5.Setting(containerEl).setName("Max Message History").setDesc("Maximum number of messages to keep in conversation history (default: 50)").addText(
|
||||
(text) => text.setValue(String(this.plugin.settings.maxMessageHistory)).onChange(async (value) => {
|
||||
const parsed = parseInt(value);
|
||||
|
||||
+2
-2
@@ -434,7 +434,7 @@ export class ChatView extends ItemView {
|
||||
return;
|
||||
}
|
||||
|
||||
const MAX_CONTEXT_LENGTH = 2000;
|
||||
const maxContextLength = this.settings.maxContextLength;
|
||||
const tools = this.getTools();
|
||||
const messageId = crypto.randomUUID();
|
||||
const userMessageId = `${messageId}-user`;
|
||||
@@ -490,7 +490,7 @@ export class ChatView extends ItemView {
|
||||
return parts.join('\n');
|
||||
})
|
||||
.join('\n\n')
|
||||
.slice(0, MAX_CONTEXT_LENGTH);
|
||||
.slice(0, maxContextLength);
|
||||
const userMessageWithContext = context
|
||||
? `Relevant vault context:\n${context}\n\nUser question:\n${userMessage}`
|
||||
: userMessage;
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
export const DEFAULT_SETTINGS = {
|
||||
ollamaUrl: 'http://localhost:11434',
|
||||
model: 'llama3',
|
||||
vaultSearchLimit: 3,
|
||||
vaultSearchLimit: 5,
|
||||
maxMessageHistory: 50,
|
||||
maxContextLength: 8000,
|
||||
lastIndexTime: 0,
|
||||
cacheConfig: {
|
||||
enabled: false,
|
||||
|
||||
+16
-1
@@ -400,7 +400,7 @@ class OllamaSettingTab extends PluginSettingTab {
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Vault Search Limit')
|
||||
.setDesc('Maximum number of vault entries to include in context (default: 3)')
|
||||
.setDesc('Maximum number of vault entries to include in context (default: 5)')
|
||||
.addText((text) =>
|
||||
text.setValue(String(this.plugin.settings.vaultSearchLimit)).onChange(async (value) => {
|
||||
const parsed = parseInt(value);
|
||||
@@ -413,6 +413,21 @@ class OllamaSettingTab extends PluginSettingTab {
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Max Context Length')
|
||||
.setDesc('Maximum characters of vault content to send to the AI per message (default: 8000)')
|
||||
.addText((text) =>
|
||||
text.setValue(String(this.plugin.settings.maxContextLength)).onChange(async (value) => {
|
||||
const parsed = parseInt(value);
|
||||
if (!isNaN(parsed) && parsed > 0) {
|
||||
this.plugin.settings.maxContextLength = parsed;
|
||||
await this.plugin.saveSettings();
|
||||
} else {
|
||||
new Notice('Max context length must be a positive integer.');
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Max Message History')
|
||||
.setDesc('Maximum number of messages to keep in conversation history (default: 50)')
|
||||
|
||||
@@ -190,6 +190,7 @@ export interface PluginSettings {
|
||||
model: string;
|
||||
vaultSearchLimit: number;
|
||||
maxMessageHistory: number;
|
||||
maxContextLength: number;
|
||||
lastIndexTime: number;
|
||||
cacheConfig: CacheConfig;
|
||||
vaultIndexConfig: VaultIndexConfig;
|
||||
|
||||
@@ -31,6 +31,7 @@ const mockSettings: PluginSettings = {
|
||||
model: 'llama3',
|
||||
vaultSearchLimit: 3,
|
||||
maxMessageHistory: 50,
|
||||
maxContextLength: 8000,
|
||||
lastIndexTime: 0,
|
||||
cacheConfig: {
|
||||
enabled: false,
|
||||
|
||||
Reference in New Issue
Block a user