From 609ae8703de416c1a62dab565f7e7aa13177b333 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Thu, 4 Jan 2024 15:58:18 +0100 Subject: [PATCH 1/4] Added a function which cheks which port to use when port is 443 or 80 --- .../nodes/vectorstores/Qdrant/Qdrant.ts | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts index 6413f8bf8..390e7fc9e 100644 --- a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts +++ b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts @@ -149,9 +149,12 @@ class Qdrant_VectorStores implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const qdrantApiKey = getCredentialParam('qdrantApiKey', credentialData, nodeData) + const port = Qdrant_VectorStores.determinePortByUrl(qdrantServerUrl); + const client = new QdrantClient({ url: qdrantServerUrl, - apiKey: qdrantApiKey + apiKey: qdrantApiKey, + port: port }) const flattenDocs = docs && docs.length ? flatten(docs) : [] @@ -198,9 +201,12 @@ class Qdrant_VectorStores implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const qdrantApiKey = getCredentialParam('qdrantApiKey', credentialData, nodeData) + const port = Qdrant_VectorStores.determinePortByUrl(qdrantServerUrl); + const client = new QdrantClient({ url: qdrantServerUrl, - apiKey: qdrantApiKey + apiKey: qdrantApiKey, + port: port }) const dbConfig: QdrantLibArgs = { @@ -242,6 +248,25 @@ class Qdrant_VectorStores implements INode { } return vectorStore } + + /** + * Determine the port number from the given URL. + * + * The problem is when not doing this the qdrant-client.js will fall back on 6663 when you enter a port 443 and 80. + * See: https://stackoverflow.com/questions/59104197/nodejs-new-url-urlhttps-myurl-com80-lists-the-port-as-empty + * @param qdrantServerUrl the url to get the port from + */ + static determinePortByUrl(qdrantServerUrl: string) :number { + let port = 6333; + const parsedUrl = new URL(qdrantServerUrl); + if (parsedUrl.protocol === 'https:' && parsedUrl.port === '') { + port = 443; + } + if (parsedUrl.protocol === 'http:' && parsedUrl.port === '') { + port = 80; + } + return port; + } } module.exports = { nodeClass: Qdrant_VectorStores } From 2355cb2ec5c83fe7302c919d89361cd33db35fff Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Thu, 4 Jan 2024 16:07:54 +0100 Subject: [PATCH 2/4] Fixed port handling so it returns the correct port and not only 6663 --- packages/components/nodes/vectorstores/Qdrant/Qdrant.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts index 390e7fc9e..54b55d34c 100644 --- a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts +++ b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts @@ -257,14 +257,18 @@ class Qdrant_VectorStores implements INode { * @param qdrantServerUrl the url to get the port from */ static determinePortByUrl(qdrantServerUrl: string) :number { - let port = 6333; const parsedUrl = new URL(qdrantServerUrl); + + let port = parsedUrl.port ? parseInt(parsedUrl.port) : 6663 + if (parsedUrl.protocol === 'https:' && parsedUrl.port === '') { port = 443; } if (parsedUrl.protocol === 'http:' && parsedUrl.port === '') { port = 80; } + + return port; } } From a046d5296176b0649dcc6abd9d29f8ef8e003a4e Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Thu, 4 Jan 2024 16:23:08 +0100 Subject: [PATCH 3/4] Make the linter happy --- .../components/nodes/vectorstores/Qdrant/Qdrant.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts index 54b55d34c..5e01b030d 100644 --- a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts +++ b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts @@ -149,7 +149,7 @@ class Qdrant_VectorStores implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const qdrantApiKey = getCredentialParam('qdrantApiKey', credentialData, nodeData) - const port = Qdrant_VectorStores.determinePortByUrl(qdrantServerUrl); + const port = Qdrant_VectorStores.determinePortByUrl(qdrantServerUrl) const client = new QdrantClient({ url: qdrantServerUrl, @@ -201,7 +201,7 @@ class Qdrant_VectorStores implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const qdrantApiKey = getCredentialParam('qdrantApiKey', credentialData, nodeData) - const port = Qdrant_VectorStores.determinePortByUrl(qdrantServerUrl); + const port = Qdrant_VectorStores.determinePortByUrl(qdrantServerUrl) const client = new QdrantClient({ url: qdrantServerUrl, @@ -256,20 +256,20 @@ class Qdrant_VectorStores implements INode { * See: https://stackoverflow.com/questions/59104197/nodejs-new-url-urlhttps-myurl-com80-lists-the-port-as-empty * @param qdrantServerUrl the url to get the port from */ - static determinePortByUrl(qdrantServerUrl: string) :number { - const parsedUrl = new URL(qdrantServerUrl); + static determinePortByUrl(qdrantServerUrl: string): number { + const parsedUrl = new URL(qdrantServerUrl) let port = parsedUrl.port ? parseInt(parsedUrl.port) : 6663 if (parsedUrl.protocol === 'https:' && parsedUrl.port === '') { - port = 443; + port = 443 } if (parsedUrl.protocol === 'http:' && parsedUrl.port === '') { - port = 80; + port = 80 } - return port; + return port } } From e35faa57afb5243fe4b011d408b1d96eee263622 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Thu, 4 Jan 2024 16:27:53 +0100 Subject: [PATCH 4/4] One last linting --- packages/components/nodes/vectorstores/Qdrant/Qdrant.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts index 5e01b030d..e07b728a5 100644 --- a/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts +++ b/packages/components/nodes/vectorstores/Qdrant/Qdrant.ts @@ -268,7 +268,6 @@ class Qdrant_VectorStores implements INode { port = 80 } - return port } }