liveBook · Manning

Lossy compression

As explained in Retrieval Augmented Generation, The Foundational Ideas

A lossy compressor produces a smaller representation by discarding some information from the original input.

Lossy compression produces a smaller representation by discarding information. In dense retrieval, an encoder squeezes prose into a fixed-size vector, preserving topical patterns while dropping surface details. section 7.3

Semantic filtering in retrieval

A hypothetical document may contain a wrong date or name, yet its vector can still support retrieval because the dense bottleneck filters detail-level errors. This protection fails when the generated text uses the wrong framing or subject area. section 7.3

The same tradeoff appears in familiar media formats and text embeddings:

  • JPEG discards visual details people are unlikely to notice. section 7.3
  • MP3 discards audio details people are unlikely to hear. section 7.3
  • A text encoder maps a paragraph to a vector containing a few hundred to a thousand numbers. section 7.3
Listing 7.3 HyDE in LangChain.
from providers import get_chat_model, get_embeddings
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_classic.chains.hyde.base import (
    HypotheticalDocumentEmbedder)
llm = get_chat_model(temperature=0)
base_embeddings = get_embeddings()
prompt = PromptTemplate(
    input_variables=["question"],
    template=("Please write a passage to answer the question.\n"
              "Question: {question}\nPassage:")
)  #A
hyde_embedder = HypotheticalDocumentEmbedder(
    llm_chain=prompt | llm | StrOutputParser(),  #B
    base_embeddings=base_embeddings,
)
query = "What are the best practices for a startup's user growth?"
hypothetical_doc_embedding = hyde_embedder.embed_query(query)  #C
 

Shows a HyDE pipeline that generates a hypothetical passage and embeds it for retrieval. section 7.3

How Retrieval Augmented Generation, The Foundational Ideas covers it

How deep it goes
Explains the bottleneck mechanism, retained semantics, discarded details, and failure from incorrect framing.
Examples
Uses JPEG, MP3, hypothetical documents, paragraph embeddings, and detail-level versus framing errors.
What you can do after
Evaluate/understand why embeddings can retain retrieval-relevant meaning while discarding factual surface details.
How it connects
Connects lossy compression to dense retrieval, vector embeddings, hallucinations, and semantic relevance.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Retrieval Augmented Generation, The Foundational Ideas. The section links point to the parts of the book it draws on.