Skip to content

fix: guard against undefined warnings in embed/embedMany (#14425)#14426

Open
xyaz1313 wants to merge 1 commit intovercel:mainfrom
xyaz1313:fix-embed-warnings-undefined
Open

fix: guard against undefined warnings in embed/embedMany (#14425)#14426
xyaz1313 wants to merge 1 commit intovercel:mainfrom
xyaz1313:fix-embed-warnings-undefined

Conversation

@xyaz1313
Copy link
Copy Markdown

What

Fixes #14425embed() and embedMany() crash at runtime when used with EmbeddingModelV2 providers (e.g. @ai-sdk/google-vertex@3.x) that don't return a warnings property from doEmbed.

Root cause

  1. logWarnings in log-warnings.ts:97 accesses options.warnings.length without a null check — TypeError: Cannot read properties of undefined (reading 'length')
  2. embedMany in embed-many.ts:312 spreads result.warningsTypeError: result.warnings is not iterable

The EmbeddingModelV2 protocol does not include warnings in its doEmbed return type, so v2 providers return undefined for this field.

Fix

  • packages/ai/src/logger/log-warnings.ts:97: Guard with !options.warnings || before accessing .length
  • packages/ai/src/embed/embed-many.ts:312: Guard with if (result.warnings) before spreading

Testing

The existing test suite should continue to pass since these guards are no-ops when warnings is present (the common case). The fix handles the edge case where warnings is undefined.

EmbeddingModelV2 providers (e.g. @ai-sdk/google-vertex@3.x) do not
return a `warnings` property from doEmbed. This caused:
- TypeError in logWarnings: Cannot read properties of undefined (reading 'length')
- TypeError in embedMany: result.warnings is not iterable

Fix: add null checks in log-warnings.ts and embed-many.ts.
@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/google-vertex Issues related to the @ai-sdk/google-vertex provider reproduction provided labels Apr 14, 2026
@nehaaprasad
Copy link
Copy Markdown

AI Code Trust — ship readiness

Score: 100 · Verdict: SAFE · Model: deterministic-v1

No blocking issues detected by automated checks.

Top issues:

  • maintainability (medium) — File is very long (430 lines); consider splitting. packages/ai/src/embed/embed-many.ts:1

Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

embed() and embedMany() pass undefined warnings to result objects when using EmbeddingModelV2 providers, violating the warnings: Array<Warning> type contract

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/google-vertex Issues related to the @ai-sdk/google-vertex provider reproduction provided

Projects

None yet

Development

Successfully merging this pull request may close these issues.

embed/embedMany crash: 'warnings' is undefined from EmbeddingModelV2 providers

2 participants