Abstractive summarization generates a new, shorter document by integrating and rewording related source chunks instead of selecting representative sentences. In recursive retrieval, it creates synthetic documents that capture a cluster's shared theme. Use temperature 0.0 during indexing so identical inputs produce stable summaries and embeddings; reserve higher temperatures for query-time generation. section 10.4.3
Apply the technique with explicit production safeguards:
- Prompt for grounded synthesis that preserves specific entities, numerical values, and causal relationships. section 10.4.3
- Parallelize independent cluster summaries with ainvoke, asyncio.gather, or a ThreadPoolExecutor to reduce indexing latency. section 10.4.3
- Prefer extractive compression for factual recall or cited spans; choose abstractive synthesis for summarization and multi-hop reasoning. section 13.7 section 13.9
- Tune compression rather than fixing one ratio: moderate compression can remove distractors, while excessive compression causes semantic loss and over-pruning. section 13.7 section 13.9
Choosing the compression style
A legal-contract system should retain quoted clauses with extractive compression. A medical-diagnostic system may need an abstractive patient-history summary that combines information across documents, while accepting the additional hallucination surface. section 13.4.1
Listing 10.4 The summarization service.
from providers import get_chat_model
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
class SummarizationEngine:
def __init__(self, model_name="gpt-4o"):
self.llm = get_chat_model( #A
model_name, temperature=0.0)
self.prompt = ChatPromptTemplate.from_template( #B
"You are a sophisticated technical analyst. "
"Synthesize the text chunks into one summary. "
"Preserve specific entities, numerical values, "
"and causal relationships. The summary should be "
"abstractive but grounded in the details given.\n\n"
"Text Chunks:\n{context}\n\n"
"Comprehensive Summary:"
)
def summarize_cluster(self, texts: List[str]) -> str:
"""Generates a summary for a list of text chunks."""
combined_text = "\n\n".join(texts)
chain = self.prompt | self.llm | StrOutputParser()
return chain.invoke({"context": combined_text}) #C
Inspect a compact LangChain implementation that configures a zero-temperature chat model, requests grounded cluster synthesis, and returns a summary string. section 10.4.3

