{"record":{"id":"61533a3a956027e9","repo":"n8n-io/n8n","slug":"unexpected-score-type-typeof-score","errorCode":null,"errorMessage":"Unexpected score type: ${typeof score}","messagePattern":"Unexpected score type: (.+?)","errorType":"exception","errorClass":"UnexpectedError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreWeaviate/VectorStoreWeaviate.node.ts","lineNumber":82,"sourceCode":"\t\tif (args.hybridQuery) {\n\t\t\tconst options = {\n\t\t\t\tlimit: k ?? undefined,\n\t\t\t\tautoLimit: args.autoCutLimit ?? undefined,\n\t\t\t\talpha: args.alpha ?? undefined,\n\t\t\t\tvector: query,\n\t\t\t\tfilter: filter ? parseCompositeFilter(filter as WeaviateCompositeFilter) : undefined,\n\t\t\t\tqueryProperties: args.queryProperties\n\t\t\t\t\t? args.queryProperties.split(',').map((prop) => prop.trim())\n\t\t\t\t\t: undefined,\n\t\t\t\tmaxVectorDistance: args.maxVectorDistance ?? undefined,\n\t\t\t\tfusionType: args.fusionType,\n\t\t\t\treturnMetadata: args.hybridExplainScore ? ['explainScore'] : undefined,\n\t\t\t};\n\t\t\tconst content = await super.hybridSearch(args.hybridQuery, options);\n\t\t\treturn content.map((doc) => {\n\t\t\t\tconst { score, ...metadata } = doc.metadata;\n\t\t\t\tif (typeof score !== 'number') {\n\t\t\t\t\tthrow new UnexpectedError(`Unexpected score type: ${typeof score}`);\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tnew Document({\n\t\t\t\t\t\tpageContent: doc.pageContent,\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t}),\n\t\t\t\t\tscore,\n\t\t\t\t] as [Document, number];\n\t\t\t});\n\t\t}\n\t\treturn await super.similaritySearchVectorWithScore(\n\t\t\tquery,\n\t\t\tk,\n\t\t\tfilter ? parseCompositeFilter(filter as WeaviateCompositeFilter) : undefined,\n\t\t);\n\t}\n}\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreWeaviate/VectorStoreWeaviate.node.ts#L64-L100","documentation":"An UnexpectedError thrown while mapping hybridSearch results: each document's metadata.score must be a number, and if it is not (string, undefined, object) the mapping aborts. This fires only on the hybrid search branch (args.hybridQuery) where returnMetadata may be ['explainScore']. It signals the Weaviate response shape differs from what n8n expects.","triggerScenarios":"hybridSearch returns documents whose metadata.score is not a number — e.g. when hybridExplainScore is enabled and Weaviate returns an explanation object/string instead of a numeric score, or when a weaviate-ts/langchain version change alters metadata.score's type.","commonSituations":"Enabling hybridExplainScore changes the returned metadata so score is no longer numeric; weaviate server version returns score under a different key; langchain Document.metadata typing drift after an upgrade.","solutions":["If you enabled hybridExplainScore, disable it for the retrieval call that needs numeric scores (this branch only exists because of the hybrid path).","Update n8n to the latest release in case the metadata-shape handling was patched.","Check the Weaviate server version against the version n8n's bundled client expects; align them.","If you need explain output, consume it separately from the scoring path so the numeric score mapping is unaffected."],"exampleFix":"// before: options.hybridExplainScore = true  (score becomes explain object)\n// after:  options.hybridExplainScore = false (metadata.score is a number again)","handlingStrategy":"type-guard","validationCode":"// guard the mapping yourself before relying on numeric scores\nconst score = (doc.metadata as any).score;\nif (typeof score !== 'number') { /* fallback to similaritySearchVectorWithScore, or disable hybridExplainScore */ }","typeGuard":"function hasNumericScore(m: unknown): m is { score: number } { return typeof (m as any)?.score === 'number'; }","tryCatchPattern":"try { results = await store.hybridSearch(...) } catch (e) { if (/Unexpected score type/.test(e.message)) { results = await store.similaritySearchVectorWithScore(query, k); } else throw e; }","preventionTips":["Disable hybridExplainScore when you need numeric scores downstream.","Do not assume metadata.score is always present after Weaviate upgrades.","Pin a compatible Weaviate server version for your n8n release.","Add a type guard at the boundary that consumes hybrid results."],"tags":["weaviate","vector-store","hybrid-search","metadata","type-mismatch"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}