Skip to content

[bug] When cache is false, get is not to able to access cache #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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