MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / search

Function search

packages/node-runtime/src/semantic-index/chat-db/fts-searcher.ts:31–46  ·  view source on GitHub ↗
(query: string, topN: number)

Source from the content-addressed store, hash-verified

29export function createChatDbFtsSearcher(db: DatabaseAdapter): FtsSearcher {
30 return {
31 search(query: string, topN: number): Array<{ id: number; ts: number }> {
32 const keywords = extractFtsKeywords(query)
33 if (keywords.length === 0) return []
34 const { rowids } = searchByFts(db, keywords, topN, 0)
35 if (rowids.length === 0) return []
36 const placeholders = rowids.map(() => '?').join(', ')
37 const tsRows = db.prepare(`SELECT id, ts FROM message WHERE id IN (${placeholders})`).all(...rowids) as Array<{
38 id: number
39 ts: number
40 }>
41 const tsById = new Map(tsRows.map((r) => [r.id, r.ts * 1000]))
42 return rowids.flatMap((id) => {
43 const ts = tsById.get(id)
44 return ts !== undefined ? [{ id, ts }] : []
45 })
46 },
47 }
48}

Callers

nothing calls this directly

Calls 5

searchByFtsFunction · 0.90
extractFtsKeywordsFunction · 0.85
allMethod · 0.65
prepareMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected