const { CohereClient } = require("cohere-ai");
const COHERE_API_KEY = "your cohere api key";
const cohere = new CohereClient({
token: COHERE_API_KEY,
});
const model = "embed-english-v3.0"; // replace with your favorite cohere model
const input_text = `The future belongs to those who believe in the beauty of their
dreams.`;
const doc_vec_resp = await cohere.embed({
texts: [input_text], // you can pass multiple texts to embed in one batch call
model: model,
inputType: "search_document", // for embedding of documents stored in pg_vector
});
const question = "Who does the future belong to?";
const question_vec_resp = await cohere.embed({
texts: [question],
model: model,
inputType: "search_query", // for embedding of questions used to search documents
});
// Cohere's response is an object with an array of vector embeddings
// The object has other useful info like the model used, input text, billing, etc.
const doc_vec = doc_vec_resp.embeddings[0];
const question_vec = question_vec_resp.embeddings[0];