diff --git a/CHANGELOG.md b/CHANGELOG.md index 206b931..b588aaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- [2024-10-11] [Add getAll route](https://github.com/RubricLab/memory/commit/71eb1f5d7afbb26390d2b2617081b46301e9022c) - [2024-10-10] [Expand on unique tagging](https://github.com/RubricLab/memory/commit/3c550db0b9cce3ce9f54fc56ecc6716d8475b397) - [2024-10-10] [Add typesafe SQL setup](https://github.com/RubricLab/memory/commit/9acd10a3be5e0335970ca8f551a03847e04fcdda) - [2024-10-10] [Use relative import](https://github.com/RubricLab/memory/commit/2161e8cc919ac63da4b092b61ff811566417bc08) diff --git a/package.json b/package.json index ec77492..8d65c2c 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.19", + "version": "0.0.20", "private": false, "type": "module", "devDependencies": { diff --git a/src/index.ts b/src/index.ts index 7f0ab32..0fb6988 100644 --- a/src/index.ts +++ b/src/index.ts @@ -122,7 +122,40 @@ export class Memory { const vector = await this.embed(query) // biome-ignore lint/suspicious/noExplicitAny: - return await this.db.$queryRawTyped(searchVector(vector as any, threshold, limit)) + const res = await this.db.$queryRawTyped(searchVector(vector as any, threshold, limit)) + return res + } + + async getAll(args?: { where: { tags: string[] } }) { + const { where } = args || {} + + const relations = await this.db.relationship.findMany({ + where: { + ...(where?.tags + ? { + tag: { + body: { + in: where.tags + } + } + } + : {}) + }, + select: { + fact: { + select: { + body: true + } + }, + tag: { + select: { + body: true + } + } + } + }) + + return relations } async ingest({ content }: { content: string }) { @@ -133,6 +166,7 @@ export class Memory { const uniqueTags = [...new Set(tags)] + // TODO: pass these back to AI to update existing facts const similarTags = await Promise.all(uniqueTags.map(tag => this.search(tag))) const similarTagIds = similarTags.flatMap(t => t[0]?.id || []) console.log('similarTags', similarTags) @@ -172,31 +206,32 @@ export class Memory { }) const created = await this.db.$transaction(creates) - console.log({ created }) - - const relatedFacts = await this.db.relationship.findMany({ - where: { - tag: { - id: { - in: allTagIds - } - } - }, - select: { - fact: { - select: { - body: true - } - }, - tag: { - select: { - body: true - } - } - } - }) - console.log('relatedFacts', relatedFacts) + console.log(`Added ${created?.length} facts`) + + // const relatedFacts = await this.db.relationship.findMany({ + // where: { + // tag: { + // id: { + // in: allTagIds + // } + // } + // }, + // select: { + // fact: { + // select: { + // body: true + // } + // }, + // tag: { + // select: { + // body: true + // } + // } + // } + // }) + + // console.log('relatedFacts', relatedFacts) return { tags, facts } }