File tree 2 files changed +12
-7
lines changed
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -238,17 +238,18 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
238
238
match_count : number ;
239
239
unique : boolean ;
240
240
} ) : Promise < Memory [ ] > {
241
+ // Build the query and parameters carefully
241
242
const queryParams = [
242
243
new Float32Array ( params . embedding ) , // Ensure embedding is Float32Array
243
244
params . tableName ,
244
245
params . roomId ,
245
- params . match_count ,
246
246
] ;
247
247
248
248
let sql = `
249
- SELECT *, vec_distance_L2(embedding, ?) AS similarity
250
- FROM memories
251
- WHERE type = ?` ;
249
+ SELECT *, vec_distance_L2(embedding, ?) AS similarity
250
+ FROM memories
251
+ WHERE type = ?
252
+ AND roomId = ?` ;
252
253
253
254
if ( params . unique ) {
254
255
sql += " AND `unique` = 1" ;
@@ -258,13 +259,14 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
258
259
sql += " AND agentId = ?" ;
259
260
queryParams . push ( params . agentId ) ;
260
261
}
261
-
262
262
sql += ` ORDER BY similarity ASC LIMIT ?` ; // ASC for lower distance
263
- // Updated queryParams order matches the placeholders
263
+ queryParams . push ( params . match_count . toString ( ) ) ; // Convert number to string
264
264
265
+ // Execute the prepared statement with the correct number of parameters
265
266
const memories = this . db . prepare ( sql ) . all ( ...queryParams ) as ( Memory & {
266
267
similarity : number ;
267
268
} ) [ ] ;
269
+
268
270
return memories . map ( ( memory ) => ( {
269
271
...memory ,
270
272
createdAt :
@@ -275,6 +277,7 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
275
277
} ) ) ;
276
278
}
277
279
280
+
278
281
async searchMemoriesByEmbedding (
279
282
embedding : number [ ] ,
280
283
params : {
Original file line number Diff line number Diff line change @@ -896,12 +896,14 @@ Text: ${attachment.text}
896
896
897
897
async function getKnowledge ( runtime : AgentRuntime , message : Memory ) : Promise < string [ ] > {
898
898
const embedding = await embed ( runtime , message . content . text ) ;
899
+
899
900
const memories = await runtime . knowledgeManager . searchMemoriesByEmbedding (
900
901
embedding ,
901
902
{
902
- count : 3 ,
903
903
roomId : message . roomId ,
904
904
agentId : runtime . agentId ,
905
+ match_threshold : 0.95 ,
906
+ count : 1 ,
905
907
}
906
908
) ;
907
909
You can’t perform that action at this time.
0 commit comments