Skip to content

Commit

Permalink
Merge pull request #1984 from JoeyKhd/fix-sqlite-error
Browse files Browse the repository at this point in the history
fix: SQLITE ERROR, zero-lenght vectors not supported
  • Loading branch information
shakkernerd authored Jan 7, 2025
2 parents b03c152 + 0d5d8ba commit c8f1c08
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/adapter-sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,19 @@ export class SqliteDatabaseAdapter
const content = JSON.stringify(memory.content);
const createdAt = memory.createdAt ?? Date.now();

let embeddingValue: Float32Array = new Float32Array(384);
// If embedding is not available, we just load an array with a length of 384
if (memory?.embedding && memory?.embedding?.length > 0) {
embeddingValue = new Float32Array(memory.embedding);
}

// Insert the memory with the appropriate 'unique' value
const sql = `INSERT OR REPLACE INTO memories (id, type, content, embedding, userId, roomId, agentId, \`unique\`, createdAt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
this.db.prepare(sql).run(
memory.id ?? v4(),
tableName,
content,
new Float32Array(memory.embedding!), // Store as Float32Array
embeddingValue,
memory.userId,
memory.roomId,
memory.agentId,
Expand Down Expand Up @@ -707,4 +713,4 @@ export class SqliteDatabaseAdapter
return false;
}
}
}
}

0 comments on commit c8f1c08

Please sign in to comment.