Skip to main content

Problem

Desktop apps need instant, private search that works offline. Users expect results as they type, and a desktop app can’t assume a fast connection - or any connection at all. Round trips to a search service add latency you can feel and break the moment the network does.

Approach

Keep the index on the device and query it in-process from the main process. Search becomes a local function call rather than a network request, so it stays sub-10 ms and keeps working offline. The index persists to the user data directory and syncs in the background when a connection is available.

Architecture

  • Main process owns a Moss client
  • Renderer calls main via IPC for index/query
  • Index persisted to the user data directory

Code walkthrough (Main)

// main.ts
import { app, ipcMain } from 'electron'
import { MossClient } from '@moss-dev/moss'

let client: MossClient
const INDEX = 'electron-docs'

app.whenReady().then(async () => {
  client = new MossClient(process.env.MOSS_PROJECT_ID!, process.env.MOSS_PROJECT_KEY!)
  await client.createIndex(INDEX, initialDocs, { modelId: 'moss-minilm' })
})

ipcMain.handle('search', async (_e, q: string) => {
  await client.loadIndex(INDEX)
  return client.query(INDEX, q, { topK: 5 })
})

Result

Native-feel search with sub-10 ms latency, no network dependency, and data that stays on the user’s machine.

Sub-10ms knowledge retrieval

The retrieval pipeline in depth.

Local embeddings

Embed on-device for privacy.