{"record":{"id":"5428775a03a3c8f9","repo":"FlowiseAI/Flowise","slug":"must-specify-one-of-k-or-similarity-threshold","errorCode":null,"errorMessage":"Must specify one of \"k\" or \"similarity_threshold\".","messagePattern":"Must specify one of \"k\" or \"similarity_threshold\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/retrievers/EmbeddingsFilterRetriever/EmbeddingsFilterRetriever.ts","lineNumber":101,"sourceCode":"            {\n                label: 'Text',\n                name: 'text',\n                description: 'Concatenated string from pageContent of documents',\n                baseClasses: ['string', 'json']\n            }\n        ]\n    }\n\n    async init(nodeData: INodeData, input: string): Promise<any> {\n        const baseRetriever = nodeData.inputs?.baseRetriever as BaseRetriever\n        const embeddings = nodeData.inputs?.embeddings as Embeddings\n        const query = nodeData.inputs?.query as string\n        const similarityThreshold = nodeData.inputs?.similarityThreshold as string\n        const k = nodeData.inputs?.k as string\n        const output = nodeData.outputs?.output as string\n\n        if (k === undefined && similarityThreshold === undefined) {\n            throw new Error(`Must specify one of \"k\" or \"similarity_threshold\".`)\n        }\n\n        const similarityThresholdNumber = similarityThreshold ? parseFloat(similarityThreshold) : 0.8\n        const kNumber = k ? parseFloat(k) : undefined\n\n        const baseCompressor = new EmbeddingsFilter({\n            embeddings: embeddings,\n            similarityThreshold: similarityThresholdNumber,\n            k: kNumber\n        })\n\n        const retriever = new ContextualCompressionRetriever({\n            baseCompressor,\n            baseRetriever: baseRetriever\n        })\n\n        if (output === 'retriever') return retriever\n        else if (output === 'document') return await retriever._getRelevantDocuments(query ? query : input)","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/retrievers/EmbeddingsFilterRetriever/EmbeddingsFilterRetriever.ts#L83-L119","documentation":"Thrown by EmbeddingsFilterRetriever.init when both nodeData.inputs.k and nodeData.inputs.similarityThreshold are undefined. The underlying LangChain EmbeddingsFilter needs at least one stopping criterion - either keep top-k documents or keep those above a similarity threshold - otherwise its behavior is undefined.","triggerScenarios":"Both the 'k' and 'similarityThreshold' fields left blank on the Embeddings Filter Retriever node; one field connected to an empty upstream output; values explicitly set to undefined via API.","commonSituations":"New node left at defaults expecting sensible behavior; user removed the value thinking the other field would compensate; chatflow wired with a variable that resolves to empty.","solutions":["Set 'k' (e.g. 4) to keep the top-k most similar documents, OR set 'similarityThreshold' (e.g. 0.8) to keep documents above that cosine threshold.","Set both for combined behavior, but at least one is required.","If driving from a variable, ensure it resolves to a non-empty string."],"exampleFix":"// before: both undefined\n// after: in node config, set k = '4' (or similarityThreshold = '0.8')","handlingStrategy":"validation","validationCode":"function pickStopCriterion(k?: string, threshold?: string): { k?: number; similarityThreshold?: number } {\n  if (k === undefined && threshold === undefined) {\n    throw new Error('Set at least one of k or similarityThreshold on the Embeddings Filter Retriever.')\n  }\n  return { k: k ? parseFloat(k) : undefined, similarityThreshold: threshold ? parseFloat(threshold) : undefined }\n}","typeGuard":"function hasStopCriterion(nodeData: { inputs?: Record<string, unknown> }): boolean {\n  const { k, similarityThreshold } = (nodeData.inputs ?? {})\n  return k !== undefined && k !== '' || similarityThreshold !== undefined && similarityThreshold !== ''\n}","tryCatchPattern":"// Config error, not retryable. Catch only to surface a UI hint.\ntry {\n  await retriever.init(nodeData, input)\n} catch (e) {\n  if (e instanceof Error && /k\" or \"similarity_threshold/.test(e.message)) {\n    // highlight the k / similarityThreshold field\n  }\n  throw e\n}","preventionTips":["Default one of the two fields in the node template.","Mark at least one of k / similarityThreshold as required-at-least-one in the form.","Validate with hasStopCriterion before running the chatflow."],"tags":["retriever","embeddings-filter","config","validation","required-field"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}