FlowiseAI/Flowise · error · Error
Unknown distance strategy: ${distanceStrategy}
Error message
Unknown distance strategy: ${distanceStrategy} What it means
The Postgres/TypeORM pgvector driver maps a `distanceStrategy` node input to a pgvector distance operator via the `computedOperatorString` getter. Only three strategies are recognized: 'cosine' (<=>), 'innerProduct' (<#>), and 'euclidean' (<->). Any other value falls through to the default branch and throws. The comparison is exact and case-sensitive, so even a correctly-named strategy with different casing or surrounding whitespace will be rejected.
Source
Thrown at packages/components/nodes/vectorstores/Postgres/driver/TypeORM.ts:174
await this.ensureTableInDatabase(instance, effectiveTablePath)
return (instance.addVectors as any)(await this.getEmbeddings().embedDocuments(texts), documents, options)
}
return instance
}
get computedOperatorString() {
const { distanceStrategy = 'cosine' } = this.nodeData.inputs || {}
switch (distanceStrategy) {
case 'cosine':
return '<=>'
case 'innerProduct':
return '<#>'
case 'euclidean':
return '<->'
default:
throw new Error(`Unknown distance strategy: ${distanceStrategy}`)
}
}
/**
* Ensures the table exists in the database with the correct schema.
* Creates the pgvector extension and table if they don't exist.
*/
async ensureTableInDatabase(instance: TypeORMVectorStore, tablePath: string): Promise<void> {
await instance.appDataSource.query('CREATE EXTENSION IF NOT EXISTS vector;')
await instance.appDataSource.query(`
CREATE TABLE IF NOT EXISTS ${tablePath} (
"id" uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
"pageContent" text,
metadata jsonb,
embedding vector
);
`)
}View on GitHub (pinned to abe4a8601a)
Solutions
- Set `distanceStrategy` to exactly one of: 'cosine', 'innerProduct', or 'euclidean'.
- Trim and lowercase the value before it reaches the node: `distanceStrategy.trim().toLowerCase()` mapping to the canonical form.
- If the node UI exposes a value not handled here, update the dropdown to only the three supported values.
- To support a new strategy, add a case returning the correct pgvector operator and update the node's allowed-values list.
Example fix
// before
const { distanceStrategy = 'cosine' } = this.nodeData.inputs || {}
switch (distanceStrategy) { /* ... */ default: throw new Error(`Unknown distance strategy: ${distanceStrategy}`) }
// after (normalize + safe default)
const raw = String(this.nodeData.inputs?.distanceStrategy ?? 'cosine').trim().toLowerCase()
const strategy = raw === 'innerproduct' ? 'innerProduct' : raw
switch (strategy) {
case 'cosine': return '<=>'
case 'innerProduct': return '<#>'
case 'euclidean': return '<->'
default: throw new Error(`Unknown distance strategy: ${distanceStrategy}. Supported: cosine, innerProduct, euclidean`)
} Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = ['cosine', 'innerProduct', 'euclidean'] as const
function normalizeDistanceStrategy(raw: unknown): typeof ALLOWED[number] {
const s = String(raw ?? 'cosine').trim().toLowerCase()
if (s === 'innerproduct') return 'innerProduct'
if ((ALLOWED as readonly string[]).includes(s)) return s as typeof ALLOWED[number]
throw new Error(`Unsupported distanceStrategy '${String(raw)}'. Use one of: ${ALLOWED.join(', ')}`)
} Type guard
function isDistanceStrategy(v: unknown): v is 'cosine' | 'innerProduct' | 'euclidean' {
return v === 'cosine' || v === 'innerProduct' || v === 'euclidean'
} Try / catch
try { const op = computedOperatorString } catch (e) { /* surface supported list */ throw new Error(`${(e as Error).message}. Supported: cosine, innerProduct, euclidean`) } Prevention
- Constrain the node dropdown to the three supported strategies.
- Normalize incoming input (trim + lowercase) before the switch.
- Reject unsupported values at the API boundary, not deep in the getter.
When it happens
Trigger: Supplying a `distanceStrategy` input that is not exactly 'cosine', 'innerProduct', or 'euclidean' — e.g. 'Cosine', 'dot', 'manhattan', 'l2', a typo like 'cosin', or an empty string. The getter is invoked whenever the vector store computes the distance operator for similarity search.
Common situations: Node dropdown options drifting out of sync with this switch after an upgrade; user typing a free-text strategy; case mismatch ('Cosine' vs 'cosine'); migrating from another store whose strategy names differ (e.g. pgvector docs use 'l2'); trailing whitespace from a templated config value.
Related errors
- No datasource options provided
- Invalid port number
- Invalid JSON in the Agent's Prompt Input Values: ${exception
- Agent input variables values are not provided!
- Key is required
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/91a42349325557e7.
Report an issue: GitHub.