Skip to content

Commit

Permalink
simplify embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 25, 2024
1 parent 2271adc commit 4d6e188
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib/__tests__/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe("Memory - Extended Tests", () => {

const similarity = (memory as unknown as { similarity: number }).similarity;

expect(similarity).toBeGreaterThan(0.99999);
expect(similarity).toBeGreaterThan(0.9);
});

test("Test cosine similarity value inequality", async () => {
Expand Down
12 changes: 2 additions & 10 deletions src/lib/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,9 @@ export class MemoryManager {
if (memory.embedding) {
return memory;
}
const getMemoryEmbeddingString = (memory: Memory) => {
if (typeof memory.content === "string") {
return memory.content;
}
if (typeof memory.content === "object" && memory.content !== null) {
return JSON.stringify(memory.content.content ?? memory.content);
}
return "";
};

const memoryText = getMemoryEmbeddingString(memory);
const memoryText = memory.content.content;
if (!memoryText) throw new Error("Memory content is empty");
memory.embedding = memoryText
? await this.runtime.embed(memoryText)
: embeddingZeroVector.slice();
Expand Down

0 comments on commit 4d6e188

Please sign in to comment.