CertBrain
CoursesBlog
Sign in
← Back to decks
Sign in to save your progress, vote, and build your own decks.Sign in

Tokens, Chunking, Embeddings and Vectors

Before a generative AI model can read your text, the text is broken into tokens. Before it can search your documents, they are cut into chunks and turned into embeddings, which are lists of numbers called vectors. This lesson explains all four ideas and how they work together, because almost every…

11 cards
Study this deck

Tokens, Chunking, Embeddings and Vectors

Before a generative AI model can read your text, the text is broken into tokens. Before it can search your documents, they are cut into chunks and turned into embeddings, which are lists of numbers called vectors. This lesson explains all four ideas and how they work together, because almost every exam question about retrieval, cost or search builds on them.

Tokens

A token is the unit of text a language model actually reads and writes. It is often a whole short word, but it can also be part of a longer word, a punctuation mark or a space. "Unbelievable" might be split into several tokens, while "cat" is one. Each model has its own way of splitting text, called its tokenizer, so the same sentence can be a different number of tokens on different models.

Tokens matter for three practical reasons. A model has a maximum number of tokens it can handle in one request, called its context window. Models are usually priced per token. And the more tokens a model has to read and write, the longer it takes to respond. Amazon Bedrock even offers a way to count a prompt's tokens before sending it, so you can estimate cost.

Chunking

Chunking means splitting a long document into smaller pieces before storing it for search. A 200-page manual is far too big to search as one block, and too big to hand to a model in full. Cut into chunks of a few hundred tokens, each piece can be matched to a question on its own, and only the relevant pieces are passed to the model.

Chunk size is a trade-off. Small chunks match a question precisely but may lose the surrounding context. Large chunks keep context but blur the match. Amazon Bedrock Knowledge Bases offers several strategies: fixed-size chunks with overlap, a default of about 300 tokens that respects sentence boundaries, hierarchical chunking (small child chunks for matching, larger parent chunks for context), semantic chunking that splits where the meaning changes, or no chunking at all.

Embeddings and vectors

An embedding is a numerical representation of a piece of content, such as a sentence, an image or a product, produced by an embedding model. The output is a vector: a long list of numbers that places the content as a point in a space with many dimensions. Content with similar meaning ends up close together in that space. "How do I reset my password?" and "I forgot my login details" use different words, but their vectors land near each other.

On AWS, Amazon Bedrock provides embedding models such as Amazon Titan Text Embeddings, which turn text into vectors for search, similarity comparison and clustering.

Once documents are chunked and embedded, the vectors are stored in a vector database. When a user asks a question, the question is embedded with the same model, and the database returns the chunks whose vectors are closest to it. This is called semantic search or similarity search. It finds matches by meaning rather than by exact keywords, which is the foundation of Retrieval Augmented Generation (RAG), covered in Domain 3.

StepWhat happens
ChunkSplit documents into smaller pieces
EmbedTurn each chunk into a vector
StoreSave the vectors in a vector database
SearchEmbed the question and find the nearest chunks

On the exam

If a scenario says keyword search misses results that use different wording, the answer involves embeddings and vector search. If it says answers lack context or cut off mid-thought, look at chunk size or the chunking strategy. And remember that the question and the documents must be embedded with the same model, or their vectors can't be compared.

Quiz me on this
A developer notices that the same 500-word paragraph counts as a different number of tokens on two different models in Amazon Bedrock. What explains this?
  1. One of the models is miscounting and should be reported to AWS
  2. Token counts depend on which AWS Region the model is running in today
  3. ✓ Each model uses its own tokenizer, which splits text differently
  4. Token counts change each time the same text is sent to a model
An insurance company's help site uses keyword search. Customers who type "my car got dented in a parking lot" get no results, even though the site has an article titled "Filing a collision claim". Which approach would BEST fix this?
  1. ✓ Embed articles and queries, then match them by vector similarity
  2. Add more synonyms by hand to every article's list of keywords
  3. Require customers to search using the exact titles of the help articles
  4. Increase the maximum number of keyword results shown per page
A legal team builds a document search assistant on Amazon Bedrock Knowledge Bases. Retrieved passages often stop mid-argument, so the model answers without the clause's surrounding context. Matching is precise, but answers lack context. Which change addresses this MOST directly?
  1. Switch to an embedding model that produces shorter vectors
  2. Lower the model's temperature so its answers are less creative and varied
  3. Remove all chunking so each contract is one large chunk
  4. ✓ Use hierarchical chunking to return matches with parent chunks
What is an embedding in generative AI?
  1. A small image placed inside a document to illustrate a point
  2. ✓ A vector of numbers that places similar meanings close together
  3. A rule that blocks a model from answering questions on certain sensitive topics
  4. A compressed copy of a document used to save storage space
A team embeds its product catalog with one embedding model. Later, to save money, it embeds incoming customer questions with a different, cheaper embedding model. Search results become almost random. What is the MOST likely cause?
  1. The cheaper model splits each question into fewer tokens than the original
  2. The vector database needs more storage capacity
  3. ✓ Vectors from different embedding models can't be compared
  4. Customer questions are too short to be embedded
Token
The unit of text a model reads and writes: a word, part of a word or a symbol. Counts differ by model.
Chunking
Splitting long documents into smaller pieces before embedding them, so each piece can be matched and retrieved on its own.
Embedding
A vector of numbers that represents content so that items with similar meaning sit close together.
Vector
An ordered list of numbers that places a piece of content as a point in a space with many dimensions.
Similarity (semantic) search
Finding content by meaning: embed the query, then return the stored vectors closest to it.
Hierarchical chunking
Small child chunks for precise matching, replaced by larger parent chunks at retrieval to give the model context.