Skip to content

Commit

Permalink
Make it so memorize will skip items already memorized.
Browse files Browse the repository at this point in the history
Part of #55. Part of #23.
  • Loading branch information
jkomoros committed Jul 23, 2023
1 parent 2b28be8 commit 06df9c1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/grow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ const growMemorize = async (seed : Seed<SeedDataMemorize>, env : Environment) :

const embedding = item instanceof Embedding ? item : await computeEmbedding(extractString(item), env, seed.garden.profile);

//Check if the item is already memorized and if so skip
let previous : Embedding[] = [];
try {
previous = await seed.garden.profile.recall(embedding, memory, 1);
} catch(err) {
//Totally fine, for example maybe there just aren't any memories yet.
}

if (previous && previous.length) {
const first = previous[0];
if (first.text == embedding.text) {
seed.garden.profile.log(`Skipping memory because it was already memorized: ${embedding.text}`);
continue;
}
}

seed.garden.profile.memorize(embedding, memory);

results.push(embedding);
Expand Down

0 comments on commit 06df9c1

Please sign in to comment.