Skip to content

LearnRank & assemble

Context assembly

Context packing · Prompt packing

Turning ranked search results into the block of evidence a model reads: which passages, in what order, with what labels and surrounding text.

In DocSlurpGlossary entry

On this page

Retrieval produces a ranked list. The model never sees that list; it sees whatever text you paste into its prompt. Context assembly is the step in between: choosing which passages go in, how much of each, in what order, and how each is labeled.

A typical assembled block for “Are we on track to beat our FY2027 earnings?” looks like this:

[1] growth-plan-2027.pdf, p. 12, Earnings outlook > Revenue forecast
FY2027 revenue is projected at $48.2M, up 31% year over year, 12% ahead of plan.

[2] growth-plan-2027.pdf, p. 13, Earnings outlook > Margin plan
Operating margin is projected at 24% against a 20% target.

Each decision changes the answer:

  • How many passages. More passages raise the chance the answer is present and add noise. A reranker plus a small count usually beats a long list.
  • How much text per passage. The matched chunk alone, the surrounding page (small-to-big retrieval), or only the relevant sentences (contextual compression).
  • Order. Models use the start and end of a long prompt more reliably than the middle (lost in the middle).
  • Labels. A number, filename and page per passage lets the model cite, and lets you check each citation.

The gotcha

Retrieved text is untrusted input. A passage can contain “ignore previous instructions”, so the prompt should mark document text as data, not instructions (see prompt injection).

In DocSlurp, chat labels each passage [n] with its filename, pages, heading path and evidence type, attaches the parent page as surrounding context, and replaces lines that look like injected instructions with a placeholder (buildNativeDocumentInputs in core/server/src/services/project-chat.ts). Chat sends at most 12 passages. Multi-project answers merge each project’s results by score and add the project name to every label (core/server/src/services/aggregate-rag.ts).

In DocSlurp

In DocSlurp

Chat labels each passage [n] with its filename, pages, heading path and evidence type, adds parent text as surrounding context, and screens the text for prompt-injection lines (buildNativeDocumentInputs in core/server/src/services/project-chat.ts). Chat retrieves at most 12 passages. Multi-project answers merge results by score and add the project name (core/server/src/services/aggregate-rag.ts).

Sources

Jump to