Cookbook
Cookbook
Shrink a long page before the prompt
Keep only the passages that answer your question, and log how much context you saved.
1 min read · Updated 20 Nov 2026
On this page
A whole article in the prompt costs tokens and buries the answer. Send the URL and the question to Lineage and pass only what comes back.
compress-page.py
import osimport requestsAPI = "https://fluxsearch.io/api/v1"URL = ( "https://www.batterytechonline.com/design-manufacturing/" "how-catl-moved-sodium-ion-batteries-from-lab-chemistry-to-gwh-scale-reality")response = requests.post( f"{API}/lineage", headers={"Authorization": f"Bearer {os.environ['FLUX_API_KEY']}"}, json={"url": URL, "queries": ["Why are sodium-ion cells cheaper than lithium-ion?"]}, timeout=180,)response.raise_for_status()data = response.json()selection = data["selection"]print(f"Page: {selection['examined_tokens']} tokens")print(f"Kept: {selection['returned']} of {selection['considered']} passages")print(f"Context saved: {selection['reduction_ratio']:.0%}\n")context = "\n".join(p["enriched_text"].strip() for p in data["results"])print(context)const API = "https://fluxsearch.io/api/v1";const URL = "https://www.batterytechonline.com/design-manufacturing/" + "how-catl-moved-sodium-ion-batteries-from-lab-chemistry-to-gwh-scale-reality";type Selection = { examined_tokens: number; returned: number; considered: number; reduction_ratio: number;};const response = await fetch(`${API}/lineage`, { method: "POST", headers: { Authorization: `Bearer ${process.env.FLUX_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ url: URL, queries: ["Why are sodium-ion cells cheaper than lithium-ion?"], }),});if (!response.ok) throw new Error(`Flux ${response.status}: ${await response.text()}`);const data = (await response.json()) as { selection: Selection; results: { enriched_text: string }[];};const { selection } = data;console.log(`Page: ${selection.examined_tokens} tokens`);console.log(`Kept: ${selection.returned} of ${selection.considered} passages`);console.log(`Context saved: ${Math.round(selection.reduction_ratio * 100)}%\n`);const context = data.results.map((p) => p.enriched_text.trim()).join("\n");console.log(context);What it prints
Output
Page: 1481 tokensKept: 14 of 73 passagesContext saved: 75%CATL signed a 60 GWh sodium-ion supply agreement with energy storage integrator HyperStrong in ChinaThe Naxtra sodium-ion battery achieved GWh-scale industrialization with full production starting in 2026Sodium-ion cells use no cobalt or lithium and employ aluminum collectors on both electrodes for cost cutsFor years, sodium-ion batteries were considered a chemistry with compelling structural advantages, but that couldnt reach commercial relevance.Benefiting from sodium’s abundance, an architecture that omits lithium and cobalt, and lower cell expansion stress, the chemistry has many promising features that exceed lithium-ion batteries.However, sodium-ion’s design makes it significantly cheaper than lithium-ion.First, sodium is far more abundant than lithium, and sodium-ion cells use no cobalt.In addition, sodium-ion cells can use aluminum current collectors on both electrodes, eliminating the copper required on lithium-ion anodes.With these material characteristics combined, sodium-ion batteries carry a low cost that suits large-scale, long-duration stationary storage, where raw material cost influences project budgets.According to the American Physical Society, sodium-ion cells tolerate wider temperature ranges than conventional lithium-ion chemistries, maintain cycle stability at high ambient temperatures, and generate less heat during operation, reducing the burden on thermal management systems.Where sodium-ion falls short is energy density and ease of manufacturing.Sodium-ion cells store less energy per kilogram than LFP (lithium iron phosphate), and their hard carbon anodes are more difficult to produce consistently as compared to graphite anodes used in lithium-ion designs.CATL also notes that its sodium-ion cells share a platform-based design with the same form factor as its lithium-ion products.According to the company, that design choice reduces integration costs for operators and shortens the time from product qualification to power station deployment.How it works
selection.examined_tokensis the size of the page andreduction_ratiothe share Lineage cut.returnedofconsideredshows how many passages were kept out of how many were scored.