Skip to main content
A “search my videos” or “chat with this video” feature needs two things: the transcript, with times, and a way to find the part that answers a question. On Supabase both fit in the project you already have. Importly returns the transcript with start times for every line, Supabase’s built-in gte-small model turns each chunk into an embedding inside an Edge Function, and pgvector finds the closest chunks to a question. You don’t need an OpenAI key or a separate vector database. This recipe builds on Save transcripts to Supabase from an Edge Function. Set that up first: it gives you the transcripts table, the start-transcript and importly-webhook functions, and the sweep for missed webhooks. Here you add:
  • a transcript_chunks table with a pgvector column, and a match_transcript_chunks function;
  • index-transcripts, which splits finished transcripts into chunks and embeds them a few at a time;
  • search-transcripts, which takes a user’s question and returns the matching moments from that user’s own videos.

1. The table and the search function

Run this in the SQL editor or add it as a migration. Users can read only their own chunks, and match_transcript_chunks runs as the caller, so the same RLS policy limits every search to their own videos.
gte-small returns 384 numbers per text, which is why the column is vector(384). A chunk’s embedding stays null until index-transcripts gets to it, and searches skip those rows.

2. Chunk and embed

Put the shared code next to the importly.ts helper from the transcripts recipe. The transcript’s segments are short lines with start and end in seconds; joining them into about 30 seconds of speech gives each chunk enough words to match a question and a start time to jump to.
supabase/functions/_shared/chunks.ts
The batch is small on purpose. One embedding takes about 160 ms of CPU, and when we embedded a whole 18-minute transcript (35 chunks) in one call, the function failed with 546 WORKER_RESOURCE_LIMIT before the tenth. Five per call stays well inside the limit.

3. The indexing function

Each call chunks any newly finished transcripts, embeds one batch, and calls itself again while there is more to do. Claiming a transcript with chunked_at first means two calls at once never chunk the same video twice.
supabase/functions/index-transcripts/index.ts
In our test this embedded all 35 chunks of an 18-minute video about 15 seconds after the first call, in seven calls. Start it as soon as a transcript is saved: in importly-webhook from the transcripts recipe, add one call after saveJob:
supabase/functions/importly-webhook/index.ts
Also schedule index-transcripts every few minutes with Supabase Cron, next to sweep-transcripts. That picks up transcripts the sweep saved and any batch whose call failed.

4. The search function

The frontend calls this with the user’s session. The function embeds the question with the same model and asks Postgres for the five closest chunks the user is allowed to see.
supabase/functions/search-transcripts/index.ts
Deploy both:

5. Call it from your app

For other sites, or a file you saved to Supabase Storage, seek your own player to start_seconds. We ran this against a real 18-minute lecture (3Blue1Brown’s “But what is a neural network?”). The question “how does the network learn its weights” returned five moments between 9:08 and 15:31, the part of the video that explains weights and biases. A second signed-in user got an empty list for the same question, and a call without a session got 401.

Things to know

Only finished transcripts are indexed. A transcript that failed (a private or removed video) keeps status: 'failed' and never gets chunks. Long videos take more calls. A two-hour video is about 240 chunks, so about 48 calls, and each Edge Function call counts toward your Supabase plan’s invocations. gte-small is trained on English text. For videos in other languages, use a multilingual embedding model and change vector(384) to its size. To answer in sentences rather than return the moments (“chat with this video”), send the top matches and the question to the model your app already uses, and show each start_seconds as a citation.
A transcript from captions costs $0.003. Speech-to-text for a video without captions is $0.01 per minute, and maxCostDollars stops a long one before it’s charged. The embeddings run inside your Supabase project, so Importly doesn’t charge for them. Try it free, no card required. See Pricing & credits.

Let your agent write it

Using Lovable’s chat, Bolt, Claude Code or Cursor on this project? Connect the MCP server and ask it to add transcript search with Importly and pgvector: it reads the same integration guide and can test with a real link first. See Build with your agent.