Skip to content

Commit ed7a16e

Browse files
committed
chore: Make sure that cache works
1 parent 082fce9 commit ed7a16e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/unit/common/search/vectorSearchEmbeddings.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ describe("VectorSearchEmbeddings", () => {
8383

8484
expect(result?.filter((emb) => emb.type !== "vector")).toHaveLength(0);
8585
});
86+
87+
it("embeddings are cached in memory", async () => {
88+
const embeddings = new VectorSearchEmbeddings(embeddingValidationEnabled);
89+
const result1 = await embeddings.embeddingsForNamespace({ database, collection, provider });
90+
const result2 = await embeddings.embeddingsForNamespace({ database, collection, provider });
91+
92+
expect(provider.getSearchIndexes).toHaveBeenCalledOnce();
93+
expect(result1).toEqual(result2);
94+
});
95+
96+
it("embeddings are cached in memory until cleaned up", async () => {
97+
const embeddings = new VectorSearchEmbeddings(embeddingValidationEnabled);
98+
const result1 = await embeddings.embeddingsForNamespace({ database, collection, provider });
99+
embeddings.cleanupEmbeddingsForNamespace({ database, collection });
100+
const result2 = await embeddings.embeddingsForNamespace({ database, collection, provider });
101+
102+
expect(provider.getSearchIndexes).toHaveBeenCalledTimes(2);
103+
expect(result1).toEqual(result2);
104+
});
86105
});
87106
});
88107

0 commit comments

Comments
 (0)