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(In-Memory Vector Store Node): Fix displaying execution data of connected embedding nodes #11701

Merged
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
Expand Up @@ -54,6 +54,6 @@ export class VectorStoreInMemory extends createVectorStoreNode({
const workflowId = context.getWorkflow().id;
const vectorStoreInstance = MemoryVectorStoreManager.getInstance(embeddings);

void vectorStoreInstance.addDocuments(`${workflowId}__${memoryKey}`, documents, clearStore);
await vectorStoreInstance.addDocuments(`${workflowId}__${memoryKey}`, documents, clearStore);
},
}) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { OpenAIEmbeddings } from '@langchain/openai';

import { MemoryVectorStoreManager } from './MemoryVectorStoreManager';
import { mock } from 'jest-mock-extended';

describe('MemoryVectorStoreManager', () => {
it('should create an instance of MemoryVectorStoreManager', () => {
const embeddings = mock<OpenAIEmbeddings>();

const instance = MemoryVectorStoreManager.getInstance(embeddings);
expect(instance).toBeInstanceOf(MemoryVectorStoreManager);
});

it('should return existing instance', () => {
const embeddings = mock<OpenAIEmbeddings>();

const instance1 = MemoryVectorStoreManager.getInstance(embeddings);
const instance2 = MemoryVectorStoreManager.getInstance(embeddings);
expect(instance1).toBe(instance2);
});

it('should update embeddings in existing instance', () => {
const embeddings1 = mock<OpenAIEmbeddings>();
const embeddings2 = mock<OpenAIEmbeddings>();

const instance = MemoryVectorStoreManager.getInstance(embeddings1);
MemoryVectorStoreManager.getInstance(embeddings2);

expect((instance as any).embeddings).toBe(embeddings2);
});

it('should update embeddings in existing vector store instances', async () => {
const embeddings1 = mock<OpenAIEmbeddings>();
const embeddings2 = mock<OpenAIEmbeddings>();

const instance1 = MemoryVectorStoreManager.getInstance(embeddings1);
await instance1.getVectorStore('test');

const instance2 = MemoryVectorStoreManager.getInstance(embeddings2);
const vectorStoreInstance2 = await instance2.getVectorStore('test');

expect((vectorStoreInstance2 as any).embeddings).toBe(embeddings2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ export class MemoryVectorStoreManager {
public static getInstance(embeddings: Embeddings): MemoryVectorStoreManager {
if (!MemoryVectorStoreManager.instance) {
MemoryVectorStoreManager.instance = new MemoryVectorStoreManager(embeddings);
} else {
// We need to update the embeddings in the existing instance.
// This is important as embeddings instance is wrapped in a logWrapper,
// which relies on supplyDataFunctions context which changes on each workflow run
MemoryVectorStoreManager.instance.embeddings = embeddings;
MemoryVectorStoreManager.instance.vectorStoreBuffer.forEach((vectorStoreInstance) => {
vectorStoreInstance.embeddings = embeddings;
});
}

return MemoryVectorStoreManager.instance;
}

Expand Down
Loading