ai 6.0.31 → 6.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/00-introduction/index.mdx +76 -0
- package/docs/02-foundations/01-overview.mdx +43 -0
- package/docs/02-foundations/02-providers-and-models.mdx +163 -0
- package/docs/02-foundations/03-prompts.mdx +620 -0
- package/docs/02-foundations/04-tools.mdx +160 -0
- package/docs/02-foundations/05-streaming.mdx +62 -0
- package/docs/02-foundations/index.mdx +43 -0
- package/docs/02-getting-started/00-choosing-a-provider.mdx +110 -0
- package/docs/02-getting-started/01-navigating-the-library.mdx +85 -0
- package/docs/02-getting-started/02-nextjs-app-router.mdx +556 -0
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +542 -0
- package/docs/02-getting-started/04-svelte.mdx +627 -0
- package/docs/02-getting-started/05-nuxt.mdx +566 -0
- package/docs/02-getting-started/06-nodejs.mdx +512 -0
- package/docs/02-getting-started/07-expo.mdx +766 -0
- package/docs/02-getting-started/08-tanstack-start.mdx +583 -0
- package/docs/02-getting-started/index.mdx +44 -0
- package/docs/03-agents/01-overview.mdx +96 -0
- package/docs/03-agents/02-building-agents.mdx +367 -0
- package/docs/03-agents/03-workflows.mdx +370 -0
- package/docs/03-agents/04-loop-control.mdx +350 -0
- package/docs/03-agents/05-configuring-call-options.mdx +286 -0
- package/docs/03-agents/index.mdx +40 -0
- package/docs/03-ai-sdk-core/01-overview.mdx +33 -0
- package/docs/03-ai-sdk-core/05-generating-text.mdx +600 -0
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +662 -0
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +1102 -0
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +375 -0
- package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +144 -0
- package/docs/03-ai-sdk-core/25-settings.mdx +198 -0
- package/docs/03-ai-sdk-core/30-embeddings.mdx +247 -0
- package/docs/03-ai-sdk-core/31-reranking.mdx +218 -0
- package/docs/03-ai-sdk-core/35-image-generation.mdx +341 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +173 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +167 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +480 -0
- package/docs/03-ai-sdk-core/45-provider-management.mdx +349 -0
- package/docs/03-ai-sdk-core/50-error-handling.mdx +149 -0
- package/docs/03-ai-sdk-core/55-testing.mdx +218 -0
- package/docs/03-ai-sdk-core/60-telemetry.mdx +313 -0
- package/docs/03-ai-sdk-core/65-devtools.mdx +107 -0
- package/docs/03-ai-sdk-core/index.mdx +88 -0
- package/docs/04-ai-sdk-ui/01-overview.mdx +44 -0
- package/docs/04-ai-sdk-ui/02-chatbot.mdx +1313 -0
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +535 -0
- package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +263 -0
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +682 -0
- package/docs/04-ai-sdk-ui/04-generative-user-interfaces.mdx +389 -0
- package/docs/04-ai-sdk-ui/05-completion.mdx +186 -0
- package/docs/04-ai-sdk-ui/08-object-generation.mdx +344 -0
- package/docs/04-ai-sdk-ui/20-streaming-data.mdx +397 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +190 -0
- package/docs/04-ai-sdk-ui/21-transport.mdx +174 -0
- package/docs/04-ai-sdk-ui/24-reading-ui-message-streams.mdx +104 -0
- package/docs/04-ai-sdk-ui/25-message-metadata.mdx +152 -0
- package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +477 -0
- package/docs/04-ai-sdk-ui/index.mdx +64 -0
- package/docs/05-ai-sdk-rsc/01-overview.mdx +45 -0
- package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +209 -0
- package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +279 -0
- package/docs/05-ai-sdk-rsc/03-saving-and-restoring-states.mdx +105 -0
- package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +282 -0
- package/docs/05-ai-sdk-rsc/05-streaming-values.mdx +158 -0
- package/docs/05-ai-sdk-rsc/06-loading-state.mdx +273 -0
- package/docs/05-ai-sdk-rsc/08-error-handling.mdx +96 -0
- package/docs/05-ai-sdk-rsc/09-authentication.mdx +42 -0
- package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +722 -0
- package/docs/05-ai-sdk-rsc/index.mdx +58 -0
- package/docs/06-advanced/01-prompt-engineering.mdx +96 -0
- package/docs/06-advanced/02-stopping-streams.mdx +184 -0
- package/docs/06-advanced/03-backpressure.mdx +173 -0
- package/docs/06-advanced/04-caching.mdx +169 -0
- package/docs/06-advanced/05-multiple-streamables.mdx +68 -0
- package/docs/06-advanced/06-rate-limiting.mdx +60 -0
- package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +213 -0
- package/docs/06-advanced/08-model-as-router.mdx +120 -0
- package/docs/06-advanced/09-multistep-interfaces.mdx +115 -0
- package/docs/06-advanced/09-sequential-generations.mdx +55 -0
- package/docs/06-advanced/10-vercel-deployment-guide.mdx +117 -0
- package/docs/06-advanced/index.mdx +11 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2142 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3215 -0
- package/docs/07-reference/01-ai-sdk-core/03-generate-object.mdx +780 -0
- package/docs/07-reference/01-ai-sdk-core/04-stream-object.mdx +1140 -0
- package/docs/07-reference/01-ai-sdk-core/05-embed.mdx +190 -0
- package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +171 -0
- package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +309 -0
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +227 -0
- package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +138 -0
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +214 -0
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +203 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +449 -0
- package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +148 -0
- package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +168 -0
- package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +144 -0
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +196 -0
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +175 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +410 -0
- package/docs/07-reference/01-ai-sdk-core/24-mcp-stdio-transport.mdx +68 -0
- package/docs/07-reference/01-ai-sdk-core/25-json-schema.mdx +94 -0
- package/docs/07-reference/01-ai-sdk-core/26-zod-schema.mdx +109 -0
- package/docs/07-reference/01-ai-sdk-core/27-valibot-schema.mdx +55 -0
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +342 -0
- package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +415 -0
- package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +246 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +101 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +113 -0
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +182 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +121 -0
- package/docs/07-reference/01-ai-sdk-core/50-cosine-similarity.mdx +52 -0
- package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +59 -0
- package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +64 -0
- package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +46 -0
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +68 -0
- package/docs/07-reference/01-ai-sdk-core/67-simulate-streaming-middleware.mdx +71 -0
- package/docs/07-reference/01-ai-sdk-core/68-default-settings-middleware.mdx +80 -0
- package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +155 -0
- package/docs/07-reference/01-ai-sdk-core/70-extract-json-middleware.mdx +147 -0
- package/docs/07-reference/01-ai-sdk-core/70-step-count-is.mdx +84 -0
- package/docs/07-reference/01-ai-sdk-core/71-has-tool-call.mdx +120 -0
- package/docs/07-reference/01-ai-sdk-core/75-simulate-readable-stream.mdx +94 -0
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +145 -0
- package/docs/07-reference/01-ai-sdk-core/90-generate-id.mdx +43 -0
- package/docs/07-reference/01-ai-sdk-core/91-create-id-generator.mdx +89 -0
- package/docs/07-reference/01-ai-sdk-core/index.mdx +159 -0
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +446 -0
- package/docs/07-reference/02-ai-sdk-ui/02-use-completion.mdx +179 -0
- package/docs/07-reference/02-ai-sdk-ui/03-use-object.mdx +178 -0
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +230 -0
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +108 -0
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +151 -0
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +113 -0
- package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +73 -0
- package/docs/07-reference/02-ai-sdk-ui/43-read-ui-message-stream.mdx +57 -0
- package/docs/07-reference/02-ai-sdk-ui/46-infer-ui-tools.mdx +99 -0
- package/docs/07-reference/02-ai-sdk-ui/47-infer-ui-tool.mdx +75 -0
- package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +333 -0
- package/docs/07-reference/02-ai-sdk-ui/index.mdx +89 -0
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +767 -0
- package/docs/07-reference/03-ai-sdk-rsc/02-create-ai.mdx +90 -0
- package/docs/07-reference/03-ai-sdk-rsc/03-create-streamable-ui.mdx +91 -0
- package/docs/07-reference/03-ai-sdk-rsc/04-create-streamable-value.mdx +48 -0
- package/docs/07-reference/03-ai-sdk-rsc/05-read-streamable-value.mdx +78 -0
- package/docs/07-reference/03-ai-sdk-rsc/06-get-ai-state.mdx +50 -0
- package/docs/07-reference/03-ai-sdk-rsc/07-get-mutable-ai-state.mdx +70 -0
- package/docs/07-reference/03-ai-sdk-rsc/08-use-ai-state.mdx +26 -0
- package/docs/07-reference/03-ai-sdk-rsc/09-use-actions.mdx +42 -0
- package/docs/07-reference/03-ai-sdk-rsc/10-use-ui-state.mdx +35 -0
- package/docs/07-reference/03-ai-sdk-rsc/11-use-streamable-value.mdx +46 -0
- package/docs/07-reference/03-ai-sdk-rsc/20-render.mdx +262 -0
- package/docs/07-reference/03-ai-sdk-rsc/index.mdx +67 -0
- package/docs/07-reference/04-stream-helpers/01-ai-stream.mdx +89 -0
- package/docs/07-reference/04-stream-helpers/02-streaming-text-response.mdx +79 -0
- package/docs/07-reference/04-stream-helpers/05-stream-to-response.mdx +108 -0
- package/docs/07-reference/04-stream-helpers/07-openai-stream.mdx +77 -0
- package/docs/07-reference/04-stream-helpers/08-anthropic-stream.mdx +79 -0
- package/docs/07-reference/04-stream-helpers/09-aws-bedrock-stream.mdx +91 -0
- package/docs/07-reference/04-stream-helpers/10-aws-bedrock-anthropic-stream.mdx +96 -0
- package/docs/07-reference/04-stream-helpers/10-aws-bedrock-messages-stream.mdx +96 -0
- package/docs/07-reference/04-stream-helpers/11-aws-bedrock-cohere-stream.mdx +93 -0
- package/docs/07-reference/04-stream-helpers/12-aws-bedrock-llama-2-stream.mdx +93 -0
- package/docs/07-reference/04-stream-helpers/13-cohere-stream.mdx +78 -0
- package/docs/07-reference/04-stream-helpers/14-google-generative-ai-stream.mdx +85 -0
- package/docs/07-reference/04-stream-helpers/15-hugging-face-stream.mdx +84 -0
- package/docs/07-reference/04-stream-helpers/16-langchain-adapter.mdx +98 -0
- package/docs/07-reference/04-stream-helpers/16-llamaindex-adapter.mdx +70 -0
- package/docs/07-reference/04-stream-helpers/17-mistral-stream.mdx +81 -0
- package/docs/07-reference/04-stream-helpers/18-replicate-stream.mdx +83 -0
- package/docs/07-reference/04-stream-helpers/19-inkeep-stream.mdx +80 -0
- package/docs/07-reference/04-stream-helpers/index.mdx +103 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-api-call-error.mdx +30 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-download-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-empty-response-body-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-argument-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-message-role-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-prompt-error.mdx +47 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-response-data-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-approval-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-input-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-json-parse-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-load-api-key-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-load-setting-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-message-conversion-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-content-generated-error.mdx +24 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +36 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-object-generated-error.mdx +43 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-speech-generated-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +28 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-tool-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-transcript-generated-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-retry-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-too-many-embedding-values-for-call-error.mdx +27 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-not-found-for-approval-error.mdx +26 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-repair-error.mdx +28 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-type-validation-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-unsupported-functionality-error.mdx +25 -0
- package/docs/07-reference/05-ai-sdk-errors/index.mdx +38 -0
- package/docs/07-reference/index.mdx +34 -0
- package/docs/08-migration-guides/00-versioning.mdx +46 -0
- package/docs/08-migration-guides/24-migration-guide-6-0.mdx +823 -0
- package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +882 -0
- package/docs/08-migration-guides/26-migration-guide-5-0.mdx +3427 -0
- package/docs/08-migration-guides/27-migration-guide-4-2.mdx +99 -0
- package/docs/08-migration-guides/28-migration-guide-4-1.mdx +14 -0
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1157 -0
- package/docs/08-migration-guides/36-migration-guide-3-4.mdx +14 -0
- package/docs/08-migration-guides/37-migration-guide-3-3.mdx +64 -0
- package/docs/08-migration-guides/38-migration-guide-3-2.mdx +46 -0
- package/docs/08-migration-guides/39-migration-guide-3-1.mdx +168 -0
- package/docs/08-migration-guides/index.mdx +22 -0
- package/docs/09-troubleshooting/01-azure-stream-slow.mdx +33 -0
- package/docs/09-troubleshooting/02-client-side-function-calls-not-invoked.mdx +22 -0
- package/docs/09-troubleshooting/03-server-actions-in-client-components.mdx +40 -0
- package/docs/09-troubleshooting/04-strange-stream-output.mdx +36 -0
- package/docs/09-troubleshooting/05-streamable-ui-errors.mdx +16 -0
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +106 -0
- package/docs/09-troubleshooting/06-streaming-not-working-when-deployed.mdx +31 -0
- package/docs/09-troubleshooting/06-streaming-not-working-when-proxied.mdx +31 -0
- package/docs/09-troubleshooting/06-timeout-on-vercel.mdx +60 -0
- package/docs/09-troubleshooting/07-unclosed-streams.mdx +34 -0
- package/docs/09-troubleshooting/08-use-chat-failed-to-parse-stream.mdx +26 -0
- package/docs/09-troubleshooting/09-client-stream-error.mdx +25 -0
- package/docs/09-troubleshooting/10-use-chat-tools-no-response.mdx +32 -0
- package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +149 -0
- package/docs/09-troubleshooting/12-typescript-performance-zod.mdx +46 -0
- package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +59 -0
- package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +73 -0
- package/docs/09-troubleshooting/14-stream-abort-handling.mdx +73 -0
- package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +48 -0
- package/docs/09-troubleshooting/15-abort-breaks-resumable-streams.mdx +55 -0
- package/docs/09-troubleshooting/15-stream-text-not-working.mdx +33 -0
- package/docs/09-troubleshooting/16-streaming-status-delay.mdx +63 -0
- package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +141 -0
- package/docs/09-troubleshooting/18-ontoolcall-type-narrowing.mdx +66 -0
- package/docs/09-troubleshooting/19-unsupported-model-version.mdx +50 -0
- package/docs/09-troubleshooting/20-no-object-generated-content-filter.mdx +72 -0
- package/docs/09-troubleshooting/30-model-is-not-assignable-to-type.mdx +21 -0
- package/docs/09-troubleshooting/40-typescript-cannot-find-namespace-jsx.mdx +24 -0
- package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +39 -0
- package/docs/09-troubleshooting/60-jest-cannot-find-module-ai-rsc.mdx +22 -0
- package/docs/09-troubleshooting/index.mdx +11 -0
- package/package.json +8 -4
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: embed
|
|
3
|
+
description: API Reference for embed.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `embed()`
|
|
7
|
+
|
|
8
|
+
Generate an embedding for a single value using an embedding model.
|
|
9
|
+
|
|
10
|
+
This is ideal for use cases where you need to embed a single value to e.g. retrieve similar items or to use the embedding in a downstream task.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { embed } from 'ai';
|
|
14
|
+
|
|
15
|
+
const { embedding } = await embed({
|
|
16
|
+
model: 'openai/text-embedding-3-small',
|
|
17
|
+
value: 'sunny day at the beach',
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Import
|
|
22
|
+
|
|
23
|
+
<Snippet text={`import { embed } from "ai"`} prompt={false} />
|
|
24
|
+
|
|
25
|
+
## API Signature
|
|
26
|
+
|
|
27
|
+
### Parameters
|
|
28
|
+
|
|
29
|
+
<PropertiesTable
|
|
30
|
+
content={[
|
|
31
|
+
{
|
|
32
|
+
name: 'model',
|
|
33
|
+
type: 'EmbeddingModel',
|
|
34
|
+
description:
|
|
35
|
+
"The embedding model to use. Example: openai.embeddingModel('text-embedding-3-small')",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'value',
|
|
39
|
+
type: 'VALUE',
|
|
40
|
+
description: 'The value to embed. The type depends on the model.',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'maxRetries',
|
|
44
|
+
type: 'number',
|
|
45
|
+
isOptional: true,
|
|
46
|
+
description:
|
|
47
|
+
'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'abortSignal',
|
|
51
|
+
type: 'AbortSignal',
|
|
52
|
+
isOptional: true,
|
|
53
|
+
description:
|
|
54
|
+
'An optional abort signal that can be used to cancel the call.',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'headers',
|
|
58
|
+
type: 'Record<string, string>',
|
|
59
|
+
isOptional: true,
|
|
60
|
+
description:
|
|
61
|
+
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'experimental_telemetry',
|
|
65
|
+
type: 'TelemetrySettings',
|
|
66
|
+
isOptional: true,
|
|
67
|
+
description: 'Telemetry configuration. Experimental feature.',
|
|
68
|
+
properties: [
|
|
69
|
+
{
|
|
70
|
+
type: 'TelemetrySettings',
|
|
71
|
+
parameters: [
|
|
72
|
+
{
|
|
73
|
+
name: 'isEnabled',
|
|
74
|
+
type: 'boolean',
|
|
75
|
+
isOptional: true,
|
|
76
|
+
description:
|
|
77
|
+
'Enable or disable telemetry. Disabled by default while experimental.',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'recordInputs',
|
|
81
|
+
type: 'boolean',
|
|
82
|
+
isOptional: true,
|
|
83
|
+
description:
|
|
84
|
+
'Enable or disable input recording. Enabled by default.',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'recordOutputs',
|
|
88
|
+
type: 'boolean',
|
|
89
|
+
isOptional: true,
|
|
90
|
+
description:
|
|
91
|
+
'Enable or disable output recording. Enabled by default.',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'functionId',
|
|
95
|
+
type: 'string',
|
|
96
|
+
isOptional: true,
|
|
97
|
+
description:
|
|
98
|
+
'Identifier for this function. Used to group telemetry data by function.',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'metadata',
|
|
102
|
+
isOptional: true,
|
|
103
|
+
type: 'Record<string, string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>>',
|
|
104
|
+
description:
|
|
105
|
+
'Additional information to include in the telemetry data.',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'tracer',
|
|
109
|
+
type: 'Tracer',
|
|
110
|
+
isOptional: true,
|
|
111
|
+
description: 'A custom tracer to use for the telemetry data.',
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
]}
|
|
118
|
+
/>
|
|
119
|
+
|
|
120
|
+
### Returns
|
|
121
|
+
|
|
122
|
+
<PropertiesTable
|
|
123
|
+
content={[
|
|
124
|
+
{
|
|
125
|
+
name: 'value',
|
|
126
|
+
type: 'VALUE',
|
|
127
|
+
description: 'The value that was embedded.',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'embedding',
|
|
131
|
+
type: 'number[]',
|
|
132
|
+
description: 'The embedding of the value.',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'usage',
|
|
136
|
+
type: 'EmbeddingModelUsage',
|
|
137
|
+
description: 'The token usage for generating the embeddings.',
|
|
138
|
+
properties: [
|
|
139
|
+
{
|
|
140
|
+
type: 'EmbeddingModelUsage',
|
|
141
|
+
parameters: [
|
|
142
|
+
{
|
|
143
|
+
name: 'tokens',
|
|
144
|
+
type: 'number',
|
|
145
|
+
description: 'The number of tokens used in the embedding.',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'warnings',
|
|
153
|
+
type: 'Warning[]',
|
|
154
|
+
description:
|
|
155
|
+
'Warnings from the model provider (e.g. unsupported settings).',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'response',
|
|
159
|
+
type: 'Response',
|
|
160
|
+
isOptional: true,
|
|
161
|
+
description: 'Optional response data.',
|
|
162
|
+
properties: [
|
|
163
|
+
{
|
|
164
|
+
type: 'Response',
|
|
165
|
+
parameters: [
|
|
166
|
+
{
|
|
167
|
+
name: 'headers',
|
|
168
|
+
isOptional: true,
|
|
169
|
+
type: 'Record<string, string>',
|
|
170
|
+
description: 'Response headers.',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'body',
|
|
174
|
+
type: 'unknown',
|
|
175
|
+
isOptional: true,
|
|
176
|
+
description: 'The response body.',
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'providerMetadata',
|
|
184
|
+
type: 'ProviderMetadata | undefined',
|
|
185
|
+
isOptional: true,
|
|
186
|
+
description:
|
|
187
|
+
'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
|
|
188
|
+
},
|
|
189
|
+
]}
|
|
190
|
+
/>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: embedMany
|
|
3
|
+
description: API Reference for embedMany.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `embedMany()`
|
|
7
|
+
|
|
8
|
+
Embed several values using an embedding model. The type of the value is defined
|
|
9
|
+
by the embedding model.
|
|
10
|
+
|
|
11
|
+
`embedMany` automatically splits large requests into smaller chunks if the model
|
|
12
|
+
has a limit on how many embeddings can be generated in a single call.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { embedMany } from 'ai';
|
|
16
|
+
|
|
17
|
+
const { embeddings } = await embedMany({
|
|
18
|
+
model: 'openai/text-embedding-3-small',
|
|
19
|
+
values: [
|
|
20
|
+
'sunny day at the beach',
|
|
21
|
+
'rainy afternoon in the city',
|
|
22
|
+
'snowy night in the mountains',
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Import
|
|
28
|
+
|
|
29
|
+
<Snippet text={`import { embedMany } from "ai"`} prompt={false} />
|
|
30
|
+
|
|
31
|
+
## API Signature
|
|
32
|
+
|
|
33
|
+
### Parameters
|
|
34
|
+
|
|
35
|
+
<PropertiesTable
|
|
36
|
+
content={[
|
|
37
|
+
{
|
|
38
|
+
name: 'model',
|
|
39
|
+
type: 'EmbeddingModel',
|
|
40
|
+
description:
|
|
41
|
+
"The embedding model to use. Example: openai.embeddingModel('text-embedding-3-small')",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'values',
|
|
45
|
+
type: 'Array<VALUE>',
|
|
46
|
+
description: 'The values to embed. The type depends on the model.',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'maxRetries',
|
|
50
|
+
type: 'number',
|
|
51
|
+
isOptional: true,
|
|
52
|
+
description:
|
|
53
|
+
'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'abortSignal',
|
|
57
|
+
type: 'AbortSignal',
|
|
58
|
+
isOptional: true,
|
|
59
|
+
description:
|
|
60
|
+
'An optional abort signal that can be used to cancel the call.',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'headers',
|
|
64
|
+
type: 'Record<string, string>',
|
|
65
|
+
isOptional: true,
|
|
66
|
+
description:
|
|
67
|
+
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'experimental_telemetry',
|
|
71
|
+
type: 'TelemetrySettings',
|
|
72
|
+
isOptional: true,
|
|
73
|
+
description: 'Telemetry configuration. Experimental feature.',
|
|
74
|
+
properties: [
|
|
75
|
+
{
|
|
76
|
+
type: 'TelemetrySettings',
|
|
77
|
+
parameters: [
|
|
78
|
+
{
|
|
79
|
+
name: 'isEnabled',
|
|
80
|
+
type: 'boolean',
|
|
81
|
+
isOptional: true,
|
|
82
|
+
description:
|
|
83
|
+
'Enable or disable telemetry. Disabled by default while experimental.',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'recordInputs',
|
|
87
|
+
type: 'boolean',
|
|
88
|
+
isOptional: true,
|
|
89
|
+
description:
|
|
90
|
+
'Enable or disable input recording. Enabled by default.',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'recordOutputs',
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
isOptional: true,
|
|
96
|
+
description:
|
|
97
|
+
'Enable or disable output recording. Enabled by default.',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'functionId',
|
|
101
|
+
type: 'string',
|
|
102
|
+
isOptional: true,
|
|
103
|
+
description:
|
|
104
|
+
'Identifier for this function. Used to group telemetry data by function.',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'metadata',
|
|
108
|
+
isOptional: true,
|
|
109
|
+
type: 'Record<string, string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>>',
|
|
110
|
+
description:
|
|
111
|
+
'Additional information to include in the telemetry data.',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'tracer',
|
|
115
|
+
type: 'Tracer',
|
|
116
|
+
isOptional: true,
|
|
117
|
+
description: 'A custom tracer to use for the telemetry data.',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
]}
|
|
124
|
+
/>
|
|
125
|
+
|
|
126
|
+
### Returns
|
|
127
|
+
|
|
128
|
+
<PropertiesTable
|
|
129
|
+
content={[
|
|
130
|
+
{
|
|
131
|
+
name: 'values',
|
|
132
|
+
type: 'Array<VALUE>',
|
|
133
|
+
description: 'The values that were embedded.',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'embeddings',
|
|
137
|
+
type: 'number[][]',
|
|
138
|
+
description: 'The embeddings. They are in the same order as the values.',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'usage',
|
|
142
|
+
type: 'EmbeddingModelUsage',
|
|
143
|
+
description: 'The token usage for generating the embeddings.',
|
|
144
|
+
properties: [
|
|
145
|
+
{
|
|
146
|
+
type: 'EmbeddingModelUsage',
|
|
147
|
+
parameters: [
|
|
148
|
+
{
|
|
149
|
+
name: 'tokens',
|
|
150
|
+
type: 'number',
|
|
151
|
+
description: 'The total number of input tokens.',
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'warnings',
|
|
159
|
+
type: 'Warning[]',
|
|
160
|
+
description:
|
|
161
|
+
'Warnings from the model provider (e.g. unsupported settings).',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'providerMetadata',
|
|
165
|
+
type: 'ProviderMetadata | undefined',
|
|
166
|
+
isOptional: true,
|
|
167
|
+
description:
|
|
168
|
+
'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
|
|
169
|
+
},
|
|
170
|
+
]}
|
|
171
|
+
/>
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: rerank
|
|
3
|
+
description: API Reference for rerank.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `rerank()`
|
|
7
|
+
|
|
8
|
+
Rerank a set of documents based on their relevance to a query using a reranking model.
|
|
9
|
+
|
|
10
|
+
This is ideal for improving search relevance by reordering documents, emails, or other content based on semantic understanding of the query and documents.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { cohere } from '@ai-sdk/cohere';
|
|
14
|
+
import { rerank } from 'ai';
|
|
15
|
+
|
|
16
|
+
const { ranking } = await rerank({
|
|
17
|
+
model: cohere.reranking('rerank-v3.5'),
|
|
18
|
+
documents: ['sunny day at the beach', 'rainy afternoon in the city'],
|
|
19
|
+
query: 'talk about rain',
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Import
|
|
24
|
+
|
|
25
|
+
<Snippet text={`import { rerank } from "ai"`} prompt={false} />
|
|
26
|
+
|
|
27
|
+
## API Signature
|
|
28
|
+
|
|
29
|
+
### Parameters
|
|
30
|
+
|
|
31
|
+
<PropertiesTable
|
|
32
|
+
content={[
|
|
33
|
+
{
|
|
34
|
+
name: 'model',
|
|
35
|
+
type: 'RerankingModel',
|
|
36
|
+
description:
|
|
37
|
+
"The reranking model to use. Example: cohere.reranking('rerank-v3.5')",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'documents',
|
|
41
|
+
type: 'Array<VALUE>',
|
|
42
|
+
description:
|
|
43
|
+
'The documents to rerank. Can be an array of strings or JSON objects.',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'query',
|
|
47
|
+
type: 'string',
|
|
48
|
+
description: 'The search query to rank documents against.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'topN',
|
|
52
|
+
type: 'number',
|
|
53
|
+
isOptional: true,
|
|
54
|
+
description:
|
|
55
|
+
'Maximum number of top documents to return. If not specified, all documents are returned.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'maxRetries',
|
|
59
|
+
type: 'number',
|
|
60
|
+
isOptional: true,
|
|
61
|
+
description:
|
|
62
|
+
'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'abortSignal',
|
|
66
|
+
type: 'AbortSignal',
|
|
67
|
+
isOptional: true,
|
|
68
|
+
description:
|
|
69
|
+
'An optional abort signal that can be used to cancel the call.',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'headers',
|
|
73
|
+
type: 'Record<string, string>',
|
|
74
|
+
isOptional: true,
|
|
75
|
+
description:
|
|
76
|
+
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'providerOptions',
|
|
80
|
+
type: 'ProviderOptions',
|
|
81
|
+
isOptional: true,
|
|
82
|
+
description: 'Provider-specific options for the reranking request.',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'experimental_telemetry',
|
|
86
|
+
type: 'TelemetrySettings',
|
|
87
|
+
isOptional: true,
|
|
88
|
+
description: 'Telemetry configuration. Experimental feature.',
|
|
89
|
+
properties: [
|
|
90
|
+
{
|
|
91
|
+
type: 'TelemetrySettings',
|
|
92
|
+
parameters: [
|
|
93
|
+
{
|
|
94
|
+
name: 'isEnabled',
|
|
95
|
+
type: 'boolean',
|
|
96
|
+
isOptional: true,
|
|
97
|
+
description:
|
|
98
|
+
'Enable or disable telemetry. Disabled by default while experimental.',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'recordInputs',
|
|
102
|
+
type: 'boolean',
|
|
103
|
+
isOptional: true,
|
|
104
|
+
description:
|
|
105
|
+
'Enable or disable input recording. Enabled by default.',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'recordOutputs',
|
|
109
|
+
type: 'boolean',
|
|
110
|
+
isOptional: true,
|
|
111
|
+
description:
|
|
112
|
+
'Enable or disable output recording. Enabled by default.',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'functionId',
|
|
116
|
+
type: 'string',
|
|
117
|
+
isOptional: true,
|
|
118
|
+
description:
|
|
119
|
+
'Identifier for this function. Used to group telemetry data by function.',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'metadata',
|
|
123
|
+
isOptional: true,
|
|
124
|
+
type: 'Record<string, string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>>',
|
|
125
|
+
description:
|
|
126
|
+
'Additional information to include in the telemetry data.',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'tracer',
|
|
130
|
+
type: 'Tracer',
|
|
131
|
+
isOptional: true,
|
|
132
|
+
description: 'A custom tracer to use for the telemetry data.',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
]}
|
|
139
|
+
/>
|
|
140
|
+
|
|
141
|
+
### Returns
|
|
142
|
+
|
|
143
|
+
<PropertiesTable
|
|
144
|
+
content={[
|
|
145
|
+
{
|
|
146
|
+
name: 'originalDocuments',
|
|
147
|
+
type: 'Array<VALUE>',
|
|
148
|
+
description: 'The original documents array in their original order.',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: 'rerankedDocuments',
|
|
152
|
+
type: 'Array<VALUE>',
|
|
153
|
+
description: 'The documents sorted by relevance score (descending).',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'ranking',
|
|
157
|
+
type: 'Array<RankingItem<VALUE>>',
|
|
158
|
+
description: 'Array of ranking items with scores and indices.',
|
|
159
|
+
properties: [
|
|
160
|
+
{
|
|
161
|
+
type: 'RankingItem<VALUE>',
|
|
162
|
+
parameters: [
|
|
163
|
+
{
|
|
164
|
+
name: 'originalIndex',
|
|
165
|
+
type: 'number',
|
|
166
|
+
description:
|
|
167
|
+
'The index of the document in the original documents array.',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'score',
|
|
171
|
+
type: 'number',
|
|
172
|
+
description:
|
|
173
|
+
'The relevance score for the document (typically 0-1, where higher is more relevant).',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'document',
|
|
177
|
+
type: 'VALUE',
|
|
178
|
+
description: 'The document itself.',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: 'response',
|
|
186
|
+
type: 'Response',
|
|
187
|
+
description: 'Response data.',
|
|
188
|
+
properties: [
|
|
189
|
+
{
|
|
190
|
+
type: 'Response',
|
|
191
|
+
parameters: [
|
|
192
|
+
{
|
|
193
|
+
name: 'id',
|
|
194
|
+
isOptional: true,
|
|
195
|
+
type: 'string',
|
|
196
|
+
description: 'The response ID from the provider.',
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: 'timestamp',
|
|
200
|
+
type: 'Date',
|
|
201
|
+
description: 'The timestamp of the response.',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: 'modelId',
|
|
205
|
+
type: 'string',
|
|
206
|
+
description: 'The model ID used for reranking.',
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: 'headers',
|
|
210
|
+
isOptional: true,
|
|
211
|
+
type: 'Record<string, string>',
|
|
212
|
+
description: 'Response headers.',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: 'body',
|
|
216
|
+
type: 'unknown',
|
|
217
|
+
isOptional: true,
|
|
218
|
+
description: 'The raw response body.',
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: 'providerMetadata',
|
|
226
|
+
type: 'ProviderMetadata | undefined',
|
|
227
|
+
isOptional: true,
|
|
228
|
+
description:
|
|
229
|
+
'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
|
|
230
|
+
},
|
|
231
|
+
]}
|
|
232
|
+
/>
|
|
233
|
+
|
|
234
|
+
## Examples
|
|
235
|
+
|
|
236
|
+
### String Documents
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
import { cohere } from '@ai-sdk/cohere';
|
|
240
|
+
import { rerank } from 'ai';
|
|
241
|
+
|
|
242
|
+
const { ranking, rerankedDocuments } = await rerank({
|
|
243
|
+
model: cohere.reranking('rerank-v3.5'),
|
|
244
|
+
documents: [
|
|
245
|
+
'sunny day at the beach',
|
|
246
|
+
'rainy afternoon in the city',
|
|
247
|
+
'snowy night in the mountains',
|
|
248
|
+
],
|
|
249
|
+
query: 'talk about rain',
|
|
250
|
+
topN: 2,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
console.log(rerankedDocuments);
|
|
254
|
+
// ['rainy afternoon in the city', 'sunny day at the beach']
|
|
255
|
+
|
|
256
|
+
console.log(ranking);
|
|
257
|
+
// [
|
|
258
|
+
// { originalIndex: 1, score: 0.9, document: 'rainy afternoon...' },
|
|
259
|
+
// { originalIndex: 0, score: 0.3, document: 'sunny day...' }
|
|
260
|
+
// ]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Object Documents
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { cohere } from '@ai-sdk/cohere';
|
|
267
|
+
import { rerank } from 'ai';
|
|
268
|
+
|
|
269
|
+
const documents = [
|
|
270
|
+
{
|
|
271
|
+
from: 'Paul Doe',
|
|
272
|
+
subject: 'Follow-up',
|
|
273
|
+
text: 'We are happy to give you a discount of 20%.',
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
from: 'John McGill',
|
|
277
|
+
subject: 'Missing Info',
|
|
278
|
+
text: 'Here is the pricing from Oracle: $5000/month',
|
|
279
|
+
},
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
const { ranking } = await rerank({
|
|
283
|
+
model: cohere.reranking('rerank-v3.5'),
|
|
284
|
+
documents,
|
|
285
|
+
query: 'Which pricing did we get from Oracle?',
|
|
286
|
+
topN: 1,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
console.log(ranking[0].document);
|
|
290
|
+
// { from: 'John McGill', subject: 'Missing Info', ... }
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### With Provider Options
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
import { cohere } from '@ai-sdk/cohere';
|
|
297
|
+
import { rerank } from 'ai';
|
|
298
|
+
|
|
299
|
+
const { ranking } = await rerank({
|
|
300
|
+
model: cohere.reranking('rerank-v3.5'),
|
|
301
|
+
documents: ['sunny day at the beach', 'rainy afternoon in the city'],
|
|
302
|
+
query: 'talk about rain',
|
|
303
|
+
providerOptions: {
|
|
304
|
+
cohere: {
|
|
305
|
+
maxTokensPerDoc: 1000,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
```
|