Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ 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) {
log(`found cached embedding for ${this.service}/${this.model}`);
return 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)
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)}`);
Expand Down