Skip to content

Commit

Permalink
Merge pull request #1480 from micromata/feature/qdrant-port-fix
Browse files Browse the repository at this point in the history
Feature/qdrant port fix
  • Loading branch information
HenryHengZJ authored Jan 5, 2024
2 parents d20debc + e35faa5 commit 3362706
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions packages/components/nodes/vectorstores/Qdrant/Qdrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) : []
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -242,6 +248,28 @@ 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 {
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
}
}

module.exports = { nodeClass: Qdrant_VectorStores }

0 comments on commit 3362706

Please sign in to comment.