FlowiseAI/Flowise · error · Error
Must specify one of "k" or "similarity_threshold".
Error message
Must specify one of "k" or "similarity_threshold".
What it means
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.
Source
Thrown at packages/components/nodes/retrievers/EmbeddingsFilterRetriever/EmbeddingsFilterRetriever.ts:101
{
label: 'Text',
name: 'text',
description: 'Concatenated string from pageContent of documents',
baseClasses: ['string', 'json']
}
]
}
async init(nodeData: INodeData, input: string): Promise<any> {
const baseRetriever = nodeData.inputs?.baseRetriever as BaseRetriever
const embeddings = nodeData.inputs?.embeddings as Embeddings
const query = nodeData.inputs?.query as string
const similarityThreshold = nodeData.inputs?.similarityThreshold as string
const k = nodeData.inputs?.k as string
const output = nodeData.outputs?.output as string
if (k === undefined && similarityThreshold === undefined) {
throw new Error(`Must specify one of "k" or "similarity_threshold".`)
}
const similarityThresholdNumber = similarityThreshold ? parseFloat(similarityThreshold) : 0.8
const kNumber = k ? parseFloat(k) : undefined
const baseCompressor = new EmbeddingsFilter({
embeddings: embeddings,
similarityThreshold: similarityThresholdNumber,
k: kNumber
})
const retriever = new ContextualCompressionRetriever({
baseCompressor,
baseRetriever: baseRetriever
})
if (output === 'retriever') return retriever
else if (output === 'document') return await retriever._getRelevantDocuments(query ? query : input)View on GitHub (pinned to abe4a8601a)
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.
Example fix
// before: both undefined // after: in node config, set k = '4' (or similarityThreshold = '0.8')
Defensive patterns
Strategy: validation
Validate before calling
function pickStopCriterion(k?: string, threshold?: string): { k?: number; similarityThreshold?: number } {
if (k === undefined && threshold === undefined) {
throw new Error('Set at least one of k or similarityThreshold on the Embeddings Filter Retriever.')
}
return { k: k ? parseFloat(k) : undefined, similarityThreshold: threshold ? parseFloat(threshold) : undefined }
} Type guard
function hasStopCriterion(nodeData: { inputs?: Record<string, unknown> }): boolean {
const { k, similarityThreshold } = (nodeData.inputs ?? {})
return k !== undefined && k !== '' || similarityThreshold !== undefined && similarityThreshold !== ''
} Try / catch
// Config error, not retryable. Catch only to surface a UI hint.
try {
await retriever.init(nodeData, input)
} catch (e) {
if (e instanceof Error && /k" or "similarity_threshold/.test(e.message)) {
// highlight the k / similarityThreshold field
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Agent name is required!
- No extraction path configured
- JSON Path is required
- No Jira host provided
- MCP Server Config is required
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/5428775a03a3c8f9.
Report an issue: GitHub.