---
title: "YouTube Transcripts for RAG: Chunking and Embeddings"
description: "Turn YouTube videos into a searchable knowledge base: timestamped transcript chunks, chunk size and overlap, embeddings and citations to the exact second."
url: "https://fetchtranscript.com/blog/youtube-transcripts-for-rag"
markdown: "https://fetchtranscript.com/blog/youtube-transcripts-for-rag.md"
---

Guides

# YouTube Transcripts for RAG: Chunking and Embeddings

Turn YouTube videos into a searchable knowledge base: timestamped transcript chunks, chunk size and overlap, embeddings and citations to the exact second.

By FetchTranscript team Published October 27, 2026 Updated November 26, 2026 5 min read

To use YouTube videos in a RAG system, you turn each transcript into chunks of a few hundred words, keep the start and end time of every chunk, embed the chunks, and cite answers with links that open the video at the right second. The hard parts are the chunking (raw caption segments are far too short) and keeping timestamps through the pipeline. FetchTranscript returns transcripts already chunked with `format=chunks`, so this guide focuses on the choices that make retrieval good: chunk size, overlap, metadata and citations.

## Why raw transcripts are bad retrieval units

A YouTube transcript arrives as caption segments: lines of three to ten words, each with a `start` and a `duration`. Those are designed for the screen, not for search. If you embed every segment on its own, three problems appear at once:

- **No context.** "and that's why it fails" means nothing without the previous minute. The embedding of a five-word line is mostly noise.
- **Too many vectors.** A one-hour talk has around a thousand segments. Your index grows tenfold for worse results.
- **No punctuation.** Auto-generated captions often have no sentence boundaries, so splitting "by sentence" does not work either.

The opposite mistake, one vector per video, loses precision: a question about minute 42 competes with everything else in the talk, and your citation can only point to the start of the video.

The sweet spot for most embedding models is a chunk of roughly 150 to 300 words (about 800 to 1,500 characters) that still knows where it starts and ends in the video.

## Get chunks with timestamps in one call

`GET /v1/transcripts/{video_id}?format=chunks` merges the segments for you and returns a `chunks` array:

```bash
curl -H "X-API-Key: yt_your_api_key" \
  "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?format=chunks&chunk_size=1000&chunk_overlap=200"
```

```json
{
  "video_id": "dQw4w9WgXcQ",
  "language": "en",
  "chunks": [
    { "index": 0, "text": "We're no strangers to love You know the rules and so do I ...", "start": 18.64, "end": 58.24 }
  ],
  "chunk_size": 1000,
  "chunk_overlap": 200,
  "is_generated": false,
  "provider": "cache",
  "metadata": { "title": "Rick Astley - Never Gonna Give You Up", "author": "Rick Astley", "length_seconds": 213 }
}
```

Each chunk has an `index` (from 0), its `text`, and `start` / `end` in seconds. The response also carries the video's `metadata` (title, channel, length, views), which you will want next to every vector. It costs 1 credit, like any other format.

How the chunks are built, so you can reason about them:

- `chunk_size` (200-4000 characters, default 1000) is a target. Segments are joined with a space while the chunk stays within it.
- **A segment is never split.** A chunk is longer than `chunk_size` only when a single segment (plus the overlap) does not fit.
- `chunk_overlap` (0-1000, default 0, and less than `chunk_size`) repeats the last whole segments of the previous chunk, up to that many characters, at the start of the next one.
- `start` is the start of the chunk's first segment; `end` is the latest end of its segments.

Because chunks are aligned to segments, every chunk boundary is also a real moment in the video. That is what makes precise citations possible.

## Choosing chunk size and overlap

There is no universal value, but these defaults hold up well:

| Content                     | chunk_size | chunk_overlap | Why                                                                |
| --------------------------- | ---------- | ------------- | ------------------------------------------------------------------ |
| Lectures, tutorials         | 1000-1500  | 150-250       | Ideas span a few minutes; overlap keeps definitions with their use |
| Podcasts, interviews        | 1500-2000  | 200-300       | Long answers; bigger chunks keep a speaker's point together        |
| Short videos, Shorts        | 500-800    | 0-100         | The whole video is barely one chunk                                |
| Q\&A retrieval for chatbots | 800-1000   | 100-200       | Smaller chunks rank sharper for specific questions                 |

Overlap costs storage (roughly `chunk_overlap / chunk_size` more text) and buys recall at the edges: a sentence cut between two chunks is then fully present in one of them. Start around 15-20% and measure. If your answers keep missing the end of an explanation, raise the overlap; if they quote the same passage twice, lower it.

Check your embedding model's input limit, too. Hosted embedding models accept far more than 4,000 characters, so the API's maximum is safe there, but small local models truncate silently: a 512-token model stops at about 2,000 characters of English, and `all-MiniLM-L6-v2`, used below, reads only its first 256 tokens, about 1,000 characters.

## A complete ingestion script in Python

This example uses the official SDK (`pip install fetchtranscript`) for the chunks and the open-source `sentence-transformers` library for embeddings, as a stand-in for whichever embedding provider and vector store you use:

```python
from fetchtranscript import FetchTranscriptClient
from sentence_transformers import SentenceTransformer  # any embedding model works here

client = FetchTranscriptClient(api_key="yt_your_api_key")
model = SentenceTransformer("all-MiniLM-L6-v2")  # reads up to 256 tokens: keep chunks near 1,000 characters

def youtube_records(video_id: str) -> list[dict]:
    result = client.transcripts.get(video_id, format="chunks", chunk_size=1000, chunk_overlap=150)
    meta = result.get("metadata") or {}
    records = []
    for chunk in result["chunks"]:
        records.append({
            "id": f"{video_id}:{chunk['index']}",
            "text": chunk["text"],
            "video_id": video_id,
            "title": meta.get("title"),
            "channel": meta.get("author"),
            "language": result["language"],
            "is_generated": result["is_generated"],
            "start": chunk["start"],
            "end": chunk["end"],
            "url": f"https://www.youtube.com/watch?v={video_id}&t={int(chunk['start'])}s",
        })
    return records

records = youtube_records("dQw4w9WgXcQ")
vectors = model.encode([r["text"] for r in records], normalize_embeddings=True)
# store (record, vector) pairs in your vector database
```

If you only need the list of chunks, `client.transcripts.get_chunks(video_id, chunk_size=1200, chunk_overlap=200)` returns it directly.

Two details in the records matter later. `is_generated` tells you whether the text comes from YouTube's automatic captions; you may want to show that to users or weight it. And `url` is the citation, built once at ingestion so the retrieval layer never has to know about YouTube.

## The same request in JavaScript

```javascript
// Node 18+ as an ES module (a .mjs file, or "type": "module"), for the top-level await
const res = await fetch(
  'https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ?format=chunks&chunk_size=1200&chunk_overlap=200',
  { headers: { 'X-API-Key': 'yt_your_api_key' } },
);
if (!res.ok) throw new Error((await res.json()).detail.error);
const { video_id, chunks, metadata } = await res.json();
const records = chunks.map((c) => ({
  id: `${video_id}:${c.index}`,
  text: c.text,
  title: metadata?.title,
  url: `https://www.youtube.com/watch?v=${video_id}&t=${Math.floor(c.start)}s`,
}));
```

## Citations that open the right second

A good RAG answer about a video says *where* it got the information. YouTube links accept a start time: `https://www.youtube.com/watch?v=VIDEO_ID&t=754s` opens the video at 12:34. Since every chunk has `start`, you can render each source as "Title, 12:34" linking straight to the moment. Users trust answers they can verify in two clicks, and you can catch retrieval errors yourself much faster.

For extra precision, prompt the model to cite chunk IDs, then map them back to their URL in your code instead of letting the model write links.

## Scaling from one video to a library

Real knowledge bases are channels, playlists or search results, not single videos:

1. List the videos: a whole channel with the cursor endpoint ([how to get all videos from a channel](https://fetchtranscript.com/blog/get-all-videos-from-youtube-channel.md)), or a curated playlist ([exporting a playlist](https://fetchtranscript.com/blog/export-youtube-playlist.md)).
2. Fetch chunks for each video. Videos without captions answer 404 (`transcripts_disabled` or `no_transcript_found`) and cost nothing: log them and move on.
3. Re-ingest only what changed. Store the `video_id`s you already have and skip them on the next run.

Mind the 500 requests per minute limit and back off on 429 using the `Retry-After` header. At $1 per 1,000 calls, a 2,000-video channel costs about $2 to ingest; the first 100 calls every month are free ([pricing](https://fetchtranscript.com/pricing.md)).

Languages need a decision. Without `lang`, you get each video's original language. If your index is English-only but some videos are not, use a multilingual embedding model, or call `GET /v1/transcripts/{video_id}/languages` first and pick a track. The same chunking works for TikTok captions too; see [how to get a TikTok transcript](https://fetchtranscript.com/blog/tiktok-transcript.md).

## Skip the pipeline: MCP for Claude and ChatGPT

Not every use case needs a vector database. If you want to ask questions about a few videos in Claude or ChatGPT, connect the [FetchTranscript MCP server](https://fetchtranscript.com/docs/mcp.md): the assistant fetches transcripts itself and answers with them in context. Build the RAG pipeline when you need search across hundreds of videos, your own ranking, or an answer inside your product.

## Frequently asked questions

### What is the best chunk size for YouTube transcripts?

For most embedding models, 800 to 1,500 characters (about 150-300 words) with 15-20% overlap is a good start. Use larger chunks for podcasts and interviews, smaller ones for short videos and narrow Q\&A.

### Does the API split a sentence across chunks?

It never splits a caption segment: chunks are built from whole segments, so a chunk can be slightly longer than `chunk_size`. Use `chunk_overlap` so the text around each boundary is fully present in one chunk.

### How do I link a chunk to the exact moment in the video?

Use the chunk's `start` in seconds: `https://www.youtube.com/watch?v=VIDEO_ID&t=SECONDSs`. Round it down to a whole number of seconds.

### Does format=chunks cost more than a normal transcript?

No. Every format costs 1 credit per successful call, and failed calls are free.

### Can I use auto-generated captions for RAG?

Yes, they work well for retrieval even without punctuation. The response's `is_generated` field tells you which transcripts are automatic, so you can label or weight them.

### Do I need my own vector database?

Only for search across many videos. For a handful of videos, the [MCP server](https://fetchtranscript.com/docs/mcp.md) lets Claude or ChatGPT read the transcripts directly.

Try it on your own videos

100 free calls every month, no credit card. Then $1 per 1,000 calls, only for the calls that succeed.

[Get your free API key](https://fetchtranscript.com/auth/sign-up)[Read the docs](https://fetchtranscript.com/docs.md)

## Related guides

- [How to Get a YouTube Transcript with Python](https://fetchtranscript.com/blog/get-youtube-transcript-python.md)

  Fetch the transcript of any YouTube video in Python: timestamps, plain text and SRT, languages, errors and batches, with requests or the official SDK.

- [How to Get All Videos from a YouTube Channel](https://fetchtranscript.com/blog/get-all-videos-from-youtube-channel.md)

  List every video of a YouTube channel by @handle, page by page with a cursor, export it to CSV, with or without Shorts, and get the transcripts of a channel.

- [How to Get the Transcript of a TikTok Video](https://fetchtranscript.com/blog/tiktok-transcript.md)

  Get the transcript of a TikTok video from its captions as text, timed JSON, SRT or VTT: short links, languages, videos without captions, and code to automate.

[← All articles](https://fetchtranscript.com/blog.md)
