@n8n/n8n-nodes-langchain
Version:

140 lines • 5.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmbeddingsGoogleVertex = void 0;
const resource_manager_1 = require("@google-cloud/resource-manager");
const google_vertexai_1 = require("@langchain/google-vertexai");
const utilities_1 = require("n8n-nodes-base/dist/utils/utilities");
const n8n_workflow_1 = require("n8n-workflow");
const ai_utilities_1 = require("@n8n/ai-utilities");
class EmbeddingsGoogleVertex {
constructor() {
this.methods = {
listSearch: {
async gcpProjectsList() {
const results = [];
const credentials = await this.getCredentials('googleApi');
const privateKey = (0, utilities_1.formatPrivateKey)(credentials.privateKey);
const email = credentials.email.trim();
const client = new resource_manager_1.ProjectsClient({
credentials: {
client_email: email,
private_key: privateKey,
},
});
const [projects] = await client.searchProjects();
for (const project of projects) {
if (project.projectId) {
results.push({
name: project.displayName ?? project.projectId,
value: project.projectId,
});
}
}
return { results };
},
},
};
this.description = {
displayName: 'Embeddings Google Vertex',
name: 'embeddingsGoogleVertex',
icon: 'file:google.svg',
group: ['transform'],
version: 1,
description: 'Use Google Vertex Embeddings',
defaults: {
name: 'Embeddings Google Vertex',
},
requestDefaults: {
ignoreHttpStatusErrors: true,
baseURL: '={{ $credentials.host }}',
},
credentials: [
{
name: 'googleApi',
required: true,
},
],
codex: {
categories: ['AI'],
subcategories: {
AI: ['Embeddings'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsgooglevertex/',
},
],
},
},
inputs: [],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiEmbedding],
outputNames: ['Embeddings'],
properties: [
(0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiVectorStore]),
{
displayName: 'Each model is using different dimensional density for embeddings. Please make sure to use the same dimensionality for your vector store. The default model is using 768-dimensional embeddings. You can find available models <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api">here</a>.',
name: 'notice',
type: 'notice',
default: '',
},
{
displayName: 'Project ID',
name: 'projectId',
type: 'resourceLocator',
default: { mode: 'list', value: '' },
required: true,
description: 'Select or enter your Google Cloud project ID',
modes: [
{
displayName: 'From List',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'gcpProjectsList',
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
},
],
},
{
displayName: 'Model Name',
name: 'modelName',
type: 'string',
description: 'The model which will generate the embeddings. <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api">Learn more</a>.',
default: 'text-embedding-005',
},
],
};
}
async supplyData(itemIndex) {
const credentials = await this.getCredentials('googleApi');
const privateKey = (0, utilities_1.formatPrivateKey)(credentials.privateKey);
const email = credentials.email.trim();
const region = credentials.region;
const modelName = this.getNodeParameter('modelName', itemIndex);
const projectId = this.getNodeParameter('projectId', itemIndex, '', {
extractValue: true,
});
const embeddings = new google_vertexai_1.VertexAIEmbeddings({
authOptions: {
projectId,
credentials: {
client_email: email,
private_key: privateKey,
},
},
location: region,
model: modelName,
});
return {
response: (0, ai_utilities_1.logWrapper)(embeddings, this),
};
}
}
exports.EmbeddingsGoogleVertex = EmbeddingsGoogleVertex;
//# sourceMappingURL=EmbeddingsGoogleVertex.node.js.map