From f09e1349485ebf42ec4f0083673c6271f5a6cbc2 Mon Sep 17 00:00:00 2001 From: Florian Egger Date: Wed, 20 May 2026 01:13:40 +0200 Subject: [PATCH] fix: include tags in vault context sent to AI and update system prompt - chat-view.ts: include 'Tags: ...' prefix in vault context when tags exist - chat-view.ts: update system prompt to instruct AI to pay attention to tags when organizing or categorizing notes --- main.js | 13 +++++++++++-- src/chat-view.ts | 12 +++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index f459c28..890f3b3 100644 --- a/main.js +++ b/main.js @@ -9260,6 +9260,8 @@ var ChatView = class extends import_obsidian3.ItemView { buildMessages(userMessageContent, tools) { const systemContent = `You are an assistant that can help answer questions using the contents of a vault. The user can ask questions about their vault contents, and you should provide helpful responses based on the files. + Vault context includes note titles, content, and any tags (shown as "Tags: ..." at the top of a note entry). + When organizing or categorizing notes, pay attention to tags as they reflect the note's topics and categories. When a user asks for information, try to find relevant files using the search_vault_files tool and read their contents with the read_vault_file tool. Only use the tools if you need to access vault content that is not already in the context.`; const systemMessage = { @@ -9355,8 +9357,15 @@ var ChatView = class extends import_obsidian3.ItemView { userMessage, this.settings.vaultSearchLimit ); - const context = entries.map((entry) => `${entry.title} -${entry.content}`).join("\n\n").slice(0, MAX_CONTEXT_LENGTH); + const context = entries.map((entry) => { + const parts = []; + if (entry.tags) { + parts.push(`Tags: ${entry.tags}`); + } + parts.push(entry.title); + parts.push(entry.content); + return parts.join("\n"); + }).join("\n\n").slice(0, MAX_CONTEXT_LENGTH); const userMessageWithContext = context ? `Relevant vault context: ${context} diff --git a/src/chat-view.ts b/src/chat-view.ts index f06c159..7d65b71 100755 --- a/src/chat-view.ts +++ b/src/chat-view.ts @@ -356,6 +356,8 @@ export class ChatView extends ItemView { buildMessages(userMessageContent: string, tools?: OllamaTool[]): OllamaMessage[] { const systemContent = `You are an assistant that can help answer questions using the contents of a vault. The user can ask questions about their vault contents, and you should provide helpful responses based on the files. + Vault context includes note titles, content, and any tags (shown as "Tags: ..." at the top of a note entry). + When organizing or categorizing notes, pay attention to tags as they reflect the note's topics and categories. When a user asks for information, try to find relevant files using the search_vault_files tool and read their contents with the read_vault_file tool. Only use the tools if you need to access vault content that is not already in the context.`; const systemMessage: OllamaMessage = { @@ -478,7 +480,15 @@ export class ChatView extends ItemView { this.settings.vaultSearchLimit ); const context = entries - .map((entry) => `${entry.title}\n${entry.content}`) + .map((entry) => { + const parts: string[] = []; + if (entry.tags) { + parts.push(`Tags: ${entry.tags}`); + } + parts.push(entry.title); + parts.push(entry.content); + return parts.join('\n'); + }) .join('\n\n') .slice(0, MAX_CONTEXT_LENGTH); const userMessageWithContext = context