diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d13d5..14731f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- [2024-10-10] [Fix post-insert return](https://github.com/RubricLab/memory/commit/a79a936cff2baadbd5411caec354579b47d8c846) - [2024-10-10] [Support more DBs. Simplify types.](https://github.com/RubricLab/memory/commit/c9500b038646adac4a4250b9956914bafbb53bea) - [2024-10-10] [Add main to pkg](https://github.com/RubricLab/memory/commit/ef8082790fbd93c6ae2b4b47112bc1986dd8f0ab) - [2024-10-10] [Move DB to top-level](https://github.com/RubricLab/memory/commit/67913408246413448008f902963eb5a288b963d8) diff --git a/package.json b/package.json index 3fd0d2f..a3e45b2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@rubriclab/memory", "module": "src/index.ts", "main": "src/index.ts", - "version": "0.0.15", + "version": "0.0.16", "private": false, "type": "module", "devDependencies": { diff --git a/src/evals/index.ts b/src/evals/index.ts index 986f099..865faa2 100644 --- a/src/evals/index.ts +++ b/src/evals/index.ts @@ -25,6 +25,7 @@ const args = parseArgs({ if (import.meta.path === Bun.main) { const { help, sota, dataset } = args.values + if (help) { console.log(` Usage: bun evals/index.ts [options] @@ -41,7 +42,7 @@ if (import.meta.path === Bun.main) { const bunDB = new Database(':memory:', { create: true, strict: true }) const db = { - execute: async (cmd: string) => await bunDB.prepare(cmd).get() + execute: async (cmd: string) => await bunDB.prepare(cmd).all() } await db.execute( diff --git a/src/evals/multi-turn/index.ts b/src/evals/multi-turn/index.ts index 06e8ba8..1d3f326 100644 --- a/src/evals/multi-turn/index.ts +++ b/src/evals/multi-turn/index.ts @@ -17,12 +17,14 @@ export const runMultiTurnExamples = async ({ db, model }: { model: LLM; db: Data console.log(chalk.yellow(`\n\n"${message.content}"`)) - const { facts: attempts } = await memory.extract({ + // Clean up DB in between conversations + const omitted: number[] = [] + await db.execute('delete from facts') + + const { facts: attempts } = await memory.insert({ content: message.content }) - const omitted: number[] = [] - for (const [i, fact] of message.facts.entries()) { let correctFacts = 0 @@ -39,14 +41,21 @@ export const runMultiTurnExamples = async ({ db, model }: { model: LLM; db: Data const correctRelation = fact.relation === relation const correctObject = fact.object === object + if (omitted.includes(k)) { + console.log( + chalk.blackBright.italic( + `🤖 ${k + 1} of ${newFacts.length}: ${subject} ${relation} ${object}` + ) + ) + continue + } + console.log( `🤖 ${k + 1} of ${newFacts.length}: ${chalk.magenta(format(subject, correctSubject))} ${chalk.yellow( format(relation, correctRelation) )} ${chalk.blue(format(object, correctObject))}` ) - if (omitted.includes(k)) continue - correctFacts += Number(correctSubject && correctRelation && correctObject) if (correctFacts) { diff --git a/src/index.ts b/src/index.ts index bba48a2..2e4e746 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,7 +45,7 @@ export class Memory { "${content}"` }) - const tags = entities?.map(({ name }) => `"${name}"`).join(', ') || '' + const tags = entities?.map(({ name }) => `'${name}'`).join(', ') || '' const relevantFacts = (await this.db.execute( `select * from facts where subject in (${tags}) or object in (${tags})` @@ -88,12 +88,11 @@ export class Memory { await this.db.execute(` insert into facts (subject, relation, object) - values (${subject}, ${relation}, ${object}) - on conflict (subject, object) do update set relation = ${relation} + values ("${subject}", "${relation}", "${object}") + on conflict (subject, object) do update set relation = "${relation}" `) } - const priorFacts = await this.db.execute('select * from facts') - console.log({ priorFacts }) + return { facts } } }