{"record":{"id":"6acb6ec303693a29","repo":"redis/node-redis","slug":"vectoroutput-is-undefined","errorCode":null,"errorMessage":"vectorOutput is undefined","messagePattern":"vectorOutput is undefined","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"doctests/query-combined.js","lineNumber":25,"sourceCode":"import { pipeline } from '@xenova/transformers';\n\nfunction float32Buffer(arr) {\n  const floatArray = new Float32Array(arr);\n  const float32Buffer = Buffer.from(floatArray.buffer);\n  return float32Buffer;\n}\n\nasync function embedText(sentence) {\n  let modelName = 'Xenova/all-MiniLM-L6-v2';\n  let pipe = await pipeline('feature-extraction', modelName);\n\n  let vectorOutput = await pipe(sentence, {\n      pooling: 'mean',\n      normalize: true,\n  });\n\n  if (vectorOutput == null) {\n    throw new Error('vectorOutput is undefined');\n  }\n\n  const embedding = Object.values(vectorOutput.data);\n\n  return embedding;\n}\n\nlet vector_query = float32Buffer(await embedText('That is a very happy person'));\n\nconst client = createClient();\nawait client.connect().catch(console.error);\n\n// create index\nawait client.ft.create('idx:bicycle', {\n    '$.description': {\n      type: SCHEMA_FIELD_TYPE.TEXT,\n      AS: 'description'\n    },","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/redis/node-redis/blob/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/doctests/query-combined.js#L7-L43","documentation":"Thrown by an explicit guard in the doctest's embedText() helper. The @xenova/transformers pipeline('feature-extraction', ...) call resolved to null/undefined for the input sentence, so vectorOutput.data cannot be read. transformers.js returns null when model loading, inference, or ONNX runtime setup fails internally and swallows the underlying cause.","triggerScenarios":"Running doctests/query-combined.js and the await pipe(sentence, { pooling: 'mean', normalize: true }) call resolves to null/undefined. Happens when the model artifact fails to load, ONNX backend init fails, or inference throws and is caught upstream.","commonSituations":"HuggingFace model download blocked (offline/corporate proxy); @xenova/transformers version mismatch with the bundled ONNX runtime; Node version incompatibility; model name typo 'Xenova/all-MiniLM-L6-v2'; first-run fetch timeout; WASM threads disabled in the runtime.","solutions":["Wrap the pipe() call in try/catch to surface the real upstream error (transformers.js hides it behind the null return).","Verify network access to huggingface.co or pre-download the model into a local cache directory and point env.cacheDir at it.","Pin @xenova/transformers to a version known to work with your Node runtime and the all-MiniLM-L6-v2 model.","Confirm the model id is correct and reachable: test with transformers.js standalone before invoking the doctest."],"exampleFix":"// before\nlet pipe = await pipeline('feature-extraction', modelName);\nlet vectorOutput = await pipe(sentence, { pooling: 'mean', normalize: true });\nif (vectorOutput == null) throw new Error('vectorOutput is undefined');\n\n// after\nconst pipe = await pipeline('feature-extraction', modelName);\nlet vectorOutput;\ntry {\n  vectorOutput = await pipe(sentence, { pooling: 'mean', normalize: true });\n} catch (err) {\n  throw new Error('feature-extraction inference failed: ' + err.message, { cause: err });\n}\nif (vectorOutput == null || !('data' in vectorOutput)) {\n  throw new Error('vectorOutput is undefined (model load or inference returned nothing)');\n}","handlingStrategy":"try-catch","validationCode":"import { pipeline, env } from '@xenova/transformers';\n\nasync function safePipeline(name) {\n  try {\n    const pipe = await pipeline('feature-extraction', name);\n    if (typeof pipe !== 'function') {\n      throw new Error('pipeline did not return a callable');\n    }\n    return pipe;\n  } catch (err) {\n    throw new Error(`transformers pipeline init failed for ${name}: ${err.message}`, { cause: err });\n  }\n}\n\n// call before the doctest runs\nconst pipe = await safePipeline('Xenova/all-MiniLM-L6-v2');","typeGuard":"function isTensor(v) {\n  return v != null && typeof v === 'object' && 'data' in v && typeof v.data.length === 'number';\n}","tryCatchPattern":"try {\n  vectorOutput = await pipe(sentence, { pooling: 'mean', normalize: true });\n} catch (err) {\n  throw new Error('feature-extraction failed: ' + err.message, { cause: err });\n}\nif (!isTensor(vectorOutput)) throw new Error('vectorOutput is undefined');","preventionTips":["Pre-warm and cache the pipeline once at process startup; reuse the instance.","Pin @xenova/transformers and verify Node/ONNX runtime compatibility.","Set env.cacheDir and pre-download the model so offline runs do not return null.","Wrap pipe() in try/catch — transformers.js swallows inference errors into null returns."],"tags":["transformers","ml-embedding","doctest","network","model-loading"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}