Cohere: Update embeddings to v2 #2962

9db761cea42dede55747beb4f9edabbc2bbb2c41

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +4 -3Ignore whitespace
src/vectors/cohere-vectors.js+4 -3
@@ -17,7 +17,7 @@ async function getCohereBatchVector(texts, isQuery, directories, model) {
17 throw new Error('No API key found');17 throw new Error('No API key found');
18 }18 }
1919
20 const response = await fetch('https://api.cohere.ai/v1/embed', {20 const response = await fetch('https://api.cohere.ai/v2/embed', {
21 method: 'POST',21 method: 'POST',
22 headers: {22 headers: {
23 'Content-Type': 'application/json',23 'Content-Type': 'application/json',
@@ -26,6 +26,7 @@ async function getCohereBatchVector(texts, isQuery, directories, model) {
26 body: JSON.stringify({26 body: JSON.stringify({
27 texts: texts,27 texts: texts,
28 model: model,28 model: model,
29 embedding_types: ['float'],
29 input_type: isQuery ? 'search_query' : 'search_document',30 input_type: isQuery ? 'search_query' : 'search_document',
30 truncate: 'END',31 truncate: 'END',
31 }),32 }),
@@ -38,12 +39,12 @@ async function getCohereBatchVector(texts, isQuery, directories, model) {
38 }39 }
3940
40 const data = await response.json();41 const data = await response.json();
41 if (!Array.isArray(data?.embeddings)) {42 if (!Array.isArray(data?.embeddings?.float)) {
42 console.log('API response was not an array');43 console.log('API response was not an array');
43 throw new Error('API response was not an array');44 throw new Error('API response was not an array');
44 }45 }
4546
46 return data.embeddings;47 return data.embeddings.float;
47}48}
4849
49/**50/**