@@ -19,11 +19,14 @@ export default class LongTermMemory extends PluginBase {
1919 }
2020
2121 async load ( athena : Athena ) {
22- this . db = new DatabaseSync ( this . config . persist_db ? this . config . db_file : ':memory:' , {
23- allowExtension : true
24- } ) ;
22+ this . db = new DatabaseSync (
23+ this . config . persist_db ? this . config . db_file : ":memory:" ,
24+ {
25+ allowExtension : true ,
26+ } ,
27+ ) ;
2528 load ( this . db ) ;
26-
29+
2730 // TODO: Support migration for varying dimensions
2831 this . db . exec ( `
2932 CREATE VIRTUAL TABLE IF NOT EXISTS vec_items USING
@@ -35,9 +38,9 @@ export default class LongTermMemory extends PluginBase {
3538 ` ) ;
3639
3740 const insertStmt = this . db . prepare (
38- ' INSERT INTO vec_items(embedding, desc, data) VALUES (?, ?, ?)'
41+ " INSERT INTO vec_items(embedding, desc, data) VALUES (?, ?, ?)" ,
3942 ) ;
40-
43+
4144 this . openai = new OpenAI ( {
4245 baseURL : this . config . base_url ,
4346 apiKey : this . config . api_key ,
@@ -73,9 +76,11 @@ export default class LongTermMemory extends PluginBase {
7376 input : args . desc ,
7477 encoding_format : "float" ,
7578 } ) ;
76- insertStmt . run ( Float32Array . from ( embedding . data [ 0 ] . embedding ) ,
77- args . desc ,
78- JSON . stringify ( args . data ) ) ;
79+ insertStmt . run (
80+ Float32Array . from ( embedding . data [ 0 ] . embedding ) ,
81+ args . desc ,
82+ JSON . stringify ( args . data ) ,
83+ ) ;
7984 return { status : "success" } ;
8085 } ,
8186 } ) ;
@@ -149,21 +154,23 @@ export default class LongTermMemory extends PluginBase {
149154 input : args . query ,
150155 encoding_format : "float" ,
151156 } ) ;
152- const results = this . db . prepare (
153- `SELECT
157+ const results = this . db
158+ . prepare (
159+ `SELECT
154160 distance,
155161 desc,
156162 data
157163 FROM vec_items
158164 WHERE embedding MATCH ?
159165 ORDER BY distance
160- LIMIT ${ this . config . max_query_results } `
161- ) . all ( Float32Array . from ( embedding . data [ 0 ] . embedding ) ) ;
166+ LIMIT ${ this . config . max_query_results } ` ,
167+ )
168+ . all ( Float32Array . from ( embedding . data [ 0 ] . embedding ) ) ;
162169 if ( ! results || results . length === 0 ) {
163170 throw new Error ( "No results found" ) ;
164171 }
165- return results . map ( result => {
166- if ( ! result || typeof result !== ' object' ) {
172+ return results . map ( ( result ) => {
173+ if ( ! result || typeof result !== " object" ) {
167174 throw new Error ( "Invalid result format" ) ;
168175 }
169176 return {
0 commit comments