Skip to content

Commit d0924a8

Browse files
author
mike dupont
committed
removing duplicates
1 parent d44a661 commit d0924a8

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

packages/adapter-sqlite/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class SqliteDatabaseAdapter
424424
ORDER BY levenshtein_score ASC
425425
LIMIT ?
426426
`;
427-
427+
console.log("similarity",sql)
428428
const rows = this.db
429429
.prepare(sql)
430430
.all(
@@ -439,7 +439,7 @@ export class SqliteDatabaseAdapter
439439
opts.query_input,
440440
opts.query_match_count
441441
) as { embedding: Buffer; levenshtein_score: number }[];
442-
442+
console.log("found these",rows)
443443
return rows.map((row) => ({
444444
embedding: Array.from(new Float32Array(row.embedding as Buffer)),
445445
levenshtein_score: row.levenshtein_score,

packages/core/src/embedding.ts

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export async function embed(runtime: IAgentRuntime, input: string) {
295295
}
296296
if (! runtime.messageManager) {
297297
elizaLogger.log("No message manager");
298+
throw Error("No message manager");
298299
return null;
299300
}
300301

scripts/jsdoc-automation/src/AIService/AIService.ts

+36-21
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ export class AIService {
326326
throw error;
327327
}
328328
}
329+
function contentToUuid(content:string):UUID {
330+
// Step 1: Create a SHA-1 hash of the content
331+
const hash = crypto.createHash('sha1')
332+
.update(content)
333+
.digest('hex'); // Outputs a 40-character hex string
334+
335+
// Step 2: Format the hash into a UUID-like structure
336+
// UUID format: 8-4-4-4-12 (e.g., 550e8400-e29b-41d4-a716-446655440000)
337+
const uuid = `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
338+
339+
return uuid as `${string}-${string}-${string}-${string}-${string}`;
340+
}
329341

330342
async function processChunk(prompt: string, manager: string, runtime: AgentRuntime): Promise<string> {
331343
console.log("process chunk");
@@ -336,15 +348,30 @@ async function processChunk(prompt: string, manager: string, runtime: AgentRunti
336348
console.log("memoryManagers",runtime.memoryManagers);
337349
throw new Error(`Memory manager not found {manager}`);
338350
}
339-
const memory = await mm.addEmbeddingToMemory({
340-
agentId: runtime.agentId,
341-
userId: runtime.agentId, //|| runtime.userId,
342-
content: { text: prompt },
343-
roomId: runtime.agentId,
344-
embedding: await embed(runtime, prompt),
345-
});
346-
await mm.createMemory(memory);
347-
return "Success";
351+
352+
const memId = contentToUuid (prompt);
353+
const existingResponse =
354+
await mm.getMemoryById(
355+
memId
356+
);
357+
if (!existingResponse) {
358+
console.log("create new memory", memId);
359+
const memory = await mm.addEmbeddingToMemory({
360+
id: memId,
361+
agentId: runtime.agentId,
362+
userId: runtime.agentId, //|| runtime.userId,
363+
content: { text: prompt },
364+
roomId: runtime.agentId,
365+
embedding: await embed(runtime, prompt),
366+
});
367+
await mm.createMemory(memory);
368+
return "Success";
369+
}
370+
else {
371+
console.log("existingResponse", memId, existingResponse);
372+
return "Success";
373+
}
374+
348375
} catch (error: any) {
349376
console.error("Failed to process chunk:", error);
350377
return "Failed";
@@ -353,18 +380,6 @@ async function processChunk(prompt: string, manager: string, runtime: AgentRunti
353380

354381

355382

356-
function contentToUuid(content:string):UUID {
357-
// Step 1: Create a SHA-1 hash of the content
358-
const hash = crypto.createHash('sha1')
359-
.update(content)
360-
.digest('hex'); // Outputs a 40-character hex string
361-
362-
// Step 2: Format the hash into a UUID-like structure
363-
// UUID format: 8-4-4-4-12 (e.g., 550e8400-e29b-41d4-a716-446655440000)
364-
const uuid = `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
365-
366-
return uuid as `${string}-${string}-${string}-${string}-${string}`;
367-
}
368383

369384
// async function process_text(this: any, agentId: string, userName: string, name: string, sUserId: string | undefined,
370385
// sRoomId: string, text:string, agents: Map<string, any>) {

0 commit comments

Comments
 (0)