@@ -143,22 +143,17 @@ export class SqliteDatabaseAdapter
143
143
}
144
144
145
145
async getMemoriesByRoomIds ( params : {
146
+ agentId : UUID ;
146
147
roomIds : UUID [ ] ;
147
148
tableName : string ;
148
- agentId ?: UUID ;
149
149
} ) : Promise < Memory [ ] > {
150
150
if ( ! params . tableName ) {
151
151
// default to messages
152
152
params . tableName = "messages" ;
153
153
}
154
154
const placeholders = params . roomIds . map ( ( ) => "?" ) . join ( ", " ) ;
155
- let sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${ placeholders } )` ;
156
- let queryParams = [ params . tableName , ...params . roomIds ] ;
157
-
158
- if ( params . agentId ) {
159
- sql += ` AND agentId = ?` ;
160
- queryParams . push ( params . agentId ) ;
161
- }
155
+ let sql = `SELECT * FROM memories WHERE type = ? AND agentId = ? AND roomId IN (${ placeholders } )` ;
156
+ let queryParams = [ params . tableName , params . agentId , ...params . roomIds ] ;
162
157
163
158
const stmt = this . db . prepare ( sql ) ;
164
159
const rows = stmt . all ( ...queryParams ) as ( Memory & {
@@ -189,8 +184,8 @@ export class SqliteDatabaseAdapter
189
184
190
185
async createMemory ( memory : Memory , tableName : string ) : Promise < void > {
191
186
// Delete any existing memory with the same ID first
192
- const deleteSql = `DELETE FROM memories WHERE id = ? AND type = ?` ;
193
- this . db . prepare ( deleteSql ) . run ( memory . id , tableName ) ;
187
+ // const deleteSql = `DELETE FROM memories WHERE id = ? AND type = ?`;
188
+ // this.db.prepare(deleteSql).run(memory.id, tableName);
194
189
195
190
let isUnique = true ;
196
191
@@ -200,6 +195,7 @@ export class SqliteDatabaseAdapter
200
195
memory . embedding ,
201
196
{
202
197
tableName,
198
+ agentId : memory . agentId ,
203
199
roomId : memory . roomId ,
204
200
match_threshold : 0.95 , // 5% similarity threshold
205
201
count : 1 ,
@@ -281,7 +277,7 @@ export class SqliteDatabaseAdapter
281
277
match_threshold ?: number ;
282
278
count ?: number ;
283
279
roomId ?: UUID ;
284
- agentId ? : UUID ;
280
+ agentId : UUID ;
285
281
unique ?: boolean ;
286
282
tableName : string ;
287
283
}
@@ -290,20 +286,17 @@ export class SqliteDatabaseAdapter
290
286
// JSON.stringify(embedding),
291
287
new Float32Array ( embedding ) ,
292
288
params . tableName ,
289
+ params . agentId ,
293
290
] ;
294
291
295
292
let sql = `
296
293
SELECT *, vec_distance_L2(embedding, ?) AS similarity
297
294
FROM memories
298
- WHERE type = ?` ;
295
+ WHERE embedding IS NOT NULL type = ? AND agentId = ?` ;
299
296
300
297
if ( params . unique ) {
301
298
sql += " AND `unique` = 1" ;
302
299
}
303
- if ( params . agentId ) {
304
- sql += " AND agentId = ?" ;
305
- queryParams . push ( params . agentId ) ;
306
- }
307
300
308
301
if ( params . roomId ) {
309
302
sql += " AND roomId = ?" ;
@@ -418,7 +411,7 @@ export class SqliteDatabaseAdapter
418
411
count ?: number ;
419
412
unique ?: boolean ;
420
413
tableName : string ;
421
- agentId ? : UUID ;
414
+ agentId : UUID ;
422
415
start ?: number ;
423
416
end ?: number ;
424
417
} ) : Promise < Memory [ ] > {
@@ -428,19 +421,18 @@ export class SqliteDatabaseAdapter
428
421
if ( ! params . roomId ) {
429
422
throw new Error ( "roomId is required" ) ;
430
423
}
431
- let sql = `SELECT * FROM memories WHERE type = ? AND roomId = ?` ;
424
+ let sql = `SELECT * FROM memories WHERE type = ? AND agentId = ? AND roomId = ?` ;
432
425
433
- const queryParams = [ params . tableName , params . roomId ] as any [ ] ;
426
+ const queryParams = [
427
+ params . tableName ,
428
+ params . agentId ,
429
+ params . roomId ,
430
+ ] as any [ ] ;
434
431
435
432
if ( params . unique ) {
436
433
sql += " AND `unique` = 1" ;
437
434
}
438
435
439
- if ( params . agentId ) {
440
- sql += " AND agentId = ?" ;
441
- queryParams . push ( params . agentId ) ;
442
- }
443
-
444
436
if ( params . start ) {
445
437
sql += ` AND createdAt >= ?` ;
446
438
queryParams . push ( params . start ) ;
0 commit comments