Skip to content

Commit 7453a99

Browse files
committed
upd: prevent empty embedding from corrupting the database
1 parent b03c152 commit 7453a99

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/adapter-sqlite/src/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from "./sqliteTables.ts";
22
export * from "./sqlite_vec.ts";
33

4-
import { DatabaseAdapter, IDatabaseCacheAdapter } from "@elizaos/core";
4+
import { DatabaseAdapter, elizaLogger, IDatabaseCacheAdapter } from "@elizaos/core";
55
import {
66
Account,
77
Actor,
@@ -215,13 +215,19 @@ export class SqliteDatabaseAdapter
215215
const content = JSON.stringify(memory.content);
216216
const createdAt = memory.createdAt ?? Date.now();
217217

218+
let embeddingValue: Float32Array = new Float32Array(384);
219+
// If embedding is not available, we just load an array with a length of 384
220+
if (memory?.embedding && memory?.embedding?.length > 0) {
221+
embeddingValue = new Float32Array(memory.embedding);
222+
}
223+
218224
// Insert the memory with the appropriate 'unique' value
219225
const sql = `INSERT OR REPLACE INTO memories (id, type, content, embedding, userId, roomId, agentId, \`unique\`, createdAt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
220226
this.db.prepare(sql).run(
221227
memory.id ?? v4(),
222228
tableName,
223229
content,
224-
new Float32Array(memory.embedding!), // Store as Float32Array
230+
embeddingValue,
225231
memory.userId,
226232
memory.roomId,
227233
memory.agentId,
@@ -707,4 +713,4 @@ export class SqliteDatabaseAdapter
707713
return false;
708714
}
709715
}
710-
}
716+
}

0 commit comments

Comments
 (0)