Merge branch 'master' of github.com:Mintplex-Labs/anything-llm
This commit is contained in:
commit
bd0faba9be
@ -12,16 +12,10 @@ class MistralEmbedder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async embedTextInput(textInput) {
|
async embedTextInput(textInput) {
|
||||||
try {
|
const result = await this.embedChunks(
|
||||||
const response = await this.openai.embeddings.create({
|
Array.isArray(textInput) ? textInput : [textInput]
|
||||||
model: this.model,
|
);
|
||||||
input: textInput,
|
return result?.[0] || [];
|
||||||
});
|
|
||||||
return response?.data[0]?.embedding || [];
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to get embedding from Mistral.", error.message);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async embedChunks(textChunks = []) {
|
async embedChunks(textChunks = []) {
|
||||||
@ -30,10 +24,13 @@ class MistralEmbedder {
|
|||||||
model: this.model,
|
model: this.model,
|
||||||
input: textChunks,
|
input: textChunks,
|
||||||
});
|
});
|
||||||
return response?.data?.map((emb) => emb.embedding) || [];
|
const embeddings = response?.data?.map((emb) => emb.embedding) || [];
|
||||||
|
if (embeddings.length === 0)
|
||||||
|
throw new Error("Mistral returned empty embeddings for batch");
|
||||||
|
return embeddings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to get embeddings from Mistral.", error.message);
|
console.error("Failed to get embeddings from Mistral.", error.message);
|
||||||
return new Array(textChunks.length).fill([]);
|
throw new Error(`Mistral Failed to embed: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user