| 54 | } |
| 55 | |
| 56 | function removeConversation(conversationId: string): void { |
| 57 | // Mark entries as removed (nullish id) — we rebuild if fragmentation grows |
| 58 | for (const entry of entries) { |
| 59 | if (entry.conversationId === conversationId) { |
| 60 | (entry as { conversationId: string }).conversationId = "__removed__"; |
| 61 | } |
| 62 | } |
| 63 | // Prune index entries that only point to removed items |
| 64 | for (const [token, set] of index) { |
| 65 | for (const idx of set) { |
| 66 | if (entries[idx].conversationId === "__removed__") set.delete(idx); |
| 67 | } |
| 68 | if (set.size === 0) index.delete(token); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function extractSnippet(text: string, query: string): string { |
| 73 | const lower = text.toLowerCase(); |