Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat: use cloud semantic search in agent search_notes tool

Gabriel Stein500c6f91ac5d
diff --git a/src/components/AgentOverlay.tsx b/src/components/AgentOverlay.tsx
index a3975f101..f6a3dfe4d 100644
--- a/src/components/AgentOverlay.tsx
+++ b/src/components/AgentOverlay.tsx
@@ -115,6 +115,7 @@ export default function AgentOverlay() {
? createToolRegistry({
isSignedIn: settings.isSignedIn,
gcalConnected: settings.gcalConnected,
+ cloudBackupEnabled: settings.cloudBackupEnabled,
})
: null;
const systemPrompt = getAgentSystemPrompt(registry?.getAll().map((t) => t.name));
diff --git a/src/services/tools/index.ts b/src/services/tools/index.ts
index d45d10f35..35552f94a 100644
--- a/src/services/tools/index.ts
+++ b/src/services/tools/index.ts
@@ -1,5 +1,5 @@
import { ToolRegistry } from "./ToolRegistry";
-import { searchNotesTool } from "./searchNotesTool";
+import { createSearchNotesTool } from "./searchNotesTool";
import { getNoteTool } from "./getNoteTool";
import { createNoteTool } from "./createNoteTool";
import { updateNoteTool } from "./updateNoteTool";
@@ -13,12 +13,14 @@ export type { ToolDefinition, ToolResult } from "./ToolRegistry";
interface ToolRegistrySettings {
isSignedIn: boolean;
gcalConnected: boolean;
+ cloudBackupEnabled: boolean;
}
export function createToolRegistry(settings: ToolRegistrySettings): ToolRegistry {
const registry = new ToolRegistry();
- registry.register(searchNotesTool);
+ const useCloudSearch = settings.isSignedIn && settings.cloudBackupEnabled;
+ registry.register(createSearchNotesTool({ useCloudSearch }));
registry.register(getNoteTool);
registry.register(createNoteTool);
registry.register(updateNoteTool);
diff --git a/src/services/tools/searchNotesTool.ts b/src/services/tools/searchNotesTool.ts
index 2e8f1bae4..70e7e1539 100644
--- a/src/services/tools/searchNotesTool.ts
+++ b/src/services/tools/searchNotesTool.ts
@@ -2,61 +2,112 @@ import type { ToolDefinition, ToolResult } from "./ToolRegistry";
const MAX_CONTENT_LENGTH = 500;
-export const searchNotesTool: ToolDefinition = {
- name: "search_notes",
- description:
- "Search the user's notes by keyword or phrase. Returns matching notes with title, date, and a preview of content.",
- parameters: {
- type: "object",
- properties: {
- query: {
- type: "string",
- description: "The search query to find relevant notes",
- },
- limit: {
- type: "number",
- description: "Maximum number of results to return (default 5)",
+interface SearchToolOptions {
+ useCloudSearch: boolean;
+}
+
+export function createSearchNotesTool(options: SearchToolOptions): ToolDefinition {
+ const { useCloudSearch } = options;
+
+ return {
+ name: "search_notes",
+ description: useCloudSearch
+ ? "Search the user's notes using semantic search. Understands meaning and context, not just keywords. Returns matching notes with title, date, relevance score, and a preview of content."
+ : "Search the user's notes by keyword or phrase. Returns matching notes with title, date, and a preview of content.",
+ parameters: {
+ type: "object",
+ properties: {
+ query: {
+ type: "string",
+ description: "The search query to find relevant notes",
+ },
+ limit: {
+ type: "number",
+ description: "Maximum number of results to return (default 5)",
+ },
},
+ required: ["query"],
+ additionalProperties: false,
},
- required: ["query"],
- additionalProperties: false,
- },
- readOnly: true,
+ readOnly: true,
- async execute(args: Record<string, unknown>): Promise<ToolResult> {
- const query = args.query as string;
- const limit = typeof args.limit === "number" ? args.limit : 5;
+ async execute(args: Record<string, unknown>): Promise<ToolResult> {
+ const query = args.query as string;
+ const limit = typeof args.limit === "number" ? args.limit : 5;
- try {
- const notes = await window.electronAPI.searchNotes(query, limit);
-
- if (notes.length === 0) {
+ try {
+ if (useCloudSearch) {
+ return await executeCloudSearch(query, limit);
+ }
+ return await executeLocalSearch(query, limit);
+ } catch (error) {
+ if (useCloudSearch) {
+ try {
+ return await executeLocalSearch(query, limit);
+ } catch {
+ // Both failed
+ }
+ }
return {
- success: true,
- data: [],
- displayText: `No notes found for "${query}"`,
+ success: false,
+ data: null,
+ displayText: `Failed to search notes: ${(error as Error).message}`,
};
}
+ },
+ };
+}
+
+async function executeLocalSearch(query: string, limit: number): Promise<ToolResult> {
+ const notes = await window.electronAPI.searchNotes(query, limit);
+
+ if (notes.length === 0) {
+ return {
+ success: true,
+ data: [],
+ displayText: `No notes found for "${query}"`,
+ };
+ }
+
+ const results = notes.map((note) => ({
+ id: note.id,
+ title: note.title,
+ date: note.created_at,
+ type: note.note_type,
+ content: (note.enhanced_content || note.content).slice(0, MAX_CONTENT_LENGTH),
+ }));
+
+ return {
+ success: true,
+ data: results,
+ displayText: `Found ${results.length} note${results.length === 1 ? "" : "s"} for "${query}"`,
+ };
+}
+
+async function executeCloudSearch(query: string, limit: number): Promise<ToolResult> {
+ const { NotesService } = await import("../../services/NotesService.js");
+ const { notes: cloudNotes } = await NotesService.search(query, limit);
+
+ if (cloudNotes.length === 0) {
+ return {
+ success: true,
+ data: [],
+ displayText: `No notes found for "${query}"`,
+ };
+ }
+
+ const results = cloudNotes.map((cn) => ({
+ id: cn.client_note_id ? parseInt(cn.client_note_id, 10) : null,
+ title: cn.title,
+ date: cn.created_at,
+ type: cn.note_type,
+ score: cn.score,
+ content: (cn.enhanced_content || cn.content).slice(0, MAX_CONTENT_LENGTH),
+ }));
- const results = notes.map((note) => ({
- id: note.id,
- title: note.title,
- date: note.created_at,
- type: note.note_type,
- content: (note.enhanced_content || note.content).slice(0, MAX_CONTENT_LENGTH),
- }));
-
- return {
- success: true,
- data: results,
- displayText: `Found ${results.length} note${results.length === 1 ? "" : "s"} for "${query}"`,
- };
- } catch (error) {
- return {
- success: false,
- data: null,
- displayText: `Failed to search notes: ${(error as Error).message}`,
- };
- }
- },
-};
+ return {
+ success: true,
+ data: results,
+ displayText: `Found ${results.length} note${results.length === 1 ? "" : "s"} for "${query}" (semantic search)`,
+ };
+}