{"record":{"id":"4217040e000e2e80","repo":"FlowiseAI/Flowise","slug":"invalid-similarity-metric-should-be-one-of-cosine","errorCode":null,"errorMessage":"Invalid Similarity Metric should be one of 'cosine' | 'euclidean' | 'dot_product'","messagePattern":"Invalid Similarity Metric should be one of 'cosine' \\| 'euclidean' \\| 'dot_product'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/vectorstores/Astra/Astra.ts","lineNumber":109,"sourceCode":"                name: 'vectorStore',\n                baseClasses: [this.type, ...getBaseClasses(AstraDBVectorStore)]\n            }\n        ]\n    }\n\n    //@ts-ignore\n    vectorStoreMethods = {\n        async upsert(nodeData: INodeData, options: ICommonObject): Promise<Partial<IndexingResult>> {\n            const docs = nodeData.inputs?.document as Document[]\n            const embeddings = nodeData.inputs?.embeddings as Embeddings\n            const vectorDimension = nodeData.inputs?.vectorDimension as number\n            const astraCollection = nodeData.inputs?.astraCollection as string\n            const similarityMetric = nodeData.inputs?.similarityMetric as 'cosine' | 'euclidean' | 'dot_product' | undefined\n            const credentialData = await getCredentialData(nodeData.credential ?? '', options)\n\n            const expectedSimilarityMetric = ['cosine', 'euclidean', 'dot_product']\n            if (similarityMetric && !expectedSimilarityMetric.includes(similarityMetric)) {\n                throw new Error(`Invalid Similarity Metric should be one of 'cosine' | 'euclidean' | 'dot_product'`)\n            }\n\n            const clientConfig = {\n                token: credentialData?.applicationToken,\n                endpoint: credentialData?.dbEndPoint\n            }\n\n            const astraConfig: AstraLibArgs = {\n                ...clientConfig,\n                collection: astraCollection ?? credentialData.collectionName ?? 'flowise_test',\n                collectionOptions: {\n                    vector: {\n                        dimension: vectorDimension ?? 1536,\n                        metric: similarityMetric ?? 'cosine'\n                    }\n                }\n            }\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/vectorstores/Astra/Astra.ts#L91-L127","documentation":"Thrown in Astra vectorStoreMethods.upsert when `similarityMetric` is set but not one of 'cosine', 'euclidean', 'dot_product'. The validation runs before any Astra client is created, so it is purely an input-config check. The same check exists in init (error 498).","triggerScenarios":"A user selects or types a similarity metric value outside the allowed set (e.g. 'manhattan', 'Cosine' with wrong casing, 'dot', empty-but-defined).","commonSituations":"Custom metric typed manually; case mismatch; stale flow referencing a previously-supported metric; typo in API-driven flow creation.","solutions":["Set the similarity metric to one of 'cosine', 'euclidean', or 'dot_product'.","Leave the field unset to use the Astra default rather than supplying an invalid value.","Normalize input to lowercase before validation if casing is the issue (but the allowed set is lowercase only)."],"exampleFix":"// before\nsimilarityMetric = 'manhattan' // throws: Invalid Similarity Metric ...\n\n// after\nsimilarityMetric = 'cosine' // or 'euclidean' | 'dot_product'","handlingStrategy":"validation","validationCode":"const ALLOWED_ASTRA_METRICS = ['cosine', 'euclidean', 'dot_product'] as const\ntype AstraMetric = typeof ALLOWED_ASTRA_METRICS[number]\nfunction normalizeMetric(v: unknown): AstraMetric | undefined {\n  if (v == null || v === '') return undefined\n  const lower = String(v).toLowerCase()\n  if (!ALLOWED_ASTRA_METRICS.includes(lower as AstraMetric)) {\n    throw new Error(`similarityMetric must be one of ${ALLOWED_ASTRA_METRICS.join('|')}, got: ${String(v)}`)\n  }\n  return lower as AstraMetric\n}\n// before upsert\nnormalizeMetric(nodeData.inputs?.similarityMetric)","typeGuard":"const isAstraMetric = (v: unknown): v is 'cosine' | 'euclidean' | 'dot_product' =>\n  typeof v === 'string' && ['cosine', 'euclidean', 'dot_product'].includes(v)","tryCatchPattern":"try { return await astraNode.vectorStoreMethods.upsert(nodeData, options) }\ncatch (e) {\n  if (/Invalid Similarity Metric/.test((e as Error).message)) {\n    throw new Error('Set similarityMetric to cosine|euclidean|dot_product (or leave unset)')\n  }\n  throw e\n}","preventionTips":["Constrain the metric field in the UI/API to a dropdown of allowed values.","Normalize to lowercase before passing to the node.","Leave unset rather than guessing if the desired value is unclear."],"tags":["validation","vector-store","astra","configuration"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}