@@ -316,6 +316,31 @@ export function createMemoryQuery(db: Database, vec: VecService, logger?: Logger
316316 projectId ?: string ,
317317 limit : number = 50
318318 ) : Memory [ ] {
319+ const embeddingsTableExists = db . prepare (
320+ "SELECT name FROM sqlite_master WHERE type='table' AND name='memory_embeddings'"
321+ ) . get ( )
322+
323+ if ( ! embeddingsTableExists ) {
324+ const conditions : string [ ] = [ ]
325+ const params : ( string | number ) [ ] = [ ]
326+
327+ if ( projectId ) {
328+ conditions . push ( 'project_id = ?' )
329+ params . push ( projectId )
330+ }
331+
332+ const where = conditions . length > 0 ? `WHERE ${ conditions . join ( ' AND ' ) } ` : ''
333+ const rows = db . prepare ( `
334+ SELECT id, project_id, scope, content, file_path, access_count, last_accessed_at, created_at, updated_at
335+ FROM memories
336+ ${ where }
337+ ORDER BY created_at ASC
338+ LIMIT ? OFFSET 0
339+ ` ) . all ( ...params , limit ) as MemoryRow [ ]
340+
341+ return rows . map ( mapRow )
342+ }
343+
319344 const conditions : string [ ] = [ 'e.memory_id IS NULL' ]
320345 const params : ( string | number ) [ ] = [ ]
321346
@@ -337,6 +362,27 @@ export function createMemoryQuery(db: Database, vec: VecService, logger?: Logger
337362 } ,
338363
339364 countMemoriesWithoutEmbeddings ( projectId ?: string ) : number {
365+ const embeddingsTableExists = db . prepare (
366+ "SELECT name FROM sqlite_master WHERE type='table' AND name='memory_embeddings'"
367+ ) . get ( )
368+
369+ if ( ! embeddingsTableExists ) {
370+ const conditions : string [ ] = [ ]
371+ const params : ( string | number ) [ ] = [ ]
372+
373+ if ( projectId ) {
374+ conditions . push ( 'project_id = ?' )
375+ params . push ( projectId )
376+ }
377+
378+ const where = conditions . length > 0 ? `WHERE ${ conditions . join ( ' AND ' ) } ` : ''
379+ const result = db . prepare ( `
380+ SELECT COUNT(*) as count FROM memories ${ where }
381+ ` ) . get ( ...params ) as { count : number }
382+
383+ return result . count
384+ }
385+
340386 const conditions : string [ ] = [ 'e.memory_id IS NULL' ]
341387 const params : ( string | number ) [ ] = [ ]
342388
0 commit comments