Class that extends the Embeddings class and provides methods for generating embeddings using the Google Palm API.
class GoogleGenerativeAIEmbeddingsGoogle API key to use
The async caller should be used by subclasses to make any async calls, which will thus benefit from the concurrency and retry logic.
Model Name to use
Note: The format must follow the pattern - {model}
Model Name to use
Alias for model
Note: The format must follow the pattern - {model}
Whether to strip new lines from the input text. Default to true
Type of task for which the embedding will be used
Note: currently only supported by embedding-001 model
An optional title for the text. Only applicable when TaskType is
RETRIEVAL_DOCUMENT
Note: currently only supported by embedding-001 model
Method that takes an array of documents as input and returns a promise that resolves to a 2D array of embeddings for each document. It calls the _embedText method for each document in the array.
Method that takes a document as input and returns a promise that resolves to an embedding for the document. It calls the _embedText method with the document as the input.
const model = new GoogleGenerativeAIEmbeddings({
apiKey: "<YOUR API KEY>",
modelName: "embedding-001",
});
// Embed a single query
const res = await model.embedQuery(
"What would be a good company name for a company that makes colorful socks?"
);
console.log({ res });
// Embed multiple documents
const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
console.log({ documentRes });