Skip to content

feat(ai): introduce experimental callbacks for embed function#13478

Merged
aayush-kapoor merged 14 commits intomainfrom
aayush/embed-callbacks
Mar 18, 2026
Merged

feat(ai): introduce experimental callbacks for embed function#13478
aayush-kapoor merged 14 commits intomainfrom
aayush/embed-callbacks

Conversation

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

@aayush-kapoor aayush-kapoor commented Mar 16, 2026

Background

In order to completely decouple OTel from the ai package, we need to align all the core functions to emit event data at each step for each of the functions.

We made similar changes to generateText and streamText when we introduced experimental_* (onStart, onStepStart, onFinish etc) and the same changes/callbacks needed to be added for the embed function

Summary

  • introduce the onStart and onFinish callbacks (experimental)
  • create new interfaces for both of those events for proper type safety
  • change added for embed and embedMany

Manual Verification

na

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

decouple otel from the embed and embedMany function and move integration to open-telemetry-integration

@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. feature New feature or request labels Mar 16, 2026
*
* Called when the operation begins, before the embedding model is called.
*/
export interface EmbedOnStartEvent {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

when this is integrated into telemetry, some of the telemetry method names might need to change

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, might need to come up with a good nomenclature. worth discussing in the follow up PR

@@ -17,9 +17,9 @@
/**
* Common model information used across callback events.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

rm callback

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also file still called callback-events -- maybe generate-text-events?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

these are used by stream text as well.. how about core-events?

Comment on lines +20 to 25
export interface ModelEventInfo {
/** The provider identifier (e.g., 'openai', 'anthropic'). */
readonly provider: string;
/** The specific model identifier (e.g., 'gpt-4o'). */
readonly modelId: string;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we have this already somewhere in the codebase afaik. if not it is worth having more general, e.g. as standalone ModelInfo (dont like info but good enough until we have a better name)


/** The model being used for generation. */
readonly model: CallbackModelInfo;
readonly model: ModelEventInfo;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do we have ModelEventInfo to begin with? can it be flattened?

@@ -0,0 +1,104 @@
import type { JSONValue } from '@ai-sdk/provider';
import type { ProviderOptions } from '@ai-sdk/provider-utils';
import type { ModelEventInfo } from '../generate-text/callback-events';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the dependency on generate-text seems strange. can we flatten the object into the events? or extract it into some other folder?

@aayush-kapoor aayush-kapoor enabled auto-merge (squash) March 18, 2026 19:38
@aayush-kapoor aayush-kapoor merged commit ff9ce30 into main Mar 18, 2026
20 checks passed
@aayush-kapoor aayush-kapoor deleted the aayush/embed-callbacks branch March 18, 2026 19:39
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 18, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.25
@ai-sdk/alibaba 2.0.0-beta.9
@ai-sdk/amazon-bedrock 5.0.0-beta.9
@ai-sdk/angular 3.0.0-beta.25
@ai-sdk/anthropic 4.0.0-beta.9
@ai-sdk/assemblyai 3.0.0-beta.6
@ai-sdk/azure 4.0.0-beta.11
@ai-sdk/baseten 2.0.0-beta.7
@ai-sdk/black-forest-labs 2.0.0-beta.5
@ai-sdk/bytedance 2.0.0-beta.5
@ai-sdk/cerebras 3.0.0-beta.7
@ai-sdk/cohere 4.0.0-beta.5
@ai-sdk/deepgram 3.0.0-beta.5
@ai-sdk/deepinfra 3.0.0-beta.7
@ai-sdk/deepseek 3.0.0-beta.6
@ai-sdk/devtools 1.0.0-beta.3
@ai-sdk/elevenlabs 3.0.0-beta.5
@ai-sdk/fal 3.0.0-beta.5
@ai-sdk/fireworks 3.0.0-beta.7
@ai-sdk/gateway 4.0.0-beta.16
@ai-sdk/gladia 3.0.0-beta.5
@ai-sdk/google 4.0.0-beta.13
@ai-sdk/google-vertex 5.0.0-beta.18
@ai-sdk/groq 4.0.0-beta.6
@ai-sdk/huggingface 2.0.0-beta.7
@ai-sdk/hume 3.0.0-beta.5
@ai-sdk/klingai 4.0.0-beta.6
@ai-sdk/langchain 3.0.0-beta.25
@ai-sdk/llamaindex 3.0.0-beta.25
@ai-sdk/lmnt 3.0.0-beta.5
@ai-sdk/luma 3.0.0-beta.5
@ai-sdk/mcp 2.0.0-beta.9
@ai-sdk/mistral 4.0.0-beta.5
@ai-sdk/moonshotai 3.0.0-beta.7
@ai-sdk/open-responses 2.0.0-beta.6
@ai-sdk/openai 4.0.0-beta.11
@ai-sdk/openai-compatible 3.0.0-beta.7
@ai-sdk/perplexity 4.0.0-beta.6
@ai-sdk/prodia 2.0.0-beta.7
@ai-sdk/provider 4.0.0-beta.3
@ai-sdk/provider-utils 5.0.0-beta.5
@ai-sdk/react 4.0.0-beta.25
@ai-sdk/replicate 3.0.0-beta.6
@ai-sdk/revai 3.0.0-beta.6
@ai-sdk/rsc 3.0.0-beta.26
@ai-sdk/svelte 5.0.0-beta.25
@ai-sdk/togetherai 3.0.0-beta.7
@ai-sdk/valibot 3.0.0-beta.5
@ai-sdk/vercel 3.0.0-beta.7
@ai-sdk/vue 4.0.0-beta.25
@ai-sdk/xai 4.0.0-beta.13

@aayush-kapoor aayush-kapoor added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 19, 2026
vercel-ai-sdk bot pushed a commit that referenced this pull request Mar 19, 2026
@vercel-ai-sdk vercel-ai-sdk bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 19, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 19, 2026

⚠️ Backport to release-v6.0 created but has conflicts: #13637

aayush-kapoor added a commit that referenced this pull request Mar 19, 2026
…on (#13637)

This is an automated backport of #13478 to the release-v6.0 branch. FYI
@aayush-kapoor
This backport has conflicts that need to be resolved manually.

### `git cherry-pick` output

```
Auto-merging content/docs/03-ai-sdk-core/65-event-listeners.mdx
Auto-merging packages/ai/src/embed/embed-many.test.ts
Auto-merging packages/ai/src/embed/embed.test.ts
CONFLICT (content): Merge conflict in packages/ai/src/embed/embed.test.ts
Auto-merging packages/ai/src/generate-text/callback-events.ts
error: could not apply ff9ce30... feat(ai): introduce experimental callbacks for embed function (#13478)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
```

---------

Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
Co-authored-by: Aayush Kapoor <aayushkapoor34@gmail.com>
aayush-kapoor added a commit that referenced this pull request Mar 19, 2026
## Background

as a follow up to this PR #13478,
specifically [this
comment](#13478 (comment)),
there was uneccessary convolution of the data

## Summary

- flatten the `model: {provider, modelId}` to be `provider` and
`modelId` individually
- rename `callback-events.ts` to `core-events.ts`

## Manual Verification

na

## Checklist

- [x] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)

---------

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
aayush-kapoor added a commit that referenced this pull request Mar 20, 2026
## Background

the changes from #13478 were backported
when they shouldn't have been.

## Summary

cherry pick and revert all the changes

## Manual Verification

na

## Checklist

- [x] Tests have been added / updated (for bug fixes / features)
- [x] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)
@aayush-kapoor aayush-kapoor linked an issue Apr 9, 2026 that may be closed by this pull request
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. feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add experimental callbacks to all core functions

2 participants