(limit: number, ownerFilter?: string[])
| 1366 | } |
| 1367 | |
| 1368 | getRecentEmbeddings(limit: number, ownerFilter?: string[]): Array<{ chunkId: string; vector: number[] }> { |
| 1369 | if (limit <= 0) return this.getAllEmbeddings(ownerFilter); |
| 1370 | |
| 1371 | let sql = `SELECT e.chunk_id, e.vector, e.dimensions |
| 1372 | FROM chunks c |
| 1373 | JOIN embeddings e ON e.chunk_id = c.id |
| 1374 | WHERE c.dedup_status = 'active'`; |
| 1375 | const params: any[] = []; |
| 1376 | |
| 1377 | if (ownerFilter && ownerFilter.length > 0) { |
| 1378 | const placeholders = ownerFilter.map(() => "?").join(","); |
| 1379 | sql += ` AND c.owner IN (${placeholders})`; |
| 1380 | params.push(...ownerFilter); |
| 1381 | } |
| 1382 | |
| 1383 | sql += ` ORDER BY c.created_at DESC LIMIT ?`; |
| 1384 | params.push(limit); |
| 1385 | |
| 1386 | const rows = this.db.prepare(sql).all(...params) as Array<{ chunk_id: string; vector: Buffer; dimensions: number }>; |
| 1387 | |
| 1388 | return rows.map((r) => ({ |
| 1389 | chunkId: r.chunk_id, |
| 1390 | vector: Array.from(new Float32Array(r.vector.buffer, r.vector.byteOffset, r.dimensions)), |
| 1391 | })); |
| 1392 | } |
| 1393 | |
| 1394 | getEmbedding(chunkId: string): number[] | null { |
| 1395 | const row = this.db.prepare( |
no test coverage detected