MCPcopy Create free account
hub / github.com/MemTensor/MemOS / searchHubChunks

Method searchHubChunks

packages/memos-core/src/storage/sqlite.ts:2412–2432  ·  view source on GitHub ↗
(query: string, options?: { userId?: string; maxResults?: number })

Source from the content-addressed store, hash-verified

2410 }
2411
2412 searchHubChunks(query: string, options?: { userId?: string; maxResults?: number }): Array<{ hit: HubSearchRow; rank: number }> {
2413 const limit = options?.maxResults ?? 10;
2414 const userId = options?.userId ?? "";
2415 const rows = this.db.prepare(`
2416 SELECT hc.id, hc.content, hc.summary, hc.role, hc.created_at, ht.title as task_title, ht.visibility,
2417 COALESCE(hg.name, '') as group_name, hu.username as owner_name,
2418 bm25(hub_chunks_fts) as rank
2419 FROM hub_chunks_fts f
2420 JOIN hub_chunks hc ON hc.rowid = f.rowid
2421 JOIN hub_tasks ht ON ht.id = hc.hub_task_id
2422 LEFT JOIN hub_users hu ON hu.id = ht.source_user_id
2423 LEFT JOIN hub_groups hg ON hg.id = ht.group_id
2424 WHERE hub_chunks_fts MATCH ?
2425 AND (ht.visibility = 'public'
2426 OR ht.source_user_id = ?
2427 OR EXISTS (SELECT 1 FROM hub_group_members gm WHERE gm.group_id = ht.group_id AND gm.user_id = ?))
2428 ORDER BY rank
2429 LIMIT ?
2430 `).all(sanitizeFtsQuery(query), userId, userId, limit) as HubSearchRow[];
2431 return rows.map((row, idx) => ({ hit: row, rank: idx + 1 }));
2432 }
2433
2434 upsertHubEmbedding(chunkId: string, vector: Float32Array): void {
2435 const buf = Buffer.from(vector.buffer, vector.byteOffset, vector.byteLength);

Callers 1

handleMethod · 0.45

Calls 4

allMethod · 0.80
prepareMethod · 0.80
mapMethod · 0.80
sanitizeFtsQueryFunction · 0.70

Tested by

no test coverage detected