@agentskit/memory
Advanced tools
+35
-12
@@ -733,2 +733,18 @@ export { createInMemoryPersonalization, renderProfileContext } from './chunk-JNYX5ZQ4.js'; | ||
| } | ||
| var qdrantSourceId = "__agentskitSourceId"; | ||
| var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
| async function qdrantPointId(id) { | ||
| if (uuidPattern.test(id)) return id; | ||
| if (/^\d+$/.test(id)) { | ||
| const numericId = Number(id); | ||
| if (Number.isSafeInteger(numericId)) return numericId; | ||
| } | ||
| const digest = new Uint8Array( | ||
| await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(id)) | ||
| ).slice(0, 16); | ||
| digest[6] = digest[6] & 15 | 80; | ||
| digest[8] = digest[8] & 63 | 128; | ||
| const hex = Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join(""); | ||
| return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; | ||
| } | ||
| async function call2(config, method, path, body) { | ||
@@ -759,8 +775,9 @@ const fetchImpl = config.fetch ?? globalThis.fetch; | ||
| if (docs.length === 0) return; | ||
| const points = await Promise.all(docs.map(async (d) => ({ | ||
| id: await qdrantPointId(d.id), | ||
| vector: d.embedding, | ||
| payload: { content: d.content, ...d.metadata ?? {}, [qdrantSourceId]: d.id } | ||
| }))); | ||
| await call2(config, "PUT", `/collections/${config.collection}/points`, { | ||
| points: docs.map((d) => ({ | ||
| id: d.id, | ||
| vector: d.embedding, | ||
| payload: { content: d.content, ...d.metadata ?? {} } | ||
| })) | ||
| points | ||
| }); | ||
@@ -776,13 +793,19 @@ }, | ||
| }); | ||
| return (result.result ?? []).filter((m) => m.score >= threshold).map((m) => ({ | ||
| id: String(m.id), | ||
| content: String((m.payload ?? {}).content ?? ""), | ||
| metadata: m.payload, | ||
| score: m.score | ||
| })); | ||
| return (result.result ?? []).filter((m) => m.score >= threshold).map((m) => { | ||
| const payload = { ...m.payload ?? {} }; | ||
| const sourceId = payload[qdrantSourceId]; | ||
| delete payload[qdrantSourceId]; | ||
| return { | ||
| id: typeof sourceId === "string" ? sourceId : String(m.id), | ||
| content: String(payload.content ?? ""), | ||
| metadata: payload, | ||
| score: m.score | ||
| }; | ||
| }); | ||
| }, | ||
| async delete(ids) { | ||
| if (ids.length === 0) return; | ||
| const points = await Promise.all(ids.map(qdrantPointId)); | ||
| await call2(config, "POST", `/collections/${config.collection}/points/delete`, { | ||
| points: ids | ||
| points | ||
| }); | ||
@@ -789,0 +812,0 @@ } |
+1
-1
| { | ||
| "name": "@agentskit/memory", | ||
| "version": "0.11.3", | ||
| "version": "0.11.4", | ||
| "description": "Persistent and vector memory backends for AgentsKit.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
585254
1.26%4870
0.95%