Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
  • Prompting13
  • Trust and Verification14
  • Using AI for Engineering Work17
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
    • Cost Arithmetic
    • Latency and Throughput
    • Reducing Tokens
      • Prefix Caching
      • Summarisation and Information Loss
      • Retrieval Instead of Pasting
      • Trimming Logs and RTL
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

‹Reducing Tokens
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Tokens, Cost and Latency
  4. Reducing Tokens
  5. Retrieval Instead of Pasting

Reference: Tokens, Cost and Latency · Beginner to Intermediate

Retrieval Instead of Pasting

Split notes into chunks and rank them with keyword scores instead of pasting everything.

On this page

    Chunks and ranking

    Retrieval splits documents into chunks and sends only the top-ranked ones. The rest of the manual stays out of the prompt entirely.

    Ranking quality varies by model and method, so measure it on local notes. Keyword ranking below is deterministic and inspectable, which makes it a good baseline.

    Chunk size

    Benefit

    Cost

    Too large

    Each chunk keeps full context

    Few chunks fit, and most tokens are surplus.

    Balanced

    One idea per chunk with its heading

    Top chunks answer directly with little surplus.

    Too small

    Many precise matches

    Ideas split across chunks and ranking spreads thin.

    TF-IDF by hand

    TF-IDF scores a chunk by term frequency times inverse document frequency. Frequent terms in the chunk raise the score, while terms common across chunks lower it.

    With 5 chunks, a term in 2 chunks scores ln(5 / 2), about 0.916. A term in 1 chunk scores ln(5 / 1), about 1.609, so rare matching terms dominate.

    plaintext
    1
    2
    3
    4
    5
    N = 5 chunks
    df(reset) = 2 -> idf = ln(5 / 2) = ln(2.5) = about 0.916
    df(synchronizer) = 2 -> idf = ln(5 / 2) = about 0.916
    df(metastability) = 1 -> idf = ln(5 / 1) = ln(5) = about 1.609
    a chunk matching all three query terms outscores chunks matching one

    Query term

    Chunks containing it

    df

    idf

    reset

    Chunks 2 and 4

    2

    about 0.916

    synchronizer

    Chunks 2 and 5

    2

    about 0.916

    metastability

    Chunk 2 only

    1

    about 1.609

    A runnable toy

    The program ranks five short hardware notes against a three-term query. Chunk 2 holds every query term, so it must rank first.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    import math
    import sys
    
    DOCS = [
        "Clock gating saves power by stopping the clock when logic is idle.",
        "A reset synchronizer chain guards against metastability when reset crosses clock domains.",
        "FIFO pointers use gray code so crossings stay safe.",
        "Reset tree buffering limits skew across a large block.",
        "A deeper synchronizer adds latency but tolerates skew.",
    ]
    QUERY = ["reset", "synchronizer", "metastability"]
    
    def toks(s):
        out = []
        for w in s.lower().split():
            w = w.strip(".,;:!?()")
            if w:
                out.append(w)
        return out
    
    def main():
        dt = [toks(d) for d in DOCS]
        n = len(DOCS)
        scores = []
        for t in dt:
            s = 0.0
            for q in QUERY:
                df = sum(1 for u in dt if q in u)
                idf = math.log(n / df) if df else 0.0
                s += (t.count(q) / len(t)) * idf
            scores.append(s)
        ranked = sorted(range(n), key=lambda i: scores[i], reverse=True)
        bad = 0
        if ranked[0] != 1:
            bad += 1
        if not (scores[1] > scores[3]):
            bad += 1
        if not (scores[1] > scores[4]):
            bad += 1
        if not (scores[0] == 0.0 and scores[2] == 0.0):
            bad += 1
        if len(ranked) != 5:
            bad += 1
        if bad == 0:
            print(f"PASS: doc 1 top over {n} docs with {len(QUERY)} query terms scored")
        else:
            print(f"FAIL: {bad} checks wrong")
            sys.exit(1)
    
    main()

    Only chunk 2 matches all three terms, and the rare term metastability lifts it furthest. Chunks 1 and 3 match nothing and score exactly zero.

    Common mistakes

    Common pitfall

    Pasting the whole manual because one chunk ranked badly confuses a ranking fault with a coverage fault. Fix the chunks or the query first, and only widen the window after ranking is measured.

    Interview

    Likely probes: how chunking and TF-IDF interact.

    • One idea per chunk keeps scores sharp; heading lines preserve context.

    • Rare query terms dominate through higher inverse document frequency.

    • Keyword ranking is a baseline; its misses argue for better chunks, not longer prompts.

    Check yourself Why does chunk 2 outscore chunk 4 for the query reset, synchronizer, metastability?

    Chunk 2 matches all three terms including the rare metastability. Chunk 4 matches only reset, so its score stays lower.

    Check yourself Chunks 1 and 3 score exactly zero. What does that say about their query terms?

    They hold none of the three query terms, so every term frequency is zero.

    Related topics

    • Trimming logs and RTL

    • Anatomy of a prompt

    • Caches

    Previous

    141 / 173

    Next: Trimming Logs and RTL

    Up next

    Up nextTrimming Logs and RTL

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Prefix Caching