Cohere: Update embeddings to v2 #2962
| @@ -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 | } |
| 19 | 19 | ||
| 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 | } |
| 39 | 40 | ||
| 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 | } |
| 45 | 46 | ||
| 46 | return data.embeddings; | 47 | return data.embeddings.float; |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | /** | 50 | /** |