Skip to content

Commit

Permalink
Move DB to top-level
Browse files Browse the repository at this point in the history
  • Loading branch information
tedspare committed Oct 10, 2024
1 parent dce59e1 commit d816783
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [2024-10-10] [Move DB to top-level](https://github.com/RubricLab/memory/commit/67913408246413448008f902963eb5a288b963d8)
- [2024-10-10] [Decouple extraction and save](https://github.com/RubricLab/memory/commit/d5fd7c08eff9458b9775ef439b480cd38922759d)
- [2024-10-09] [Add multi-turn examples](https://github.com/RubricLab/memory/commit/a0e32260e510a3ef1312030fcb5e2685ac2bb300)
- [2024-10-09] [Scaffold multi-turn evals](https://github.com/RubricLab/memory/commit/ecb5531acef6a924b81684660150eeb71d93e704)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@rubriclab/memory",
"module": "src/index.ts",
"version": "0.0.12",
"version": "0.0.13",
"private": false,
"type": "module",
"devDependencies": {
Expand Down
13 changes: 11 additions & 2 deletions src/evals/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Database from 'bun:sqlite'
import { parseArgs } from 'node:util'
import { runMultiTurnExamples } from '@/evals/multi-turn'
import { runOneShotExamples } from '@/evals/one-shot'
Expand Down Expand Up @@ -37,9 +38,17 @@ if (import.meta.path === Bun.main) {

const model = fast ? 'gpt-4o-mini' : 'gpt-4o-2024-08-06'

const db = new Database(':memory:', { create: true, strict: true })

await db
.prepare(
'create table if not exists facts (subject text, relation text, object text, primary key (subject, object))'
)
.get()

if (dataset === '1') {
await runOneShotExamples({ model })
await runOneShotExamples({ db, model })
} else if (dataset === '2') {
await runMultiTurnExamples({ model })
await runMultiTurnExamples({ db, model })
}
}
16 changes: 5 additions & 11 deletions src/evals/multi-turn/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { Database } from 'bun:sqlite'
import { Memory } from '@/index'
import type { Fact } from '@/types'
import type { Database, Fact } from '@/types'
import { format } from '@/utils/string'
import type { openai } from '@ai-sdk/openai'
import chalk from 'chalk'
import { EXAMPLES } from './examples'

const db = new Database(':memory:', { create: true, strict: true })

await db
.prepare(
'create table if not exists facts (subject text, relation text, object text, primary key (subject, object))'
)
.get()

export const runMultiTurnExamples = async ({ model }: { model: Parameters<typeof openai>[0] }) => {
export const runMultiTurnExamples = async ({
db,
model
}: { model: Parameters<typeof openai>[0]; db: Database }) => {
const memory = new Memory({ model, db })

let totalFacts = 0
Expand Down
9 changes: 5 additions & 4 deletions src/evals/one-shot/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Database } from 'bun:sqlite'
import { Memory } from '@/index'
import type { Database } from '@/types'
import { format } from '@/utils/string'
import type { openai } from '@ai-sdk/openai'
import chalk from 'chalk'
import { EXAMPLES } from './examples'

const db = new Database(':memory:', { create: true, strict: true })

export const runOneShotExamples = async ({ model }: { model: Parameters<typeof openai>[0] }) => {
export const runOneShotExamples = async ({
db,
model
}: { model: Parameters<typeof openai>[0]; db: Database }) => {
const memory = new Memory({ model, db })

let totalFacts = 0
Expand Down
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { Database as BunDatabase } from 'bun:sqlite'

export type Fact = {
subject: string
relation: string
object: string
data?: Record<string, string>
}

export type Database = BunDatabase

0 comments on commit d816783

Please sign in to comment.