Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Zep Vector Store Node): Cloud vector store integration #12353

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ZepVectorStore } from '@langchain/community/vectorstores/zep';
import { ZepCloudVectorStore } from '@langchain/community/vectorstores/zep_cloud';
import { mock } from 'jest-mock-extended';
import type { ISupplyDataFunctions } from 'n8n-workflow';

import { VectorStoreZep } from './VectorStoreZep.node';

describe('VectorStoreZep', () => {
const vectorStore = new VectorStoreZep();
const helpers = mock<ISupplyDataFunctions['helpers']>();
const executeFunctions = mock<ISupplyDataFunctions>({ helpers });

beforeEach(() => {
jest.resetAllMocks();

executeFunctions.addInputData.mockReturnValue({ index: 0 });
});

it('should get vector store cloud client', async () => {
executeFunctions.getNodeParameter.mockImplementation((paramName: string) => {
switch (paramName) {
case 'mode':
return 'retrieve';
case 'collectionName':
return 'test-collection';
case 'options':
return {};
default:
return undefined;
}
});

executeFunctions.getCredentials.mockResolvedValue(
mock({
apiKey: 'some-key',
cloud: true,
}),
);

const { response } = await vectorStore.supplyData.call(executeFunctions, 0);

expect(response).toBeDefined();
expect(response).toBeInstanceOf(ZepCloudVectorStore);
});

it('should get vector store self-hosted client', async () => {
executeFunctions.getNodeParameter.mockImplementation((paramName: string) => {
switch (paramName) {
case 'mode':
return 'retrieve';
case 'collectionName':
return 'test-collection';
case 'options':
return {};
default:
return undefined;
}
});

executeFunctions.getCredentials.mockResolvedValue(
mock({
apiKey: 'some-key',
apiUrl: 'https://example.com',
cloud: false,
}),
);

const { response } = await vectorStore.supplyData.call(executeFunctions, 0);

expect(response).toBeDefined();
expect(response).toBeInstanceOf(ZepVectorStore);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IZepConfig } from '@langchain/community/vectorstores/zep';
import { ZepVectorStore } from '@langchain/community/vectorstores/zep';
import { ZepCloudVectorStore } from '@langchain/community/vectorstores/zep_cloud';
import type { IDataObject, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';

Expand Down Expand Up @@ -84,17 +84,21 @@ export class VectorStoreZep extends createVectorStoreNode({
const credentials = await context.getCredentials<{
apiKey?: string;
apiUrl: string;
cloud: boolean;
}>('zepApi');

const zepConfig: IZepConfig = {
apiUrl: credentials.apiUrl,
const zepConfig = {
apiKey: credentials.apiKey,
collectionName,
embeddingDimensions: options.embeddingDimensions ?? 1536,
metadata: filter,
};

return new ZepVectorStore(embeddings, zepConfig);
if (credentials.cloud) {
return new ZepCloudVectorStore(embeddings, zepConfig);
} else {
return new ZepVectorStore(embeddings, { ...zepConfig, apiUrl: credentials.apiUrl });
}
},
async populateVectorStore(context, embeddings, documents, itemIndex) {
const collectionName = context.getNodeParameter('collectionName', itemIndex) as string;
Expand All @@ -107,18 +111,25 @@ export class VectorStoreZep extends createVectorStoreNode({
const credentials = await context.getCredentials<{
apiKey?: string;
apiUrl: string;
cloud: boolean;
}>('zepApi');

const zepConfig = {
apiUrl: credentials.apiUrl,
apiKey: credentials.apiKey,
collectionName,
embeddingDimensions: options.embeddingDimensions ?? 1536,
isAutoEmbedded: options.isAutoEmbedded ?? true,
};

try {
await ZepVectorStore.fromDocuments(documents, embeddings, zepConfig);
if (credentials.cloud) {
await ZepCloudVectorStore.fromDocuments(documents, embeddings, zepConfig);
} else {
await ZepVectorStore.fromDocuments(documents, embeddings, {
...zepConfig,
apiUrl: credentials.apiUrl,
});
}
} catch (error) {
const errorCode = (error as IDataObject).code as number;
const responseData = (error as IDataObject).responseData as string;
Expand Down
Loading