Contentful webhooks mean I never push to Supabase manually. Claude Code wrote it in 15 minutes.
The RAG search index now updates itself every time I publish a Field Note. One endpoint, one webhook, done.
After #019 shipped RAG search, the index needed updating every time I published a new Field Note. The command was npm run embed. Simple enough. But simple commands you have to remember are still commands you have to remember.
Contentful has webhooks. Claude Code wrote the endpoint. The whole thing took 15 minutes.
Contentful fires a webhook on publish. The endpoint does the rest.
The new route at app/api/reindex receives the webhook, reads the entry ID from the payload, fetches the full Field Note from the Contentful Delivery API, runs the same chunking logic from #019, and upserts the fresh embeddings to Supabase. Clean slate per slug, new chunks in.
Auth is a REINDEX_SECRET environment variable checked against the Authorization header. Wrong token gets a 401. Contentful sends the header with every call automatically.
In Contentful: Settings → Webhooks → one entry, trigger on Entry Published, filter to fieldNote content type, custom header with the secret. That is the entire configuration.
One thing worth knowing: the webhook payload is minimal.
Contentful sends sys.id and some metadata. It does not send the full entry. The route fetches the complete entry separately using the Delivery API with include=2 to resolve linked entries and assets. Quick to handle, just not obvious the first time.
Active. 100% successful calls.
That is the webhook status in Contentful after the first real publish fired it. The search index updates itself now. Publish a Field Note, ASK ✦ knows about it within seconds.
npm run embed still exists for full corpus re-indexes. Otherwise, it is retired.
Stats field
Trigger: Contentful Entry Published, filtered to fieldNote Endpoint: app/api/reindex Shared logic: lib/embed.ts Build time: 15 minutes Session cost: $1.05 Total tokens: 1.5M Model: claude-opus-4-6 Webhook status: Active, 100% successful calls