RAG & Agents Engineering

M07 lab, LCEL, Runnables and chains

Map-reduce buys a small prompt with more calls.

Three Larkspur Cloud handbook documents, split by a port of LangChain’s RecursiveCharacterTextSplitter with an overlap of 20, as in notebook 05a. A RunnableBranch sends short documents to stuff and long ones to map-reduce. Move the chunk size and count what each strategy costs.

Document
Map calls allowed at once (max_concurrency)
Chunks
Router picks
Map-reduce calls
Map-reduce rounds

The three strategies on this document

StrategyModel callsRoundsMost source text in one call

A round of callsThe reduce callThe strategy the router picks

summarise = RunnableBranch(
    (lambda x: len(x["text"]) <= 1500, stuff_chain),
    map_reduce_chain,
)

A round is one wait on the model: calls in the same round run at the same time. Refine’s calls after the first also read the running summary, and the reduce call reads the joined summaries; their length depends on the model, so the last column counts source text only. The 1,500-character limit stands in for a context budget.

Chunks the map step reads

#CharactersStarts with