Build AI-powered applications with Trigger.dev and Postgres change data capture (CDC). Learn how to automatically create embeddings when database records change.
posts
table and then send the payload of the post to an API endpoint that will call tasks.trigger()
to create the embedding and update the database.
As long as you create an HTTP endpoint that Sequin can deliver webhooks to, you can use any web framework or edge function (e.g. Supabase Edge Functions, Vercel Functions, Cloudflare Workers, etc.) to invoke your Trigger.dev task. In this guide, we’ll show you how to setup Trigger.dev tasks using Next.js API Routes.
You’ll need the following to follow this guide:
src/trigger/tasks
directory, create a new file called create-embedding-for-post.ts
and add the following code:post_embeddings
table.create-embedding-for-post
task to your Trigger.dev cloud project by running the following command:create-embedding-for-post
task:create-embedding-for-post
task.
route.ts
file in a /app/api/create-embedding-for-post
directory:create-embedding-for-post
task..env.local
file:SEQUIN_WEBHOOK_SECRET
ensures that only Sequin can access your APIendpoint.The TRIGGER_SECRET_KEY
is used to authenticate requests to Trigger.dev and can be found in the API keys tab of the Trigger.dev dashboard.The OPENAI_API_KEY
and DATABASE_URL
are used to create an embedding using OpenAI and connect to your database. Be sure to add these as environment variables in Trigger.dev as well.public.posts
or public
).30000 ms
for “Request timeout” as this is more than enough time for your function to process the request1
for “Batch size” since you’re just processing one post at a timelocal_endpoint
) and flip the “Use localhost” switchAuthorization
and the value to Bearer SEQUIN_WEBHOOK_SECRET
local_endpoint
and add the path to your API route (i.e. /api/create-embedding-for-post
).posts_webhook_sink
) and click “Create Webhook Sink”.npm run dev
npx trigger.dev@latest dev
sequin tunnel --ports=3001:local_endpoint
200
response in your Next.js app:create-embedding-for-post
task.