andy-stack_vaultkeeper-ai/AIClasses/FunctionDefinitions/Functions/SearchVaultFiles.ts
Andrew Beal d58e9ef1ff refactor: enhance vault search to return content snippets with context
- Update SearchVaultFiles function to return contextual snippets instead of just file lists
- Implement snippet extraction with configurable context length (300 chars)
- Add snippet merging logic to consolidate overlapping matches
- Limit results to 20 randomly sampled matches when exceeding threshold
- Update return types across service layer to use SearchMatch/SearchSnippet
- Change regex flags to 'ig' for global case-insensitive matching
2025-10-14 19:50:45 +01:00

26 lines
No EOL
1.3 KiB
TypeScript

import { AIFunction } from "Enums/AIFunction";
import type { IAIFunctionDefinition } from "../IAIFunctionDefinition";
export const SearchVaultFiles: IAIFunctionDefinition = {
name: AIFunction.SearchVaultFiles,
description: `Searches through all files in the user's Obsidian vault for the given search term.
Uses regex pattern matching to search file content.
Returns matching vault files with metadata (names, paths) and contextual snippets showing matched content with surrounding text to enable relevance assessment.
Call this whenever you need to know what files exist in the vault to answer questions,
verify file presence, or to perform further agentic functions.
Use proactively when vault contents would inform your response.`,
parameters: {
type: "object",
properties: {
search_term: {
type: "string",
description: "The regex pattern to search for in vault files. Supports both simple text (e.g., 'todo') and regex patterns (e.g., '(urgent|important)'). The search is performed on both file names and content."
},
user_message: {
type: "string",
description: "A short message to be displayed to the user that explains the action being taken"
}
},
required: ["search_term", "user_message"]
}
}