Skip to content

LearnRank & assemble

Contextual compression

Extractive compression

Shrinking each retrieved passage to only the sentences that bear on the question before it goes into the prompt.

In DocSlurpGlossary entry

On this page

Chunks are cut at ingest, before anyone knows what will be asked. A 400-word chunk from growth-plan-2027.pdf might hold the margin plan in two sentences and spend the rest on hiring and office leases. Retrieve it for “How far above our margin target are we?” and the model reads all 400 words to use 20.

Contextual compression re-cuts each retrieved passage after the question is known. A model (or a smaller trained compressor) reads the question and the passage and keeps only what bears on the question:

FY2027 operating margin is projected at 24% against a 20% target.

There are two styles. Extractive compression copies sentences out of the passage unchanged. Abstractive compression writes a summary. Extractive is safer for citations, because every kept word is still in the source and still points to the same page.

The gotcha

Compression is another model call per passage, so it adds latency and cost before the answer model even starts. And it can cut too much: a sentence that looks irrelevant on its own, such as “The following applies only to the London office”, may change the meaning of the one that was kept. An abstractive compressor can also introduce errors of its own.

DocSlurp’s version is extractive and optional (core/server/src/search/contextual-compression.ts). It compresses the top 20 passages one by one, treats the passage as untrusted data in the prompt, and keeps the result only if it is at least 20 characters long and appears word for word in the original. Otherwise the original passage is used unchanged. Each call records its token usage.

In DocSlurp

In DocSlurp

Optional and off by default. A model extracts sentences from each of the top 20 passages, and the result is kept only if it is at least 20 characters and appears verbatim in the source; otherwise the original passage is used (core/server/src/search/contextual-compression.ts). Each call is metered.

Sources

Jump to