{"record":{"id":"6be812bf098226e2","repo":"vercel/ai","slug":"ai-unsupportedfunctionalityerror","errorCode":"AI_UnsupportedFunctionalityError","errorMessage":"Alibaba embedding outputType 'sparse' is not supported because AI SDK embeddings require dense number arrays. Use 'dense' or 'dense&sparse' instead.","messagePattern":"Alibaba embedding outputType 'sparse' is not supported because AI SDK embeddings require dense number arrays\\. Use 'dense' or 'dense&sparse' instead\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/alibaba/src/alibaba-embedding-model.ts","lineNumber":89,"sourceCode":"  > {\n    if (values.length > this.maxEmbeddingsPerCall) {\n      throw new TooManyEmbeddingValuesForCallError({\n        provider: this.provider,\n        modelId: this.modelId,\n        maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,\n        values,\n      });\n    }\n\n    const alibabaOptions = await parseProviderOptions({\n      provider: 'alibaba',\n      providerOptions,\n      schema: alibabaEmbeddingModelOptions,\n    });\n\n    // TODO: Explore first-class sparse embedding support in AI SDK core.\n    if (alibabaOptions?.outputType === 'sparse') {\n      throw new UnsupportedFunctionalityError({\n        functionality: \"Alibaba embedding outputType 'sparse'\",\n        message:\n          \"Alibaba embedding outputType 'sparse' is not supported because AI SDK embeddings require dense number arrays. Use 'dense' or 'dense&sparse' instead.\",\n      });\n    }\n\n    const {\n      responseHeaders,\n      value: response,\n      rawValue,\n    } = await postJsonToApi({\n      url: `${this.config.baseURL}/services/embeddings/text-embedding/text-embedding`,\n      headers: combineHeaders(this.config.headers?.(), headers),\n      body: {\n        model: this.modelId,\n        input: {\n          texts: values,\n        },","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/alibaba/src/alibaba-embedding-model.ts#L71-L107","documentation":"Alibaba embedding models can return sparse (index/value) vectors, but the AI SDK embed API only accepts dense number[] arrays. The provider therefore proactively rejects outputType 'sparse' with an UnsupportedFunctionalityError instead of returning data the SDK cannot represent. Use 'dense' or 'dense&sparse' (the SDK surfaces only the dense portion).","triggerScenarios":"Calling embed()/embedMany() with an alibaba.embedding(modelId) model while passing providerOptions alibaba.embeddingModelOptions with outputType: 'sparse' in doEmbed.","commonSituations":"Developers porting code that used Alibaba's native sparse vectors for keyword-style retrieval, or copying DashScope docs that recommend sparse output for search ranking, then wiring it into the AI SDK.","solutions":["Change the providerOptions outputType to 'dense' or 'dense&sparse'","If sparse vectors are required, call the Alibaba/DashScope API directly outside the AI SDK","Combine dense embeddings from the SDK with a separate sparse retrieval layer (e.g. BM25) instead"],"exampleFix":"// before\nconst { embedding } = await embed({\n  model: alibaba.embedding('text-embedding-v4'),\n  value: 'hello',\n  providerOptions: { alibaba: { outputType: 'sparse' } },\n});\n// after\nconst { embedding } = await embed({\n  model: alibaba.embedding('text-embedding-v4'),\n  value: 'hello',\n  providerOptions: { alibaba: { outputType: 'dense' } },\n});","handlingStrategy":"validation","validationCode":"if (opts.alibaba?.outputType === 'sparse') throw new Error('Use dense or dense&sparse outputType for AI SDK embeddings');","typeGuard":"function isDenseOutput(o: unknown): boolean {\n  const t = (o as { alibaba?: { outputType?: string } })?.alibaba?.outputType;\n  return t !== 'sparse';\n}","tryCatchPattern":"try {\n  await embed({ model, value, providerOptions });\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e)) {\n    // fall back to dense outputType\n  }\n}","preventionTips":["Never set outputType: 'sparse' when using the AI SDK embed APIs","Review providerOptions schemas before porting native DashScope options","Read the alibaba-embedding-model docs on sparse vector limitations"],"tags":["embeddings","unsupported-functionality","provider-options"],"backgroundTag":"sparse-embeddings-unsupported","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}