ladderlore
Request a guide
  • Type a service name, like S3 or IAM.

Concept

Optimizing retrieval and embedding models

Tune chunking, top-k, the embedding model, hybrid search, filters and query rewriting, and measure recall.

  • Chunk size and overlap

    Effect
    Precision against context
    Try
    A few hundred tokens, some overlap
  • Top-k

    Effect
    Recall against noise
    Try
    Start near 5, then adjust
  • Embedding model

    Effect
    Meaning match, languages
    Try
    Test two or three models
  • Vector dimensions

    Effect
    Accuracy against storage
    Try
    Lower them if cost is high
  • Hybrid search

    Effect
    Exact terms and meaning
    Try
    Add for codes and names
  • Metadata filter

    Effect
    Narrows the search
    Try
    Product, date, language
  • Query rewriting

    Effect
    Better search queries
    Try
    Split hard questions
Settings that shape retrieval.

1 / 3

  • Chunk size and overlap

    Effect
    Precision against context
    Try
    A few hundred tokens, some overlap
  • Top-k

    Effect
    Recall against noise
    Try
    Start near 5, then adjust
  • Embedding model

    Effect
    Meaning match, languages
    Try
    Test two or three models

2 / 3

  • Vector dimensions

    Effect
    Accuracy against storage
    Try
    Lower them if cost is high
  • Hybrid search

    Effect
    Exact terms and meaning
    Try
    Add for codes and names
  • Metadata filter

    Effect
    Narrows the search
    Try
    Product, date, language

3 / 3

  • Query rewriting

    Effect
    Better search queries
    Try
    Split hard questions
Settings that shape retrieval.
Change one setting
Run test questions
Evaluating RAG retrieval and answers
Keep the best
  1. 1Change one setting.
  2. 2Run a fixed set of test questions.
  3. 3Measure retrieval recall and answer quality, then keep what works.
Tune by measuring.

Step by step

  1. 1Change one setting.
  2. 2Run a fixed set of test questions.
  3. 3Measure retrieval recall and answer quality, then keep what works.

Tune by measuring.

What it is

RAG quality depends on whether the right chunk comes back. Start with chunking. Small chunks match precisely but can lose context. Large chunks keep context but dilute the match and use more prompt. Knowledge Bases defaults to about 300 tokens, and fixed-size chunking lets you set the size and an overlap percentage, so a sentence cut at a boundary appears in both chunks. Hierarchical chunking searches small child chunks but returns the larger parent. Semantic chunking splits where the topic changes and costs more, because it calls a foundation model.

What it is

Next, retrieval settings. Top-k is how many chunks you return (5 by default in Knowledge Bases). Too low misses the answer. Too high adds noise, cost and delay. Hybrid search combines vector and keyword search, so exact terms such as product codes are found; Knowledge Bases supports it with some vector stores (Amazon OpenSearch Serverless, Amazon RDS and MongoDB with a text field). Metadata filters limit the search to documents with the right attributes, such as product, year or language. Query rewriting turns a vague question into a better search query, and query decomposition splits a hard question into sub-queries.

What it is

The embedding model matters most. Pick one that supports your languages and domain. A longer vector captures more but costs more to store and search; Amazon Titan Text Embeddings V2 offers 256, 512 or 1,024 dimensions. Keep chunks within the model’s input limit, and use the same model for ingestion and queries. Measure each change: build a test set of questions with known source passages and track retrieval recall (did the right chunk come back in the top k), changing one setting at a time. Reranking has its own lesson.

Remember

  • Top-k: too low misses the answer, too high adds noise and cost.
  • Hybrid search finds exact terms. Metadata filters narrow the search.

On the exam

  • “Answers miss exact product codes” points to hybrid search.
  • “Search only the 2025 documents for one product line” points to a metadata filter.
  • “A chunk is cut mid-sentence and context is lost” points to more overlap or hierarchical chunking.