mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(In-Memory Vector Store Node): Fix displaying execution data of connected embedding nodes (#11701)
This commit is contained in:
@@ -54,6 +54,6 @@ export class VectorStoreInMemory extends createVectorStoreNode({
|
|||||||
const workflowId = context.getWorkflow().id;
|
const workflowId = context.getWorkflow().id;
|
||||||
const vectorStoreInstance = MemoryVectorStoreManager.getInstance(embeddings);
|
const vectorStoreInstance = MemoryVectorStoreManager.getInstance(embeddings);
|
||||||
|
|
||||||
void vectorStoreInstance.addDocuments(`${workflowId}__${memoryKey}`, documents, clearStore);
|
await vectorStoreInstance.addDocuments(`${workflowId}__${memoryKey}`, documents, clearStore);
|
||||||
},
|
},
|
||||||
}) {}
|
}) {}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,7 +14,16 @@ export class MemoryVectorStoreManager {
|
|||||||
public static getInstance(embeddings: Embeddings): MemoryVectorStoreManager {
|
public static getInstance(embeddings: Embeddings): MemoryVectorStoreManager {
|
||||||
if (!MemoryVectorStoreManager.instance) {
|
if (!MemoryVectorStoreManager.instance) {
|
||||||
MemoryVectorStoreManager.instance = new MemoryVectorStoreManager(embeddings);
|
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;
|
return MemoryVectorStoreManager.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user