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_chunkstable with a pgvector column, and amatch_transcript_chunksfunction; 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, andmatch_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 theimportly.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
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 withchunked_at first means two calls at once never chunk the same video twice.
supabase/functions/index-transcripts/index.ts
importly-webhook from the transcripts recipe, add one call after saveJob:
supabase/functions/importly-webhook/index.ts
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
5. Call it from your app
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) keepsstatus: '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.