From b3603d7d08775cbdaf1aeb98a417096e91df219b Mon Sep 17 00:00:00 2001 From: Antonio Rodriguez <42835728+rodzanto@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:51:48 +0200 Subject: [PATCH 1/6] Update AWSBedrockEmbedding.ts Corrected the version of the titan embeddings model v2 --- .../nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts b/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts index 0ac26d85..e5012372 100644 --- a/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts +++ b/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts @@ -79,7 +79,7 @@ class AWSBedrockEmbedding_Embeddings implements INode { label: 'Model Name', name: 'model', type: 'options', - options: [{ label: 'amazon.titan-embed-text-v1', name: 'amazon.titan-embed-text-v1' }], + options: [{ label: 'amazon.titan-embed-text-v1', name: 'amazon.titan-embed-text-v2' }], default: 'amazon.titan-embed-text-v1' } ] From 31d0facde78b24cb5f7c1d998832311734428fe0 Mon Sep 17 00:00:00 2001 From: Antonio Rodriguez <42835728+rodzanto@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:16:10 +0200 Subject: [PATCH 2/6] Update AWSBedrockEmbedding.ts Added the newer v2 for the Amazon Titan Embed model --- .../nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts b/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts index e5012372..f092cbec 100644 --- a/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts +++ b/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts @@ -79,7 +79,7 @@ class AWSBedrockEmbedding_Embeddings implements INode { label: 'Model Name', name: 'model', type: 'options', - options: [{ label: 'amazon.titan-embed-text-v1', name: 'amazon.titan-embed-text-v2' }], + options: [{ label: 'amazon.titan-embed-text-v1', name: 'amazon.titan-embed-text-v1' }, { label: 'amazon.titan-embed-g1-text-02', name: 'amazon.titan-embed-g1-text-02' }], default: 'amazon.titan-embed-text-v1' } ] From f3bd81839766ca49f46ae5bb84d684398afc76ed Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 23 Oct 2023 11:10:45 +0100 Subject: [PATCH 3/6] add additional config --- .../Qdrant_Existing/Qdrant_Existing.ts | 46 +++++++++++++++++-- .../Qdrant_Upsert/Qdrant_Upsert.ts | 42 ++++++++++++++++- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/packages/components/nodes/vectorstores/Qdrant_Existing/Qdrant_Existing.ts b/packages/components/nodes/vectorstores/Qdrant_Existing/Qdrant_Existing.ts index 58ef6df5..c16e8f54 100644 --- a/packages/components/nodes/vectorstores/Qdrant_Existing/Qdrant_Existing.ts +++ b/packages/components/nodes/vectorstores/Qdrant_Existing/Qdrant_Existing.ts @@ -23,7 +23,7 @@ class Qdrant_Existing_VectorStores implements INode { constructor() { this.label = 'Qdrant Load Existing Index' this.name = 'qdrantExistingIndex' - this.version = 1.0 + this.version = 2.0 this.type = 'Qdrant' this.icon = 'qdrant.png' this.category = 'Vector Stores' @@ -55,8 +55,39 @@ class Qdrant_Existing_VectorStores implements INode { type: 'string' }, { - label: 'Qdrant Collection Cofiguration', + label: 'Vector Dimension', + name: 'qdrantVectorDimension', + type: 'number', + default: 1536, + additionalParams: true + }, + { + label: 'Similarity', + name: 'qdrantSimilarity', + description: 'Similarity measure used in Qdrant.', + type: 'options', + default: 'Cosine', + options: [ + { + label: 'Cosine', + name: 'Cosine' + }, + { + label: 'Euclid', + name: 'Euclid' + }, + { + label: 'Dot', + name: 'Dot' + } + ], + additionalParams: true + }, + { + label: 'Additional Collection Cofiguration', name: 'qdrantCollectionConfiguration', + description: + 'Refer to collection docs for more reference', type: 'json', optional: true, additionalParams: true @@ -98,6 +129,8 @@ class Qdrant_Existing_VectorStores implements INode { const collectionName = nodeData.inputs?.qdrantCollection as string let qdrantCollectionConfiguration = nodeData.inputs?.qdrantCollectionConfiguration const embeddings = nodeData.inputs?.embeddings as Embeddings + const qdrantSimilarity = nodeData.inputs?.qdrantSimilarity + const qdrantVectorDimension = nodeData.inputs?.qdrantVectorDimension const output = nodeData.outputs?.output as string const topK = nodeData.inputs?.topK as string let queryFilter = nodeData.inputs?.queryFilter @@ -126,7 +159,14 @@ class Qdrant_Existing_VectorStores implements INode { typeof qdrantCollectionConfiguration === 'object' ? qdrantCollectionConfiguration : JSON.parse(qdrantCollectionConfiguration) - dbConfig.collectionConfig = qdrantCollectionConfiguration + dbConfig.collectionConfig = { + ...qdrantCollectionConfiguration, + vectors: { + ...qdrantCollectionConfiguration.vectors, + size: qdrantVectorDimension ? parseInt(qdrantVectorDimension, 10) : 1536, + distance: qdrantSimilarity ?? 'Cosine' + } + } } if (queryFilter) { diff --git a/packages/components/nodes/vectorstores/Qdrant_Upsert/Qdrant_Upsert.ts b/packages/components/nodes/vectorstores/Qdrant_Upsert/Qdrant_Upsert.ts index 6f3773ff..407a8d22 100644 --- a/packages/components/nodes/vectorstores/Qdrant_Upsert/Qdrant_Upsert.ts +++ b/packages/components/nodes/vectorstores/Qdrant_Upsert/Qdrant_Upsert.ts @@ -25,7 +25,7 @@ class QdrantUpsert_VectorStores implements INode { constructor() { this.label = 'Qdrant Upsert Document' this.name = 'qdrantUpsert' - this.version = 1.0 + this.version = 2.0 this.type = 'Qdrant' this.icon = 'qdrant.png' this.category = 'Vector Stores' @@ -62,6 +62,35 @@ class QdrantUpsert_VectorStores implements INode { name: 'qdrantCollection', type: 'string' }, + { + label: 'Vector Dimension', + name: 'qdrantVectorDimension', + type: 'number', + default: 1536, + additionalParams: true + }, + { + label: 'Similarity', + name: 'qdrantSimilarity', + description: 'Similarity measure used in Qdrant.', + type: 'options', + default: 'Cosine', + options: [ + { + label: 'Cosine', + name: 'Cosine' + }, + { + label: 'Euclid', + name: 'Euclid' + }, + { + label: 'Dot', + name: 'Dot' + } + ], + additionalParams: true + }, { label: 'Top K', name: 'topK', @@ -99,6 +128,9 @@ class QdrantUpsert_VectorStores implements INode { const collectionName = nodeData.inputs?.qdrantCollection as string const docs = nodeData.inputs?.document as Document[] const embeddings = nodeData.inputs?.embeddings as Embeddings + const qdrantSimilarity = nodeData.inputs?.qdrantSimilarity + const qdrantVectorDimension = nodeData.inputs?.qdrantVectorDimension + const output = nodeData.outputs?.output as string const topK = nodeData.inputs?.topK as string const k = topK ? parseFloat(topK) : 4 @@ -121,7 +153,13 @@ class QdrantUpsert_VectorStores implements INode { const dbConfig: QdrantLibArgs = { client, url: qdrantServerUrl, - collectionName + collectionName, + collectionConfig: { + vectors: { + size: qdrantVectorDimension ? parseInt(qdrantVectorDimension, 10) : 1536, + distance: qdrantSimilarity ?? 'Cosine' + } + } } const retrieverConfig: RetrieverConfig = { From 9900228eeb7a5b59eb16525657537c39a554e929 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Mon, 23 Oct 2023 15:24:55 +0100 Subject: [PATCH 4/6] Update AWSBedrockEmbedding.ts --- .../embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts b/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts index f092cbec..ba2aa5e7 100644 --- a/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts +++ b/packages/components/nodes/embeddings/AWSBedrockEmbedding/AWSBedrockEmbedding.ts @@ -79,7 +79,10 @@ class AWSBedrockEmbedding_Embeddings implements INode { label: 'Model Name', name: 'model', type: 'options', - options: [{ label: 'amazon.titan-embed-text-v1', name: 'amazon.titan-embed-text-v1' }, { label: 'amazon.titan-embed-g1-text-02', name: 'amazon.titan-embed-g1-text-02' }], + options: [ + { label: 'amazon.titan-embed-text-v1', name: 'amazon.titan-embed-text-v1' }, + { label: 'amazon.titan-embed-g1-text-02', name: 'amazon.titan-embed-g1-text-02' } + ], default: 'amazon.titan-embed-text-v1' } ] From f8130fdff99cbf526b203c2dd2267e8f10fdaffc Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 23 Oct 2023 15:46:27 +0100 Subject: [PATCH 5/6] fix Chatflow API Authentication --- packages/server/src/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 9d3f7052..8d4592b5 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -809,18 +809,18 @@ export class App { * @param {Response} res * @param {ChatFlow} chatflow */ - async validateKey(req: Request, res: Response, chatflow: ChatFlow) { + async validateKey(req: Request, chatflow: ChatFlow) { const chatFlowApiKeyId = chatflow.apikeyid const authorizationHeader = (req.headers['Authorization'] as string) ?? (req.headers['authorization'] as string) ?? '' - - if (chatFlowApiKeyId && !authorizationHeader) return res.status(401).send(`Unauthorized`) - + if (chatFlowApiKeyId && !authorizationHeader) return false const suppliedKey = authorizationHeader.split(`Bearer `).pop() if (chatFlowApiKeyId && suppliedKey) { const keys = await getAPIKeys() const apiSecret = keys.find((key) => key.id === chatFlowApiKeyId)?.apiSecret - if (!compareKeys(apiSecret, suppliedKey)) return res.status(401).send(`Unauthorized`) + if (!compareKeys(apiSecret, suppliedKey)) return false + return true } + return false } /** @@ -846,7 +846,8 @@ export class App { if (!chatId) chatId = chatflowid if (!isInternal) { - await this.validateKey(req, res, chatflow) + const isKeyValidated = await this.validateKey(req, chatflow) + if (!isKeyValidated) return res.status(401).send('Unauthorized') } let isStreamValid = false From 2f0b4e18f478d3c9c2d8019e199344290016658b Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 23 Oct 2023 15:52:28 +0100 Subject: [PATCH 6/6] update fix when no chatflow apikey is set --- packages/server/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 8d4592b5..89b36ad1 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -811,10 +811,13 @@ export class App { */ async validateKey(req: Request, chatflow: ChatFlow) { const chatFlowApiKeyId = chatflow.apikeyid + if (!chatFlowApiKeyId) return true + const authorizationHeader = (req.headers['Authorization'] as string) ?? (req.headers['authorization'] as string) ?? '' if (chatFlowApiKeyId && !authorizationHeader) return false + const suppliedKey = authorizationHeader.split(`Bearer `).pop() - if (chatFlowApiKeyId && suppliedKey) { + if (suppliedKey) { const keys = await getAPIKeys() const apiSecret = keys.find((key) => key.id === chatFlowApiKeyId)?.apiSecret if (!compareKeys(apiSecret, suppliedKey)) return false