From ec276dcbab46e7d71fc8e3c2da3f7fca04cdfa6d Mon Sep 17 00:00:00 2001 From: Florian Charlaix Date: Thu, 19 Dec 2024 16:39:36 +0100 Subject: [PATCH] Postgres PGVector Store : do not initialize client to avoid idle connections --- .../VectorStorePGVector/VectorStorePGVector.node.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts index 6d5da1615b036..405f9a814689d 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.ts @@ -194,7 +194,8 @@ class ExtendedPGVectorStore extends PGVectorStore { const { dimensions, ...rest } = args; const postgresqlVectorStore = new this(embeddings, rest); - await postgresqlVectorStore._initializeClient(); + // Workaround to fix https://github.com/langchain-ai/langchainjs/issues/5029#issuecomment-2468147921 + // await postgresqlVectorStore._initializeClient(); await postgresqlVectorStore.ensureTableInDatabase(dimensions); if (postgresqlVectorStore.collectionTableName) { await postgresqlVectorStore.ensureCollectionTableInDatabase(); @@ -307,6 +308,7 @@ export class VectorStorePGVector extends createVectorStoreNode({ metadataColumnName: 'metadata', }) as ColumnOptions; - await PGVectorStore.fromDocuments(documents, embeddings, config); + const vectorStore = await PGVectorStore.fromDocuments(documents, embeddings, config); + await vectorStore.end(); }, }) {}