From 93b8c12485e3d035449e787a8c2983135f494054 Mon Sep 17 00:00:00 2001 From: Jaco Koster Date: Sun, 9 Feb 2025 20:57:44 +0100 Subject: [PATCH 1/2] [bug] When cache is false, get is not to access cache --- src/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 96db448..7060178 100644 --- a/src/index.js +++ b/src/index.js @@ -32,14 +32,13 @@ export default function Embeddings(arg1, arg2) { } Embeddings.prototype.fetch = async function (input) { - if (this.options.cache && !this.cache) { - this.cache = new Cache(this.options.cache_file); - await this.cache.load(); - } - - - let embedding = await this.cache.get(input, this.model); - if (this.options.cache && embedding) { + let embedding; + if (this.options.cache) { + if (!this.cache) { + this.cache = new Cache(this.options.cache_file); + await this.cache.load(); + } + embedding = await this.cache.get(input, this.model) log(`found cached embedding for ${this.service}/${this.model}`); return embedding; } From a75a78803610fe2d6fcfa2f7cb7bdff4e7aed83a Mon Sep 17 00:00:00 2001 From: Jaco Koster Date: Sun, 9 Feb 2025 21:02:18 +0100 Subject: [PATCH 2/2] Only return when an embedding has been found --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 7060178..c1d4dbb 100644 --- a/src/index.js +++ b/src/index.js @@ -39,8 +39,10 @@ Embeddings.prototype.fetch = async function (input) { await this.cache.load(); } embedding = await this.cache.get(input, this.model) - log(`found cached embedding for ${this.service}/${this.model}`); - return embedding; + if( embedding ) { + log(`found cached embedding for ${this.service}/${this.model}`); + return embedding; + } } log(`fetching embedding from ${this.service}/${this.model} with ${JSON.stringify(this.options)}`);