Context Engineering

Layer 3 · Code

Context Engineering

Implement a token-budgeted context assembler: chunking, retrieval, and fitting content to a hard limit.

12 min read110 XP

Chunked, embedded corpus

Retriever (top-k by similarity)

Budget calculator

Assembler (fits + orders chunks)

The pieces of a hand-rolled context assembler.

The core engineering problem is a knapsack-flavored one: given a token budget and a ranked list of candidate chunks with known relevance scores and known token costs, choose which ones to include.