Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat: add local semantic search via Qdrant sidecar
Gabriel Stein67e52ffa39f4
diff --git a/main.js b/main.jsindex e7a5f2fd1..0a1fe4281 100644--- a/main.js+++ b/main.js@@ -210,6 +210,7 @@ let whisperCudaManager = null;let googleCalendarManager = null;let meetingDetectionEngine = null;let audioTapManager = null;+let qdrantManager = null;let ipcHandlers = null;let globeKeyAlertShown = false;let authBridgeServer = null;@@ -665,6 +666,23 @@ async function startApp() {});}+ if (process.env.LOCAL_SEMANTIC_SEARCH === "true") {+ const QdrantManager = require("./src/helpers/qdrantManager");+ qdrantManager = new QdrantManager();+ ipcHandlers.qdrantManager = qdrantManager;+ qdrantManager.start().then(() => {+ if (qdrantManager.isReady()) {+ const vectorIndex = require("./src/helpers/vectorIndex");+ vectorIndex.init(qdrantManager.getPort());+ vectorIndex.ensureCollection().catch((err) => {+ debugLogger.debug("Qdrant collection setup error (non-fatal)", { error: err.message });+ });+ }+ }).catch((err) => {+ debugLogger.debug("Qdrant startup error (non-fatal)", { error: err.message });+ });+ }+if (process.platform === "win32") {const nircmdStatus = clipboardManager.getNircmdStatus();debugLogger.debug("Windows paste tool status", nircmdStatus);@@ -1145,5 +1163,10 @@ if (gotSingleInstanceLock) {// Stop llama-server if runningconst modelManager = require("./src/helpers/modelManagerBridge").default;modelManager.stopServer().catch(() => {});+ if (qdrantManager) {+ qdrantManager.stop().catch(() => {});+ } else if (ipcHandlers?.qdrantManager) {+ ipcHandlers.qdrantManager.stop().catch(() => {});+ }});}diff --git a/package.json b/package.jsonindex a3701ca25..212906375 100644--- a/package.json+++ b/package.json@@ -25,26 +25,26 @@"predev:main": "npm run compile:native","dev:main": "cross-env NODE_ENV=development node scripts/run-electron.js --dev","dev:renderer": "cd src && vite",- "prebuild": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx",+ "prebuild": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant","build": "cd src && vite build && cd .. && electron-builder","postinstall": "electron-builder install-app-deps","build:renderer": "cd src && vite build",- "prebuild:mac": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx",+ "prebuild:mac": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant","build:mac": "npm run build:renderer && electron-builder --mac","build:mac:arm64": "npm run build:renderer && electron-builder --mac --arm64","build:mac:x64": "npm run build:renderer && electron-builder --mac --x64",- "prebuild:win": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:nircmd && npm run download:windows-fast-paste && npm run download:windows-key-listener && npm run download:windows-mic-listener",+ "prebuild:win": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant && npm run download:nircmd && npm run download:windows-fast-paste && npm run download:windows-key-listener && npm run download:windows-mic-listener","build:win": "npm run build:renderer && electron-builder --win",- "prebuild:linux": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx",+ "prebuild:linux": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant","build:linux": "npm run build:renderer && electron-builder --linux","build:linux:appimage": "npm run build:renderer && electron-builder --linux AppImage","build:linux:deb": "npm run build:renderer && electron-builder --linux deb","build:linux:rpm": "npm run build:renderer && electron-builder --linux rpm","build:linux:tar": "npm run build:renderer && electron-builder --linux tar.gz","setup": "node setup.js",- "prepack": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx",+ "prepack": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant","pack": "npm run build:renderer && cross-env CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --dir",- "predist": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx",+ "predist": "npm run compile:native && npm run download:whisper-cpp && npm run download:llama-server && npm run download:sherpa-onnx && npm run download:qdrant","dist": "npm run build:renderer && electron-builder","download:whisper-cpp": "node scripts/download-whisper-cpp.js --current","download:whisper-cpp:all": "node scripts/download-whisper-cpp.js --all",@@ -56,6 +56,9 @@"download:windows-fast-paste": "node scripts/download-windows-fast-paste.js","download:windows-key-listener": "node scripts/download-windows-key-listener.js","download:windows-mic-listener": "node scripts/download-windows-mic-listener.js",+ "download:qdrant": "node scripts/download-qdrant.js --current",+ "download:qdrant:all": "node scripts/download-qdrant.js --all",+ "download:embedding-model": "node scripts/download-minilm.js","format:js": "eslint . --fix && cd src && eslint . --fix && prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"","format": "npm run format:js","format:check": "eslint . && cd src && eslint . && prettier --check \"**/*.{js,jsx,ts,tsx,json,css,md}\"",@@ -107,6 +110,7 @@"@ai-sdk/google": "^3.0.43","@ai-sdk/groq": "^3.0.29","@ai-sdk/openai": "^3.0.41",+ "@qdrant/js-client-rest": "^1.12.0","@neondatabase/auth": "^0.1.0-beta.21","@neondatabase/neon-js": "^0.1.0-beta.22","@radix-ui/react-accordion": "^1.1.2",@@ -135,6 +139,7 @@"i18next": "^25.8.4","lucide-react": "^0.518.0","object-assign": "^4.1.1",+ "onnxruntime-node": "^1.21.0","ps-list": "^9.0.0","react": "^19.1.0","react-dom": "^19.1.0",diff --git a/preload.js b/preload.jsindex 31f07eb82..3289b4e5a 100644--- a/preload.js+++ b/preload.js@@ -85,6 +85,15 @@ contextBridge.exposeInMainWorld("electronAPI", {deleteNote: (id) => ipcRenderer.invoke("db-delete-note", id),exportNote: (noteId, format) => ipcRenderer.invoke("export-note", noteId, format),searchNotes: (query, limit) => ipcRenderer.invoke("db-search-notes", query, limit),+ semanticSearchNotes: (query, limit) => ipcRenderer.invoke("db-semantic-search-notes", query, limit),+ semanticReindexAll: () => ipcRenderer.invoke("db-semantic-reindex-all"),+ onSemanticReindexProgress: (callback) => {+ const listener = (_event, data) => callback?.(data);+ ipcRenderer.on("semantic-reindex-progress", listener);+ return () => ipcRenderer.removeListener("semantic-reindex-progress", listener);+ },+ enableSemanticSearch: () => ipcRenderer.invoke("semantic-search-enable"),+ disableSemanticSearch: () => ipcRenderer.invoke("semantic-search-disable"),updateNoteCloudId: (id, cloudId) => ipcRenderer.invoke("db-update-note-cloud-id", id, cloudId),// Folder functionsdiff --git a/scripts/download-minilm.js b/scripts/download-minilm.jsnew file mode 100644index 000000000..270ba15cd--- /dev/null+++ b/scripts/download-minilm.js@@ -0,0 +1,65 @@+#!/usr/bin/env node+const fs = require("fs");+const os = require("os");+const path = require("path");+const { downloadFile, parseArgs } = require("./lib/download-utils");++const MODEL_DIR = path.join(+ os.homedir(),+ ".cache",+ "openwhispr",+ "embedding-models",+ "all-MiniLM-L6-v2"+);++const FILES = [+ {+ name: "model.onnx",+ url: "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/onnx/model.onnx",+ },+ {+ name: "tokenizer.json",+ url: "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/tokenizer.json",+ },+];++async function main() {+ console.log("\n[embedding-model] Downloading all-MiniLM-L6-v2 ONNX model...\n");++ const args = parseArgs();++ const allExist = FILES.every((f) => fs.existsSync(path.join(MODEL_DIR, f.name)));+ if (allExist && !args.isForce) {+ console.log("[embedding-model] Model files already exist (use --force to re-download)\n");+ return;+ }++ fs.mkdirSync(MODEL_DIR, { recursive: true });++ for (const file of FILES) {+ const destPath = path.join(MODEL_DIR, file.name);++ if (fs.existsSync(destPath) && !args.isForce) {+ console.log(`[embedding-model] ${file.name} already exists, skipping`);+ continue;+ }++ console.log(`[embedding-model] Downloading ${file.name} from ${file.url}`);++ try {+ await downloadFile(file.url, destPath);+ const stats = fs.statSync(destPath);+ const sizeMB = (stats.size / 1024 / 1024).toFixed(1);+ console.log(`[embedding-model] ${file.name} downloaded (${sizeMB}MB)`);+ } catch (error) {+ console.error(`[embedding-model] Failed to download ${file.name}: ${error.message}`);+ if (fs.existsSync(destPath)) fs.unlinkSync(destPath);+ process.exitCode = 1;+ return;+ }+ }++ console.log(`\n[embedding-model] Model ready at ${MODEL_DIR}\n`);+}++main().catch(console.error);diff --git a/scripts/download-qdrant.js b/scripts/download-qdrant.jsnew file mode 100644index 000000000..308645bf7--- /dev/null+++ b/scripts/download-qdrant.js@@ -0,0 +1,180 @@+#!/usr/bin/env node+const fs = require("fs");+const path = require("path");+const {+ downloadFile,+ extractArchive,+ fetchLatestRelease,+ findBinaryInDir,+ parseArgs,+ setExecutable,+ cleanupFiles,+} = require("./lib/download-utils");++const QDRANT_REPO = "qdrant/qdrant";++// Version can be pinned via environment variable for reproducible builds+const VERSION_OVERRIDE = process.env.QDRANT_VERSION || null;++const BINARIES = {+ "darwin-arm64": {+ archiveName: "qdrant-aarch64-apple-darwin.tar.gz",+ binaryName: "qdrant",+ outputName: "qdrant-darwin-arm64",+ },+ "darwin-x64": {+ archiveName: "qdrant-x86_64-apple-darwin.tar.gz",+ binaryName: "qdrant",+ outputName: "qdrant-darwin-x64",+ },+ "linux-x64": {+ archiveName: "qdrant-x86_64-unknown-linux-gnu.tar.gz",+ binaryName: "qdrant",+ outputName: "qdrant-linux-x64",+ },+ "win32-x64": {+ archiveName: "qdrant-x86_64-pc-windows-msvc.zip",+ binaryName: "qdrant.exe",+ outputName: "qdrant-win32-x64.exe",+ },+};++const BIN_DIR = path.join(__dirname, "..", "resources", "bin");++// Cache the release info to avoid multiple API calls+let cachedRelease = null;++async function getRelease() {+ if (cachedRelease) return cachedRelease;++ if (VERSION_OVERRIDE) {+ cachedRelease = await fetchLatestRelease(QDRANT_REPO, { tagPrefix: VERSION_OVERRIDE });+ } else {+ cachedRelease = await fetchLatestRelease(QDRANT_REPO);+ }+ return cachedRelease;+}++function getDownloadUrl(release, archiveName) {+ const asset = release?.assets?.find((a) => a.name === archiveName);+ return asset?.url || null;+}++async function downloadBinary(platformArch, config, release, isForce = false) {+ if (!config) {+ console.log(` [qdrant] ${platformArch}: Not supported`);+ return false;+ }++ const outputPath = path.join(BIN_DIR, config.outputName);++ if (fs.existsSync(outputPath) && !isForce) {+ console.log(` [qdrant] ${platformArch}: Already exists (use --force to re-download)`);+ return true;+ }++ const url = getDownloadUrl(release, config.archiveName);+ if (!url) {+ console.error(` [qdrant] ${platformArch}: Asset ${config.archiveName} not found in release`);+ return false;+ }+ console.log(` [qdrant] ${platformArch}: Downloading from ${url}`);++ const archivePath = path.join(BIN_DIR, config.archiveName);++ try {+ await downloadFile(url, archivePath);++ const extractDir = path.join(BIN_DIR, `temp-qdrant-${platformArch}`);+ fs.mkdirSync(extractDir, { recursive: true });+ await extractArchive(archivePath, extractDir);++ const binaryPath = findBinaryInDir(extractDir, config.binaryName);+ if (binaryPath) {+ fs.copyFileSync(binaryPath, outputPath);+ setExecutable(outputPath);+ console.log(` [qdrant] ${platformArch}: Extracted to ${config.outputName}`);+ } else {+ console.error(+ ` [qdrant] ${platformArch}: Binary "${config.binaryName}" not found in archive`+ );+ return false;+ }++ fs.rmSync(extractDir, { recursive: true, force: true });+ if (fs.existsSync(archivePath)) fs.unlinkSync(archivePath);+ return true;+ } catch (error) {+ console.error(` [qdrant] ${platformArch}: Failed - ${error.message}`);+ if (fs.existsSync(archivePath)) fs.unlinkSync(archivePath);+ return false;+ }+}++async function main() {+ if (VERSION_OVERRIDE) {+ console.log(`\n[qdrant] Using pinned version: ${VERSION_OVERRIDE}`);+ } else {+ console.log("\n[qdrant] Fetching latest release...");+ }+ const release = await getRelease();++ if (!release) {+ console.error(`[qdrant] Could not fetch release from ${QDRANT_REPO}`);+ console.log(`\nMake sure release exists: https://github.com/${QDRANT_REPO}/releases`);+ process.exitCode = 1;+ return;+ }++ console.log(`\nDownloading qdrant binaries (${release.tag})...\n`);++ fs.mkdirSync(BIN_DIR, { recursive: true });++ const args = parseArgs();++ if (args.isCurrent) {+ if (!BINARIES[args.platformArch]) {+ console.error(`Unsupported platform/arch: ${args.platformArch}`);+ process.exitCode = 1;+ return;+ }++ console.log(`Downloading for target platform (${args.platformArch}):`);+ const ok = await downloadBinary(+ args.platformArch,+ BINARIES[args.platformArch],+ release,+ args.isForce+ );+ if (!ok) {+ console.error(`Failed to download binaries for ${args.platformArch}`);+ process.exitCode = 1;+ return;+ }++ if (args.shouldCleanup) {+ cleanupFiles(BIN_DIR, "qdrant", `qdrant-${args.platformArch}`);+ }+ } else {+ console.log("Downloading binaries for all platforms:");+ for (const platformArch of Object.keys(BINARIES)) {+ await downloadBinary(platformArch, BINARIES[platformArch], release, args.isForce);+ }+ }++ console.log("\n---");++ const files = fs.readdirSync(BIN_DIR).filter((f) => f.startsWith("qdrant"));+ if (files.length > 0) {+ console.log("Available qdrant binaries:\n");+ files.forEach((f) => {+ const stats = fs.statSync(path.join(BIN_DIR, f));+ console.log(` - ${f} (${Math.round(stats.size / 1024 / 1024)}MB)`);+ });+ } else {+ console.log("No binaries downloaded yet.");+ console.log(`\nMake sure release exists: https://github.com/${QDRANT_REPO}/releases`);+ }+}++main().catch(console.error);diff --git a/src/components/AgentOverlay.tsx b/src/components/AgentOverlay.tsxindex 938587fba..17011abe3 100644--- a/src/components/AgentOverlay.tsx+++ b/src/components/AgentOverlay.tsx@@ -103,7 +103,7 @@ export default function AgentOverlay() {let registry: ToolRegistry | null = null;if (supportsTools) {- const cacheKey = `${settings.isSignedIn}-${settings.gcalConnected}-${settings.cloudBackupEnabled}`;+ const cacheKey = `${settings.isSignedIn}-${settings.gcalConnected}-${settings.cloudBackupEnabled}-${settings.localSemanticSearchEnabled}`;if (toolRegistryRef.current?.key === cacheKey) {registry = toolRegistryRef.current.registry;} else {@@ -111,6 +111,7 @@ export default function AgentOverlay() {isSignedIn: settings.isSignedIn,gcalConnected: settings.gcalConnected,cloudBackupEnabled: settings.cloudBackupEnabled,+ localSemanticSearchEnabled: settings.localSemanticSearchEnabled,});toolRegistryRef.current = { key: cacheKey, registry };}diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 4a06bb1f9..4b6cb277f 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -707,6 +707,8 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPagesetPanelStartPosition,cloudBackupEnabled,setCloudBackupEnabled,+ localSemanticSearchEnabled,+ setLocalSemanticSearchEnabled,telemetryEnabled,setTelemetryEnabled,audioRetentionDays,@@ -3230,6 +3232,27 @@ EOF`,<Toggle checked={telemetryEnabled} onChange={setTelemetryEnabled} /></SettingsRow></SettingsPanelRow>+ <SettingsPanelRow>+ <SettingsRow+ label={t("settingsPage.privacy.localSemanticSearch")}+ description={t("settingsPage.privacy.localSemanticSearchDescription")}+ >+ <Toggle+ checked={localSemanticSearchEnabled}+ onChange={(v) => {+ setLocalSemanticSearchEnabled(v);+ if (v) {+ window.electronAPI+ .enableSemanticSearch?.()+ .then(() => window.electronAPI.semanticReindexAll?.())+ .catch(console.error);+ } else {+ window.electronAPI.disableSemanticSearch?.().catch(console.error);+ }+ }}+ />+ </SettingsRow>+ </SettingsPanelRow></SettingsPanel></div>diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex e940220f1..97725d29d 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -104,6 +104,7 @@ class IPCHandlers {this.googleCalendarManager = managers.googleCalendarManager;this.meetingDetectionEngine = managers.meetingDetectionEngine;this.audioTapManager = managers.audioTapManager;+ this.qdrantManager = managers.qdrantManager;this.sessionId = crypto.randomUUID();this.assemblyAiStreaming = null;this.deepgramStreaming = null;@@ -128,6 +129,24 @@ class IPCHandlers {}}+ _asyncVectorUpsert(note) {+ setImmediate(() => {+ const vectorIndex = require("./vectorIndex");+ if (!vectorIndex.isReady()) return;+ const { LocalEmbeddings } = require("./localEmbeddings");+ const text = LocalEmbeddings.noteEmbedText(note.title, note.content, note.enhanced_content);+ vectorIndex.upsertNote(note.id, text).catch(() => {});+ });+ }++ _asyncVectorDelete(noteId) {+ setImmediate(() => {+ const vectorIndex = require("./vectorIndex");+ if (!vectorIndex.isReady()) return;+ vectorIndex.deleteNote(noteId).catch(() => {});+ });+ }+_getDictionarySafe() {try {return this.databaseManager.getDictionary();@@ -526,9 +545,8 @@ class IPCHandlers {folderId);if (result?.success && result?.note) {- setImmediate(() => {- this.broadcastToWindows("note-added", result.note);- });+ setImmediate(() => this.broadcastToWindows("note-added", result.note));+ this._asyncVectorUpsert(result.note);}return result;}@@ -545,9 +563,8 @@ class IPCHandlers {ipcMain.handle("db-update-note", async (event, id, updates) => {const result = this.databaseManager.updateNote(id, updates);if (result?.success && result?.note) {- setImmediate(() => {- this.broadcastToWindows("note-updated", result.note);- });+ setImmediate(() => this.broadcastToWindows("note-updated", result.note));+ this._asyncVectorUpsert(result.note);}return result;});@@ -555,9 +572,8 @@ class IPCHandlers {ipcMain.handle("db-delete-note", async (event, id) => {const result = this.databaseManager.deleteNote(id);if (result?.success) {- setImmediate(() => {- this.broadcastToWindows("note-deleted", { id });- });+ setImmediate(() => this.broadcastToWindows("note-deleted", { id }));+ this._asyncVectorDelete(id);}return result;});@@ -566,6 +582,102 @@ class IPCHandlers {return this.databaseManager.searchNotes(query, limit);});+ ipcMain.handle("db-semantic-search-notes", async (event, query, limit = 5) => {+ const vectorIndex = require("./vectorIndex");+ if (!vectorIndex.isReady()) {+ return this.databaseManager.searchNotes(query, limit);+ }++ try {+ const [ftsResults, vectorResults] = await Promise.all([+ this.databaseManager.searchNotes(query, limit * 2),+ vectorIndex.search(query, limit * 2),+ ]);++ // Filter low-confidence semantic matches before RRF+ const filteredVectorResults = vectorResults.filter(({ score }) => score > 0.3);++ // Reciprocal Rank Fusion (K=60, matching cloud implementation)+ const scores = new Map();+ ftsResults.forEach((note, i) => {+ scores.set(note.id, (scores.get(note.id) || 0) + 1 / (60 + i));+ });+ filteredVectorResults.forEach(({ noteId }, i) => {+ scores.set(noteId, (scores.get(noteId) || 0) + 1 / (60 + i));+ });++ const rankedIds = [...scores.entries()]+ .sort((a, b) => b[1] - a[1])+ .slice(0, limit)+ .map(([id]) => id);++ const noteMap = new Map();+ ftsResults.forEach((n) => noteMap.set(n.id, n));+ for (const id of rankedIds) {+ if (!noteMap.has(id)) {+ const note = this.databaseManager.getNote(id);+ if (note) noteMap.set(id, note);+ }+ }++ return rankedIds.map((id) => noteMap.get(id)).filter(Boolean);+ } catch (error) {+ debugLogger.error("Semantic search failed, falling back to FTS5", { error: error.message });+ return this.databaseManager.searchNotes(query, limit);+ }+ });++ ipcMain.handle("db-semantic-reindex-all", async () => {+ const vectorIndex = require("./vectorIndex");+ if (!vectorIndex.isReady()) return { success: false, error: "Vector index not ready" };++ const notes = this.databaseManager.getNotes(null, 100000);+ let done = 0;+ await vectorIndex.reindexAll(notes, (completed, total) => {+ done = completed;+ this.broadcastToWindows("semantic-reindex-progress", { done: completed, total });+ });+ return { success: true, indexed: done };+ });++ ipcMain.handle("semantic-search-enable", async () => {+ try {+ const QdrantManager = require("./qdrantManager");+ const vectorIndex = require("./vectorIndex");++ if (!this.qdrantManager) {+ this.qdrantManager = new QdrantManager();+ }+ await this.qdrantManager.start();++ if (this.qdrantManager.isReady()) {+ vectorIndex.init(this.qdrantManager.getPort());+ await vectorIndex.ensureCollection();+ }++ process.env.LOCAL_SEMANTIC_SEARCH = "true";+ await this.environmentManager.saveAllKeysToEnvFile();+ return { success: true };+ } catch (error) {+ debugLogger.error("Failed to enable semantic search", { error: error.message });+ return { success: false, error: error.message };+ }+ });++ ipcMain.handle("semantic-search-disable", async () => {+ try {+ if (this.qdrantManager) {+ await this.qdrantManager.stop();+ }+ delete process.env.LOCAL_SEMANTIC_SEARCH;+ await this.environmentManager.saveAllKeysToEnvFile();+ return { success: true };+ } catch (error) {+ debugLogger.error("Failed to disable semantic search", { error: error.message });+ return { success: false, error: error.message };+ }+ });+ipcMain.handle("db-update-note-cloud-id", async (event, id, cloudId) => {return this.databaseManager.updateNoteCloudId(id, cloudId);});diff --git a/src/helpers/localEmbeddings.js b/src/helpers/localEmbeddings.jsnew file mode 100644index 000000000..358ef92b1--- /dev/null+++ b/src/helpers/localEmbeddings.js@@ -0,0 +1,181 @@+const fs = require("fs");+const os = require("os");+const path = require("path");+const debugLogger = require("./debugLogger");++const MAX_TOKENS = 256;+const EMBEDDING_DIM = 384;++class LocalEmbeddings {+ constructor() {+ this.session = null;+ this.tokenizer = null;+ this.modelDir = path.join(+ os.homedir(),+ ".cache",+ "openwhispr",+ "embedding-models",+ "all-MiniLM-L6-v2"+ );+ }++ isAvailable() {+ return (+ fs.existsSync(path.join(this.modelDir, "model.onnx")) &&+ fs.existsSync(path.join(this.modelDir, "tokenizer.json"))+ );+ }++ async _ensureLoaded() {+ if (this.session && this.tokenizer) return;++ if (!this.isAvailable()) {+ throw new Error("Embedding model not found. Run: node scripts/download-minilm.js");+ }++ debugLogger.debug("local-embeddings loading model", { modelDir: this.modelDir });++ const tokenizerPath = path.join(this.modelDir, "tokenizer.json");+ const tokenizerData = JSON.parse(fs.readFileSync(tokenizerPath, "utf-8"));+ this.tokenizer = this._buildTokenizer(tokenizerData);++ const ort = require("onnxruntime-node");+ const modelPath = path.join(this.modelDir, "model.onnx");+ this.session = await ort.InferenceSession.create(modelPath);++ debugLogger.debug("local-embeddings model loaded");+ }++ _buildTokenizer(tokenizerData) {+ const tokenToId = new Map();+ for (const [token, id] of Object.entries(tokenizerData.model.vocab)) {+ tokenToId.set(token, id);+ }++ return {+ tokenToId,+ clsId: tokenToId.get("[CLS]") ?? 101,+ sepId: tokenToId.get("[SEP]") ?? 102,+ unkId: tokenToId.get("[UNK]") ?? 100,+ };+ }++ _tokenize(text) {+ const { tokenToId, clsId, sepId, unkId } = this.tokenizer;+ const words = text.toLowerCase().match(/[a-z0-9]+|[^\s\w]/g) || [];+ const tokenIds = [clsId];++ for (const word of words) {+ if (tokenIds.length >= MAX_TOKENS - 1) break;++ if (tokenToId.has(word)) {+ tokenIds.push(tokenToId.get(word));+ continue;+ }++ // WordPiece: greedily match longest subword+ let start = 0;+ while (start < word.length) {+ if (tokenIds.length >= MAX_TOKENS - 1) break;++ let end = word.length;+ let matched = false;++ while (end > start) {+ const subword = start === 0 ? word.slice(start, end) : `##${word.slice(start, end)}`;+ if (tokenToId.has(subword)) {+ tokenIds.push(tokenToId.get(subword));+ start = end;+ matched = true;+ break;+ }+ end--;+ }++ if (!matched) {+ tokenIds.push(unkId);+ start++;+ }+ }+ }++ tokenIds.push(sepId);++ const length = tokenIds.length;+ const inputIds = new BigInt64Array(length);+ const attentionMask = new BigInt64Array(length);+ const tokenTypeIds = new BigInt64Array(length);++ for (let i = 0; i < length; i++) {+ inputIds[i] = BigInt(tokenIds[i]);+ attentionMask[i] = 1n;+ tokenTypeIds[i] = 0n;+ }++ return { inputIds, attentionMask, tokenTypeIds, length };+ }++ async embedText(text) {+ await this._ensureLoaded();++ const { inputIds, attentionMask, tokenTypeIds, length } = this._tokenize(text);++ const ort = require("onnxruntime-node");+ const feeds = {+ input_ids: new ort.Tensor("int64", inputIds, [1, length]),+ attention_mask: new ort.Tensor("int64", attentionMask, [1, length]),+ token_type_ids: new ort.Tensor("int64", tokenTypeIds, [1, length]),+ };++ const results = await this.session.run(feeds);+ const output = results.last_hidden_state ?? results.output_0;++ return this._meanPoolAndNormalize(output.data, length, EMBEDDING_DIM);+ }++ async embedTexts(texts) {+ const results = [];+ for (const text of texts) {+ results.push(await this.embedText(text));+ }+ return results;+ }++ // Mean pooling over token embeddings, then L2 normalize to unit vector+ _meanPoolAndNormalize(data, tokenCount, dim) {+ const embedding = new Float32Array(dim);++ for (let t = 0; t < tokenCount; t++) {+ const offset = t * dim;+ for (let d = 0; d < dim; d++) {+ embedding[d] += data[offset + d];+ }+ }++ for (let d = 0; d < dim; d++) {+ embedding[d] /= tokenCount;+ }++ let norm = 0;+ for (let d = 0; d < dim; d++) {+ norm += embedding[d] * embedding[d];+ }+ norm = Math.sqrt(norm);++ if (norm > 0) {+ for (let d = 0; d < dim; d++) {+ embedding[d] /= norm;+ }+ }++ return embedding;+ }++ static noteEmbedText(title, content, enhancedContent) {+ return `${title}\n${enhancedContent || content}`.slice(0, 1500);+ }+}++const instance = new LocalEmbeddings();+module.exports = instance;+module.exports.LocalEmbeddings = LocalEmbeddings;diff --git a/src/helpers/qdrantManager.js b/src/helpers/qdrantManager.jsnew file mode 100644index 000000000..e5e7f2ad1--- /dev/null+++ b/src/helpers/qdrantManager.js@@ -0,0 +1,238 @@+const { spawn } = require("child_process");+const fs = require("fs");+const path = require("path");+const http = require("http");+const os = require("os");+const debugLogger = require("./debugLogger");+const {+ findAvailablePort,+ resolveBinaryPath,+ gracefulStopProcess,+} = require("../utils/serverUtils");++const PORT_RANGE_START = 6333;+const PORT_RANGE_END = 6350;+const STARTUP_TIMEOUT_MS = 30000;+const STARTUP_POLL_INTERVAL_MS = 100;+const HEALTH_CHECK_INTERVAL_MS = 5000;+const HEALTH_CHECK_TIMEOUT_MS = 2000;++const STORAGE_DIR = path.join(os.homedir(), ".cache", "openwhispr", "qdrant-data");++class QdrantManager {+ constructor() {+ this.process = null;+ this.port = null;+ this.ready = false;+ this.startupPromise = null;+ this.healthCheckInterval = null;+ this.cachedBinaryPath = null;+ }++ getBinaryPath() {+ if (this.cachedBinaryPath) return this.cachedBinaryPath;++ const platformArch = `${process.platform}-${process.arch}`;+ const binaryName =+ process.platform === "win32" ? `qdrant-${platformArch}.exe` : `qdrant-${platformArch}`;++ const resolved = resolveBinaryPath(binaryName);+ if (resolved) this.cachedBinaryPath = resolved;+ return resolved;+ }++ isAvailable() {+ return this.getBinaryPath() !== null;+ }++ async start() {+ if (this.startupPromise) return this.startupPromise;+ if (this.ready) return;+ if (this.process) await this.stop();++ this.startupPromise = this._doStart();+ try {+ await this.startupPromise;+ } finally {+ this.startupPromise = null;+ }+ }++ async _doStart() {+ const binaryPath = this.getBinaryPath();+ if (!binaryPath) throw new Error("qdrant binary not found");++ this.port = await findAvailablePort(PORT_RANGE_START, PORT_RANGE_END);++ fs.mkdirSync(STORAGE_DIR, { recursive: true });++ const configPath = path.join(STORAGE_DIR, "config.yaml");+ const storagePath = path.join(STORAGE_DIR, "storage");+ const configContent = [+ "storage:",+ ` storage_path: ${storagePath}`,+ "service:",+ " host: 127.0.0.1",+ ` http_port: ${this.port}`,+ ` grpc_port: ${this.port + 1}`,+ "",+ ].join("\n");++ fs.writeFileSync(configPath, configContent, "utf-8");++ debugLogger.debug("Starting qdrant", {+ port: this.port,+ binaryPath,+ configPath,+ storagePath,+ });++ this.process = spawn(binaryPath, ["--config-path", configPath], {+ stdio: ["ignore", "pipe", "pipe"],+ windowsHide: true,+ });++ let stderrBuffer = "";+ let exitCode = null;++ this.process.stdout.on("data", (data) => {+ debugLogger.debug("qdrant stdout", { data: data.toString().trim() });+ });++ this.process.stderr.on("data", (data) => {+ stderrBuffer += data.toString();+ debugLogger.debug("qdrant stderr", { data: data.toString().trim() });+ });++ this.process.on("error", (error) => {+ debugLogger.error("qdrant process error", { error: error.message });+ this.ready = false;+ });++ this.process.on("close", (code) => {+ exitCode = code;+ debugLogger.debug("qdrant process exited", { code });+ this.ready = false;+ this.process = null;+ this._stopHealthCheck();+ });++ await this._waitForReady(() => ({ stderr: stderrBuffer, exitCode }));+ this._startHealthCheck();++ debugLogger.info("qdrant started successfully", { port: this.port });+ }++ async _waitForReady(getProcessInfo) {+ const startTime = Date.now();+ let pollCount = 0;++ while (Date.now() - startTime < STARTUP_TIMEOUT_MS) {+ if (!this.process || this.process.killed) {+ const info = getProcessInfo ? getProcessInfo() : {};+ const stderr = info.stderr ? info.stderr.trim().slice(0, 200) : "";+ const details = stderr || (info.exitCode !== null ? `exit code: ${info.exitCode}` : "");+ throw new Error(`qdrant process died during startup${details ? `: ${details}` : ""}`);+ }++ pollCount++;+ if (await this._checkHealth()) {+ this.ready = true;+ debugLogger.debug("qdrant ready", {+ startupTimeMs: Date.now() - startTime,+ pollCount,+ });+ return;+ }++ await new Promise((resolve) => setTimeout(resolve, STARTUP_POLL_INTERVAL_MS));+ }++ throw new Error(`qdrant failed to start within ${STARTUP_TIMEOUT_MS}ms`);+ }++ _checkHealth() {+ return new Promise((resolve) => {+ const req = http.request(+ {+ hostname: "127.0.0.1",+ port: this.port,+ path: "/healthz",+ method: "GET",+ timeout: HEALTH_CHECK_TIMEOUT_MS,+ },+ (res) => {+ resolve(true);+ res.resume();+ }+ );++ req.on("error", () => resolve(false));+ req.on("timeout", () => {+ req.destroy();+ resolve(false);+ });+ req.end();+ });+ }++ _startHealthCheck() {+ this._stopHealthCheck();+ this.healthCheckInterval = setInterval(async () => {+ if (!this.process) {+ this._stopHealthCheck();+ return;+ }+ if (!(await this._checkHealth())) {+ debugLogger.warn("qdrant health check failed");+ this.ready = false;+ }+ }, HEALTH_CHECK_INTERVAL_MS);+ }++ _stopHealthCheck() {+ if (this.healthCheckInterval) {+ clearInterval(this.healthCheckInterval);+ this.healthCheckInterval = null;+ }+ }++ async stop() {+ this._stopHealthCheck();++ if (!this.process) {+ this.ready = false;+ return;+ }++ debugLogger.debug("Stopping qdrant");++ try {+ await gracefulStopProcess(this.process);+ } catch (error) {+ debugLogger.error("Error stopping qdrant", { error: error.message });+ }++ this.process = null;+ this.ready = false;+ this.port = null;+ }++ isReady() {+ return this.ready;+ }++ getPort() {+ return this.port;+ }++ getStatus() {+ return {+ available: this.isAvailable(),+ running: this.ready && this.process !== null,+ port: this.port,+ };+ }+}++module.exports = QdrantManager;diff --git a/src/helpers/vectorIndex.js b/src/helpers/vectorIndex.jsnew file mode 100644index 000000000..da53038cb--- /dev/null+++ b/src/helpers/vectorIndex.js@@ -0,0 +1,95 @@+const { QdrantClient } = require("@qdrant/js-client-rest");+const localEmbeddings = require("./localEmbeddings");+const { LocalEmbeddings } = localEmbeddings;+const debugLogger = require("./debugLogger");++class VectorIndex {+ constructor() {+ this.client = null;+ this.collectionName = "notes";+ }++ init(port) {+ this.client = new QdrantClient({ host: "127.0.0.1", port });+ }++ async ensureCollection() {+ if (!this.client) return;+ try {+ await this.client.getCollection(this.collectionName);+ } catch {+ try {+ await this.client.createCollection(this.collectionName, {+ vectors: { size: 384, distance: "Cosine" },+ });+ } catch (err) {+ debugLogger.error("Failed to create Qdrant collection", { error: err.message });+ }+ }+ }++ async upsertNote(noteId, text) {+ if (!this.client) return;+ try {+ const vector = await localEmbeddings.embedText(text);+ await this.client.upsert(this.collectionName, {+ points: [{ id: noteId, vector: Array.from(vector), payload: {} }],+ });+ } catch (err) {+ debugLogger.debug("Vector index upsert failed", { noteId, error: err.message });+ }+ }++ async deleteNote(noteId) {+ if (!this.client) return;+ try {+ await this.client.delete(this.collectionName, { points: [noteId] });+ } catch (err) {+ debugLogger.debug("Vector index delete failed", { noteId, error: err.message });+ }+ }++ async search(queryText, limit = 5) {+ if (!this.client) return [];+ try {+ const vector = await localEmbeddings.embedText(queryText);+ const results = await this.client.search(this.collectionName, {+ vector: Array.from(vector),+ limit,+ });+ return results.map((r) => ({ noteId: r.id, score: r.score }));+ } catch (err) {+ debugLogger.debug("Vector search failed", { error: err.message });+ return [];+ }+ }++ async reindexAll(notes, onProgress) {+ if (!this.client) return;+ const BATCH_SIZE = 50;+ for (let i = 0; i < notes.length; i += BATCH_SIZE) {+ const batch = notes.slice(i, i + BATCH_SIZE);+ const texts = batch.map((n) =>+ LocalEmbeddings.noteEmbedText(n.title, n.content, n.enhanced_content)+ );+ try {+ const vectors = await localEmbeddings.embedTexts(texts);+ const points = batch.map((n, j) => ({+ id: n.id,+ vector: Array.from(vectors[j]),+ payload: {},+ }));+ await this.client.upsert(this.collectionName, { points });+ } catch (err) {+ debugLogger.debug("Vector reindex batch failed", { offset: i, error: err.message });+ }+ if (onProgress) onProgress(Math.min(i + BATCH_SIZE, notes.length), notes.length);+ }+ }++ isReady() {+ return this.client !== null;+ }+}++module.exports = new VectorIndex();diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.tsindex 7c563be18..a3a23234b 100644--- a/src/hooks/useSettings.ts+++ b/src/hooks/useSettings.ts@@ -53,6 +53,7 @@ export interface ApiKeySettings {export interface PrivacySettings {cloudBackupEnabled: boolean;+ localSemanticSearchEnabled: boolean;telemetryEnabled: boolean;audioRetentionDays: number;dataRetentionEnabled: boolean;@@ -245,6 +246,8 @@ function useSettingsInternal() {setKeepTranscriptionInClipboard: store.setKeepTranscriptionInClipboard,cloudBackupEnabled: store.cloudBackupEnabled,setCloudBackupEnabled: store.setCloudBackupEnabled,+ localSemanticSearchEnabled: store.localSemanticSearchEnabled,+ setLocalSemanticSearchEnabled: store.setLocalSemanticSearchEnabled,telemetryEnabled: store.telemetryEnabled,setTelemetryEnabled: store.setTelemetryEnabled,audioRetentionDays: store.audioRetentionDays,diff --git a/src/locales/de/translation.json b/src/locales/de/translation.jsonindex 46514273d..e4eb51561 100644--- a/src/locales/de/translation.json+++ b/src/locales/de/translation.json@@ -1352,6 +1352,8 @@"title": "Datenschutz","usageAnalytics": "Nutzungsanalysen","usageAnalyticsDescription": "Helfen Sie uns, OpenWhispr zu verbessern, indem Sie anonyme Leistungsdaten teilen. Wir senden niemals Transkriptionsinhalte – nur Timing- und Fehlerdaten.",+ "localSemanticSearch": "Lokale semantische Suche",+ "localSemanticSearchDescription": "Notizen nach Bedeutung finden, nicht nur nach Stichwörtern. Benötigt ca. 52 MB für das Einbettungsmodell und den Suchindex. Funktioniert vollständig offline.","dataRetention": "Datenaufbewahrung","dataRetentionDescription": "Transkriptionen und Audio lokal im Verlauf speichern. Wenn deaktiviert, werden Transkriptionen eingefügt, aber nicht gespeichert.","audioRetention": "Audio-Aufbewahrung",diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex c2a10f910..9f2bcac02 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -1400,6 +1400,8 @@"title": "Privacy","usageAnalytics": "Usage analytics","usageAnalyticsDescription": "Help us improve OpenWhispr by sharing anonymous performance metrics. We never send transcription content — only timing and error data.",+ "localSemanticSearch": "Local semantic search",+ "localSemanticSearchDescription": "Find notes by meaning, not just keywords. Uses ~52 MB for the embedding model and search index. Works fully offline.","audioRetention": "Audio Retention","audioRetentionDescription": "Store audio recordings locally for re-transcription and download. Files are automatically deleted after the retention period.","audioRetentionDisabled": "Disabled",diff --git a/src/locales/es/translation.json b/src/locales/es/translation.jsonindex 106b7e71d..a55ec447e 100644--- a/src/locales/es/translation.json+++ b/src/locales/es/translation.json@@ -1352,6 +1352,8 @@"title": "Privacidad","usageAnalytics": "Analíticas de uso","usageAnalyticsDescription": "Ayúdanos a mejorar OpenWhispr compartiendo métricas de rendimiento anónimas. Nunca enviamos contenido de transcripciones, solo datos de tiempo y errores.",+ "localSemanticSearch": "Búsqueda semántica local",+ "localSemanticSearchDescription": "Encuentra notas por significado, no solo por palabras clave. Usa ~52 MB para el modelo de embeddings y el índice de búsqueda. Funciona completamente sin conexión.","dataRetention": "Retención de datos","dataRetentionDescription": "Almacenar transcripciones y audio localmente en tu historial. Cuando está desactivado, las transcripciones se pegan pero no se guardan.","audioRetention": "Retención de audio",diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.jsonindex d73e7dc33..c59b4a07a 100644--- a/src/locales/fr/translation.json+++ b/src/locales/fr/translation.json@@ -1352,6 +1352,8 @@"title": "Confidentialité","usageAnalytics": "Analyse d'utilisation","usageAnalyticsDescription": "Aidez-nous à améliorer OpenWhispr en partageant des métriques de performance anonymes. Nous n'envoyons jamais le contenu de vos transcriptions — uniquement des données de performance et d'erreurs.",+ "localSemanticSearch": "Recherche sémantique locale",+ "localSemanticSearchDescription": "Trouvez des notes par sens, pas seulement par mots-clés. Utilise environ 52 Mo pour le modèle d'embeddings et l'index de recherche. Fonctionne entièrement hors ligne.","dataRetention": "Conservation des données","dataRetentionDescription": "Stocker les transcriptions et l'audio localement dans votre historique. Lorsque désactivé, les transcriptions sont collées mais pas enregistrées.","audioRetention": "Conservation de l'audio",diff --git a/src/locales/it/translation.json b/src/locales/it/translation.jsonindex 05536bcf9..a3802b7ca 100644--- a/src/locales/it/translation.json+++ b/src/locales/it/translation.json@@ -1352,6 +1352,8 @@"title": "Privacy","usageAnalytics": "Analisi dell'utilizzo","usageAnalyticsDescription": "Aiutaci a migliorare OpenWhispr condividendo metriche di prestazione anonime. Non inviamo mai il contenuto delle trascrizioni, solo dati su tempi ed errori.",+ "localSemanticSearch": "Ricerca semantica locale",+ "localSemanticSearchDescription": "Trova le note per significato, non solo per parole chiave. Usa circa 52 MB per il modello di embedding e l'indice di ricerca. Funziona completamente offline.","dataRetention": "Conservazione dei dati","dataRetentionDescription": "Salva trascrizioni e audio localmente nella cronologia. Se disattivato, le trascrizioni vengono incollate ma non salvate.","audioRetention": "Conservazione audio",diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.jsonindex 6b153204c..c4eb3bc4a 100644--- a/src/locales/ja/translation.json+++ b/src/locales/ja/translation.json@@ -1352,6 +1352,8 @@"title": "プライバシー","usageAnalytics": "使用状況の分析","usageAnalyticsDescription": "匿名のパフォーマンスデータを共有して OpenWhispr の改善にご協力ください。文字起こしの内容は送信されません。タイミングとエラーデータのみです。",+ "localSemanticSearch": "ローカルセマンティック検索",+ "localSemanticSearchDescription": "キーワードだけでなく、意味でノートを検索します。埋め込みモデルと検索インデックスに約52 MBを使用します。完全にオフラインで動作します。","dataRetention": "データ保持","dataRetentionDescription": "文字起こしと音声を履歴にローカル保存します。無効にすると、文字起こしは貼り付けられますが保存されません。","audioRetention": "音声の保持",diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.jsonindex e0e34e5b0..b36dbf535 100644--- a/src/locales/pt/translation.json+++ b/src/locales/pt/translation.json@@ -1324,6 +1324,8 @@"title": "Privacidade","usageAnalytics": "Análise de uso","usageAnalyticsDescription": "Ajude-nos a melhorar o OpenWhispr compartilhando métricas anônimas de desempenho. Nunca enviamos conteúdo de transcrição — apenas dados de tempo e erros.",+ "localSemanticSearch": "Pesquisa semântica local",+ "localSemanticSearchDescription": "Encontre notas por significado, não apenas por palavras-chave. Usa ~52 MB para o modelo de embeddings e o índice de pesquisa. Funciona totalmente offline.","dataRetention": "Retenção de dados","dataRetentionDescription": "Armazenar transcrições e áudio localmente no seu histórico. Quando desativado, as transcrições são coladas mas não salvas.","audioRetention": "Retenção de áudio",diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.jsonindex e367dc180..a1b06f0e7 100644--- a/src/locales/ru/translation.json+++ b/src/locales/ru/translation.json@@ -1352,6 +1352,8 @@"title": "Конфиденциальность","usageAnalytics": "Аналитика использования","usageAnalyticsDescription": "Помогите нам улучшить OpenWhispr, делясь анонимными метриками производительности. Мы никогда не отправляем содержимое транскрипций — только данные о времени и ошибках.",+ "localSemanticSearch": "Локальный семантический поиск",+ "localSemanticSearchDescription": "Находите заметки по смыслу, а не только по ключевым словам. Использует ~52 МБ для модели эмбеддингов и поискового индекса. Работает полностью офлайн.","dataRetention": "Хранение данных","dataRetentionDescription": "Сохранять транскрипции и аудио локально в истории. При отключении транскрипции вставляются, но не сохраняются.","audioRetention": "Хранение аудио",diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.jsonindex 93c3ec54a..d5c0f95ba 100644--- a/src/locales/zh-CN/translation.json+++ b/src/locales/zh-CN/translation.json@@ -1347,6 +1347,8 @@"title": "隐私","usageAnalytics": "使用分析","usageAnalyticsDescription": "通过分享匿名性能数据帮助我们改进 OpenWhispr。我们绝不发送转录内容——仅发送计时和错误数据。",+ "localSemanticSearch": "本地语义搜索",+ "localSemanticSearchDescription": "按含义查找笔记,不仅仅是关键词。嵌入模型和搜索索引约需 52 MB 空间。完全离线运行。","dataRetention": "数据保留","dataRetentionDescription": "将转录和音频本地保存到历史记录中。禁用后,转录内容会被粘贴但不会被保存。","audioRetention": "音频保留",diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.jsonindex e3811b4da..f1c7260bd 100644--- a/src/locales/zh-TW/translation.json+++ b/src/locales/zh-TW/translation.json@@ -1347,6 +1347,8 @@"title": "隱私權","usageAnalytics": "使用分析","usageAnalyticsDescription": "分享匿名的效能指標,協助我們改善 OpenWhispr。我們絕不會傳送轉錄內容——只有計時和錯誤資料。",+ "localSemanticSearch": "本地語義搜尋",+ "localSemanticSearchDescription": "依含義尋找筆記,不僅僅是關鍵字。嵌入模型和搜尋索引約需 52 MB 空間。完全離線運作。","dataRetention": "資料保留","dataRetentionDescription": "將轉錄和音訊本地儲存至歷史記錄。停用後,轉錄內容會被貼上但不會被儲存。","audioRetention": "音訊保留",diff --git a/src/services/tools/index.ts b/src/services/tools/index.tsindex 35552f94a..9b840dcb6 100644--- a/src/services/tools/index.ts+++ b/src/services/tools/index.ts@@ -14,13 +14,15 @@ interface ToolRegistrySettings {isSignedIn: boolean;gcalConnected: boolean;cloudBackupEnabled: boolean;+ localSemanticSearchEnabled?: boolean;}export function createToolRegistry(settings: ToolRegistrySettings): ToolRegistry {const registry = new ToolRegistry();const useCloudSearch = settings.isSignedIn && settings.cloudBackupEnabled;- registry.register(createSearchNotesTool({ useCloudSearch }));+ const useLocalSemanticSearch = !useCloudSearch && !!settings.localSemanticSearchEnabled;+ registry.register(createSearchNotesTool({ useCloudSearch, useLocalSemanticSearch }));registry.register(getNoteTool);registry.register(createNoteTool);registry.register(updateNoteTool);diff --git a/src/services/tools/searchNotesTool.ts b/src/services/tools/searchNotesTool.tsindex 70e7e1539..1a30cd4a6 100644--- a/src/services/tools/searchNotesTool.ts+++ b/src/services/tools/searchNotesTool.ts@@ -4,14 +4,17 @@ const MAX_CONTENT_LENGTH = 500;interface SearchToolOptions {useCloudSearch: boolean;+ useLocalSemanticSearch: boolean;}export function createSearchNotesTool(options: SearchToolOptions): ToolDefinition {- const { useCloudSearch } = options;+ const { useCloudSearch, useLocalSemanticSearch } = options;++ const hasSemanticSearch = useCloudSearch || useLocalSemanticSearch;return {name: "search_notes",- description: useCloudSearch+ description: hasSemanticSearch? "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: {@@ -35,31 +38,39 @@ export function createSearchNotesTool(options: SearchToolOptions): ToolDefinitioconst query = args.query as string;const limit = typeof args.limit === "number" ? args.limit : 5;- 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+ // Build fallback chain: cloud → local semantic → FTS5+ const strategies: Array<() => Promise<ToolResult>> = [];+ if (useCloudSearch) strategies.push(() => executeCloudSearch(query, limit));+ if (useLocalSemanticSearch) strategies.push(() => executeLocalSearch(query, limit, true));+ strategies.push(() => executeLocalSearch(query, limit, false));++ for (let i = 0; i < strategies.length; i++) {+ try {+ return await strategies[i]();+ } catch (error) {+ if (i === strategies.length - 1) {+ return {+ success: false,+ data: null,+ displayText: `Failed to search notes: ${(error as Error).message}`,+ };}}- return {- success: false,- data: null,- displayText: `Failed to search notes: ${(error as Error).message}`,- };}++ return { success: false, data: null, displayText: "No search strategies available" };},};}-async function executeLocalSearch(query: string, limit: number): Promise<ToolResult> {- const notes = await window.electronAPI.searchNotes(query, limit);+async function executeLocalSearch(+ query: string,+ limit: number,+ semantic: boolean+): Promise<ToolResult> {+ const notes = semantic+ ? await window.electronAPI.semanticSearchNotes(query, limit)+ : await window.electronAPI.searchNotes(query, limit);if (notes.length === 0) {return {@@ -80,7 +91,7 @@ async function executeLocalSearch(query: string, limit: number): Promise<ToolResreturn {success: true,data: results,- displayText: `Found ${results.length} note${results.length === 1 ? "" : "s"} for "${query}"`,+ displayText: `Found ${results.length} note${results.length === 1 ? "" : "s"} for "${query}"${semantic ? " (semantic search)" : ""}`,};}diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.tsindex 85321b4cc..067f5445b 100644--- a/src/stores/settingsStore.ts+++ b/src/stores/settingsStore.ts@@ -54,6 +54,7 @@ const BOOLEAN_SETTINGS = new Set(["useReasoningModel","preferBuiltInMic","cloudBackupEnabled",+ "localSemanticSearchEnabled","telemetryEnabled","audioCuesEnabled","pauseMediaOnDictation",@@ -144,6 +145,7 @@ export interface SettingsStatesetTheme: (value: "light" | "dark" | "auto") => void;setCloudBackupEnabled: (value: boolean) => void;+ setLocalSemanticSearchEnabled: (value: boolean) => void;setTelemetryEnabled: (value: boolean) => void;setAudioRetentionDays: (days: number) => void;setDataRetentionEnabled: (value: boolean) => void;@@ -273,6 +275,7 @@ export const useSettingsStore = create<SettingsState>()((set, get) => ({return "auto" as const;})(),cloudBackupEnabled: readBoolean("cloudBackupEnabled", false),+ localSemanticSearchEnabled: readBoolean("localSemanticSearchEnabled", false),telemetryEnabled: readBoolean("telemetryEnabled", false),audioRetentionDays: (() => {if (!isBrowser) return 30;@@ -442,6 +445,7 @@ export const useSettingsStore = create<SettingsState>()((set, get) => ({},setCloudBackupEnabled: createBooleanSetter("cloudBackupEnabled"),+ setLocalSemanticSearchEnabled: createBooleanSetter("localSemanticSearchEnabled"),setTelemetryEnabled: createBooleanSetter("telemetryEnabled"),setAudioRetentionDays: (days: number) => {if (isBrowser) localStorage.setItem("audioRetentionDays", String(days));diff --git a/src/types/electron.ts b/src/types/electron.tsindex 078350eb6..82aef3395 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -371,6 +371,13 @@ declare global {format: "txt" | "md") => Promise<{ success: boolean; error?: string }>;searchNotes: (query: string, limit?: number) => Promise<NoteItem[]>;+ semanticSearchNotes: (query: string, limit?: number) => Promise<NoteItem[]>;+ semanticReindexAll: () => Promise<{ success: boolean; indexed?: number; error?: string }>;+ onSemanticReindexProgress: (+ callback: (data: { done: number; total: number }) => void+ ) => () => void;+ enableSemanticSearch: () => Promise<{ success: boolean; error?: string }>;+ disableSemanticSearch: () => Promise<{ success: boolean; error?: string }>;updateNoteCloudId: (id: number, cloudId: string) => Promise<NoteItem>;// Folder operations