Skip to content

Commit 04c62f0

Browse files
committedNov 2, 2024
add agentId to filtering
1 parent 5da90dc commit 04c62f0

File tree

5 files changed

+23773
-74
lines changed

5 files changed

+23773
-74
lines changed
 

‎core/src/adapters/sqlite.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -152,32 +152,29 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
152152
tableName: string;
153153
agentId?: UUID;
154154
}): Promise<Memory[]> {
155+
console.log("getMemoriesByRoomIds", params);
155156
if (!params.tableName) {
156157
// default to messages
157158
params.tableName = "messages";
158159
}
159160
const placeholders = params.roomIds.map(() => "?").join(", ");
160161
let sql = `SELECT * FROM memories WHERE type = ? AND roomId IN (${placeholders})`;
161-
const stmt = this.db.prepare(sql);
162-
const queryParams = [params.tableName, ...params.roomIds];
162+
let queryParams = [params.tableName, ...params.roomIds];
163163

164164
if (params.agentId) {
165165
sql += ` AND userId = ?`;
166166
queryParams.push(params.agentId);
167167
}
168168

169-
const memories: Memory[] = [];
169+
const stmt = this.db.prepare(sql);
170170
const rows = stmt.all(...queryParams) as (Memory & {
171171
content: string;
172172
})[];
173-
rows.forEach((row) => {
174-
memories.push({
175-
...row,
176-
content: JSON.parse(row.content),
177-
});
178-
});
179-
180-
return memories;
173+
174+
return rows.map(row => ({
175+
...row,
176+
content: JSON.parse(row.content)
177+
}));
181178
}
182179

183180
async getMemoryById(memoryId: UUID): Promise<Memory | null> {

‎core/src/adapters/sqlite/sqliteTables.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ CREATE TABLE IF NOT EXISTS "memories" (
2222
"embedding" BLOB NOT NULL, -- TODO: EMBEDDING ARRAY, CONVERT TO BEST FORMAT FOR SQLITE-VSS (JSON?)
2323
"userId" TEXT,
2424
"roomId" TEXT,
25+
"agentId" TEXT,
2526
"unique" INTEGER DEFAULT 1 NOT NULL,
2627
FOREIGN KEY ("userId") REFERENCES "accounts"("id"),
27-
FOREIGN KEY ("roomId") REFERENCES "rooms"("id")
28+
FOREIGN KEY ("roomId") REFERENCES "rooms"("id"),
29+
FOREIGN KEY ("agentId") REFERENCES "accounts"("id")
2830
);
2931
3032
-- Table: goals

0 commit comments

Comments
 (0)