C.W.K.
Stream
Lesson 05 of 06 · published

Tokens, Context Limits, and Truncation

~20 min · tokens, models, gotchas

Level 0Scout
0 XP0/41 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Embedding models have hard token limits

An embedding call accepts text up to a maximum number of tokens, not characters. Tokens are subword pieces from the model's tokenizer — for English, roughly 0.75 words per token. Korean, Japanese, and code can be much denser.

Common limits in 2026:

  • OpenAI text-embedding-3-large: 8,192 tokens
  • Voyage voyage-3-large: 32,000 tokens
  • BGE-M3: 8,192 tokens
  • BGE-small-en-v1.5: 512 tokens (this trips people)
  • all-MiniLM-L6-v2: 256 tokens

What happens past the limit

Almost every API silently truncates. You will not get an error — the model embeds the front of your text and discards the rest. Your vector will look fine, your search will look like it works, and you will lose the back half of every long document.

How to defend against silent truncation

  1. Use the model's tokenizer to count tokens before sending.
  2. If tokens > limit, either chunk the input (next track) or use a long-context model.
  3. Log the chunk length distribution after ingestion. If P99 hits exactly the limit, you are losing data.

Code

Count tokens before embedding (OpenAI)·python
import tiktoken

enc = tiktoken.encoding_for_model('text-embedding-3-large')

def count_tokens(text: str) -> int:
    return len(enc.encode(text))

long_text = open('white_paper.md').read()
print(count_tokens(long_text))   # if > 8192, you must chunk
Count tokens for a HuggingFace model·python
from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained('BAAI/bge-m3')
print(len(tok.encode(long_text)))   # uses the actual model tokenizer

External links

Exercise

Pick the largest 5 documents in your corpus. Count their tokens with the actual tokenizer of your chosen embedding model. Report how many exceed the limit. Decide your chunking budget based on that distribution, not on a guess.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.