refactor(core): All calls to supplyData should use a distinct context type (no-changelog) (#11421)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-10-28 11:37:23 +01:00
committed by GitHub
parent 04c075a46b
commit 8f5fe05a92
70 changed files with 560 additions and 308 deletions

View File

@@ -1,10 +1,10 @@
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
import {
NodeConnectionType,
type SupplyData,
type IExecuteFunctions,
type INodeType,
type INodeTypeDescription,
type ISupplyDataFunctions,
type SupplyData,
} from 'n8n-workflow';
import type { Embeddings } from '@langchain/core/embeddings';
import { MemoryVectorStoreManager } from '../shared/MemoryVectorStoreManager';
@@ -59,7 +59,7 @@ export class VectorStoreInMemoryLoad implements INodeType {
],
};
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
const embeddings = (await this.getInputConnectionData(
NodeConnectionType.AiEmbedding,
itemIndex,

View File

@@ -1,8 +1,8 @@
import {
NodeConnectionType,
type IExecuteFunctions,
type INodeType,
type INodeTypeDescription,
type ISupplyDataFunctions,
type SupplyData,
} from 'n8n-workflow';
import type { PineconeStoreParams } from '@langchain/pinecone';
@@ -84,7 +84,7 @@ export class VectorStorePineconeLoad implements INodeType {
},
};
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
this.logger.debug('Supplying data for Pinecone Load Vector Store');
const namespace = this.getNodeParameter('pineconeNamespace', itemIndex) as string;

View File

@@ -1,7 +1,7 @@
import {
type IExecuteFunctions,
type INodeType,
type INodeTypeDescription,
type ISupplyDataFunctions,
type SupplyData,
NodeConnectionType,
} from 'n8n-workflow';
@@ -81,7 +81,7 @@ export class VectorStoreSupabaseLoad implements INodeType {
methods = { listSearch: { supabaseTableNameSearch } };
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
this.logger.debug('Supply Supabase Load Vector Store');
const tableName = this.getNodeParameter('tableName', itemIndex, '', {

View File

@@ -1,8 +1,8 @@
import {
NodeConnectionType,
type IExecuteFunctions,
type INodeType,
type INodeTypeDescription,
type ISupplyDataFunctions,
type SupplyData,
} from 'n8n-workflow';
import type { IZepConfig } from '@langchain/community/vectorstores/zep';
@@ -83,7 +83,7 @@ export class VectorStoreZepLoad implements INodeType {
],
};
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
this.logger.debug('Supplying data for Zep Load Vector Store');
const collectionName = this.getNodeParameter('collectionName', itemIndex) as string;

View File

@@ -7,11 +7,8 @@ export class MemoryVectorStoreManager {
private vectorStoreBuffer: Map<string, MemoryVectorStore>;
private embeddings: Embeddings;
private constructor(embeddings: Embeddings) {
private constructor(private embeddings: Embeddings) {
this.vectorStoreBuffer = new Map();
this.embeddings = embeddings;
}
public static getInstance(embeddings: Embeddings): MemoryVectorStoreManager {

View File

@@ -5,12 +5,13 @@ import type { Embeddings } from '@langchain/core/embeddings';
import type { VectorStore } from '@langchain/core/vectorstores';
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import type {
IExecuteFunctions,
INodeCredentialDescription,
INodeProperties,
INodeExecutionData,
IExecuteFunctions,
INodeTypeDescription,
SupplyData,
ISupplyDataFunctions,
INodeType,
ILoadOptionsFunctions,
INodeListSearchResult,
@@ -57,13 +58,13 @@ interface VectorStoreNodeConstructorArgs {
retrieveFields?: INodeProperties[];
updateFields?: INodeProperties[];
populateVectorStore: (
context: IExecuteFunctions,
context: ISupplyDataFunctions,
embeddings: Embeddings,
documents: Array<Document<Record<string, unknown>>>,
itemIndex: number,
) => Promise<void>;
getVectorStoreClient: (
context: IExecuteFunctions,
context: ISupplyDataFunctions,
filter: Record<string, never> | undefined,
embeddings: Embeddings,
itemIndex: number,
@@ -281,7 +282,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
});
resultData.push(...serializedDocs);
void logAiEvent(this, 'ai-vector-store-searched', { query: prompt });
logAiEvent(this, 'ai-vector-store-searched', { query: prompt });
}
return [resultData];
@@ -311,7 +312,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
try {
await args.populateVectorStore(this, embeddings, processedDocuments, itemIndex);
void logAiEvent(this, 'ai-vector-store-populated');
logAiEvent(this, 'ai-vector-store-populated');
} catch (error) {
throw error;
}
@@ -365,7 +366,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
ids: [documentId],
});
void logAiEvent(this, 'ai-vector-store-updated');
logAiEvent(this, 'ai-vector-store-updated');
} catch (error) {
throw error;
}
@@ -380,7 +381,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
);
}
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {
const mode = this.getNodeParameter('mode', 0) as 'load' | 'insert' | 'retrieve';
const filter = getMetadataFiltersValues(this, itemIndex);
const embeddings = (await this.getInputConnectionData(