Add Entries Asynchronously using File Storage#
import { httpRouter } from "convex/server";
import { authComponent, createAuth } from "./auth";
import { corsRouter } from "convex-helpers/server/cors";
import { internal } from "./_generated/api";
import { rag } from "./rag";
import { httpAction } from "./_generated/server";
import { Id } from "./_generated/dataModel";
const cors = corsRouter(httpRouter());
cors.route({
path: "/upload",
method: "POST",
handler: httpAction(async (ctx, request) => {
const storageId = await ctx.storage.store(await request.blob());
await rag.addAsync(ctx, {
namespace: "all-files",
chunkerAction: internal.http.chunkerAction,
metadata: { storageId },
});
return new Response();
}),
});
export const chunkerAction = rag.defineChunkerAction(async (ctx, args) => {
const storageId = args.entry.metadata!.storageId;
const file = await ctx.storage.get(storageId as Id<"_storage">);
const text = await new TextDecoder().decode(await file!.arrayBuffer());
return { chunks: text.split("\n\n") };
});
authComponent.registerRoutes(cors.http, createAuth);
export default cors.http;
import { httpRouter } from "convex/server";
import { authComponent, createAuth } from "./auth";
import { corsRouter } from "convex-helpers/server/cors";
import { internal } from "./_generated/api";
import { rag } from "./rag";
import { httpAction } from "./_generated/server";
import { Id } from "./_generated/dataModel";
const cors = corsRouter(httpRouter());
cors.route({
path: "/upload",
method: "POST",
handler: httpAction(async (ctx, request) => {
const storageId = await ctx.storage.store(await request.blob());
await rag.addAsync(ctx, {
namespace: "all-files",
chunkerAction: internal.http.chunkerAction,
metadata: { storageId },
});
return new Response();
}),
});
export const chunkerAction = rag.defineChunkerAction(async (ctx, args) => {
const storageId = args.entry.metadata!.storageId;
const file = await ctx.storage.get(storageId as Id<"_storage">);
const text = await new TextDecoder().decode(await file!.arrayBuffer());
return { chunks: text.split("\n\n") };
});
authComponent.registerRoutes(cors.http, createAuth);
export default cors.http;
/upload throws the errors listed below:2 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
10/3/2025, 11:21:07 AM [CONVEX A(http:chunkerAction)] Uncaught AI_APICallError: Bad Request
at <anonymous> (../../../../node_modules/@ai-sdk/provider-utils/src/response-handler.ts:70:10)
at async postToApi (../../../../node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:118:10)
at async doEmbed [as doEmbed] (../../../../node_modules/@ai-sdk/openai-compatible/src/embedding/openai-compatible-embedding-model.ts:107:6)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:255:20)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async _retryWithExponentialBackoff (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:11)
at async Promise.all (index 0)all [as all] (<anonymous>)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:233:28)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async createChunkArgsBatch (../../../../node_modules/@convex-dev/rag/src/client/index.ts:1013:13)
]
10/3/2025, 11:21:07 AM [CONVEX A(http:chunkerAction)] Uncaught AI_APICallError: Bad Request
at <anonymous> (../../../../node_modules/@ai-sdk/provider-utils/src/response-handler.ts:70:10)
at async postToApi (../../../../node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:118:10)
at async doEmbed [as doEmbed] (../../../../node_modules/@ai-sdk/openai-compatible/src/embedding/openai-compatible-embedding-model.ts:107:6)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:255:20)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async _retryWithExponentialBackoff (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:11)
at async Promise.all (index 0)all [as all] (<anonymous>)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:233:28)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async createChunkArgsBatch (../../../../node_modules/@convex-dev/rag/src/client/index.ts:1013:13)
]
10/3/2025, 11:21:07 AM [CONVEX A(worker:runActionWrapper)] [ERROR] [Error: Uncaught AI_APICallError: Bad Request
at <anonymous> (../../../../node_modules/@ai-sdk/provider-utils/src/response-handler.ts:70:10)
at async postToApi (../../../../node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:118:10)
at async doEmbed [as doEmbed] (../../../../node_modules/@ai-sdk/openai-compatible/src/embedding/openai-compatible-embedding-model.ts:107:6)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:255:20)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async _retryWithExponentialBackoff (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:11)
at async Promise.all (index 0)all [as all] (<anonymous>)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:233:28)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async createChunkArgsBatch (../../../../node_modules/@convex-dev/rag/src/client/index.ts:1013:13)
]
10/3/2025, 11:21:07 AM [CONVEX A(worker:runActionWrapper)] [ERROR] [Error: Uncaught AI_APICallError: Bad Request
at <anonymous> (../../../../node_modules/@ai-sdk/provider-utils/src/response-handler.ts:70:10)
at async postToApi (../../../../node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:118:10)
at async doEmbed [as doEmbed] (../../../../node_modules/@ai-sdk/openai-compatible/src/embedding/openai-compatible-embedding-model.ts:107:6)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:255:20)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async _retryWithExponentialBackoff (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:11)
at async Promise.all (index 0)all [as all] (<anonymous>)
at async fn (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/embed/embed-many.ts:233:28)
at async <anonymous> (../../../../node_modules/@convex-dev/rag/node_modules/ai/src/telemetry/record-span.ts:19:10)
at async createChunkArgsBatch (../../../../node_modules/@convex-dev/rag/src/client/index.ts:1013:13)
]