diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts index 4bb1d47250..296c2e00ce 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/createVectorStoreNode.ts @@ -5,6 +5,7 @@ import type { Embeddings } from '@langchain/core/embeddings'; import type { VectorStore } from '@langchain/core/vectorstores'; import { DynamicTool } from 'langchain/tools'; import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; +import { PGVectorStore } from '@langchain/community/vectorstores/pgvector'; import type { IExecuteFunctions, INodeCredentialDescription, @@ -481,7 +482,14 @@ export const createVectorStoreNode = ( if (mode === 'retrieve') { const vectorStore = await args.getVectorStoreClient(this, filter, embeddings, itemIndex); + + async function closeFunction() { + const pgVectorStore = vectorStore as PGVectorStore; + void pgVectorStore?.client?.release(); + } + return { + closeFunction, response: logWrapper(vectorStore, this), closeFunction: async () => { args.releaseVectorStoreClient?.(vectorStore);