From 9db761cea42dede55747beb4f9edabbc2bbb2c41 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 9 Oct 2024 00:52:07 +0300 Subject: [PATCH] Cohere: Update embeddings to v2 #2962 --- src/vectors/cohere-vectors.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vectors/cohere-vectors.js b/src/vectors/cohere-vectors.js index 1ec01130c..96ce5bff5 100644 --- a/src/vectors/cohere-vectors.js +++ b/src/vectors/cohere-vectors.js @@ -17,7 +17,7 @@ async function getCohereBatchVector(texts, isQuery, directories, model) { throw new Error('No API key found'); } - const response = await fetch('https://api.cohere.ai/v1/embed', { + const response = await fetch('https://api.cohere.ai/v2/embed', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -26,6 +26,7 @@ async function getCohereBatchVector(texts, isQuery, directories, model) { body: JSON.stringify({ texts: texts, model: model, + embedding_types: ['float'], input_type: isQuery ? 'search_query' : 'search_document', truncate: 'END', }), @@ -38,12 +39,12 @@ async function getCohereBatchVector(texts, isQuery, directories, model) { } const data = await response.json(); - if (!Array.isArray(data?.embeddings)) { + if (!Array.isArray(data?.embeddings?.float)) { console.log('API response was not an array'); throw new Error('API response was not an array'); } - return data.embeddings; + return data.embeddings.float; } /**