Skip to content

Commit c8f1c08

Browse files
authored
Merge pull request elizaOS#1984 from JoeyKhd/fix-sqlite-error
fix: SQLITE ERROR, zero-lenght vectors not supported
2 parents b03c152 + 0d5d8ba commit c8f1c08

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/adapter-sqlite/src/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -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)