Add vertexai text embeddings capability

This commit is contained in:
Hristo 2024-05-21 16:23:34 -04:00
parent 4c7942d2e8
commit 8bf4269208

View file

@ -1,6 +1,7 @@
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai'; import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
import { ChatOllama } from '@langchain/community/chat_models/ollama'; import { ChatOllama } from '@langchain/community/chat_models/ollama';
import { VertexAI } from "@langchain/google-vertexai"; import { VertexAI } from "@langchain/google-vertexai";
import { GoogleVertexAIEmbeddings } from "@langchain/community/embeddings/googlevertexai";
import { OllamaEmbeddings } from '@langchain/community/embeddings/ollama'; import { OllamaEmbeddings } from '@langchain/community/embeddings/ollama';
import { HuggingFaceTransformersEmbeddings } from './huggingfaceTransformer'; import { HuggingFaceTransformersEmbeddings } from './huggingfaceTransformer';
import { hasGCPCredentials } from '../auth'; import { hasGCPCredentials } from '../auth';
@ -186,6 +187,16 @@ export const getAvailableEmbeddingModelProviders = async () => {
} }
} }
if (await hasGCPCredentials()) {
try {
models['vertexai'] = {
'Text Gecko default': new GoogleVertexAIEmbeddings(),
}
} catch (err) {
logger.error(`Error loading VertexAI embeddings: ${err}`);
}
}
try { try {
models['local'] = { models['local'] = {
'BGE Small': new HuggingFaceTransformersEmbeddings({ 'BGE Small': new HuggingFaceTransformersEmbeddings({