NEWVectors or files. Pick a path.Start →
    Back to DiagramsRetrieval Mechanics

    Sorting by Price Shows the Wrong One First: Landed Cost Computed Inside the Pipeline

    A real "floor lamp" query, then a sandboxed Python stage applies discount tiers and a shipping threshold to each result. $298.71 lands at $323.66 and $322.38 lands at $308.64, so the two cheapest rows swap. Sort by list price and the wrong lamp is first.

    A portrait diagram. The headline reads Sorting by price, shows the wrong one first, with the subline: discount tiers and a shipping threshold are business rules, not search config, so we ran them inside the pipeline. A five-row table has columns item, list, tier, disc and landed. Steel Floor Lamp, 298.71 dollars, retail, 0 percent, landed 323.66; Brass Floor Lamp, 322.38 dollars, trade, 12 percent, landed 308.64; Wood Floor Lamp, 729.19 dollars, wholesale, 25 percent, landed 546.89; Brass Floor Lamp, 801.62 dollars, wholesale, 25 percent, landed 601.22; Wood Floor Lamp, 907.60 dollars, wholesale, 25 percent, landed 680.70. The first two rows are outlined in rose, with the caption sorted by list price, the two highlighted rows swap once landed cost is computed. A bold line reads 298.71 dollars lands at 323.66, 322.38 dollars lands at 308.64, sort by price and you show the wrong one first. A dark code window labelled code_execution, python, sandboxed, 5854 ms shows the Python that assigns a tier by price, a discount of 25, 12 or 0 percent, free shipping at or above 500 dollars and 24.95 below, and appends tier, discount_pct and landed_cost per document. The footer prints mxp.co/d/code-in-the-pipeline and real query, real execution, mixpeek.
    A real "floor lamp" query, then a sandboxed Python stage applies discount tiers and a shipping threshold to each result. $298.71 lands at $323.66 and $322.38 lands at $308.64, so the two cheapest rows swap. Sort by list price and the wrong lamp is first.

    Sort a result set by price and you can still show the wrong item first. The diagram runs a real floor lamp query against a 118 image index, then adds one code_execution stage: a sandboxed Python block that applies discount tiers and a shipping threshold to each result.

    The rules are ordinary. Wholesale at 700 dollars and above takes 25 percent off, trade at 300 and above takes 12 percent, retail pays list. Orders under 500 dollars pay 24.95 shipping. Applied to the five lamps the search returned, 298.71 dollars lands at 323.66 because it sits under the free shipping line, and 322.38 dollars lands at 308.64 because it clears the trade discount. The two cheapest rows swap.

    Tiers, thresholds and landed cost are business rules. They change more often than an index does and they belong to whoever owns pricing, so writing them into search configuration would be the wrong place even if the configuration could express them. The stage runs the Python in an isolated sandbox as part of retrieval, so the rule lives next to the query rather than in whichever service happens to render the results. 5.8 seconds for five documents in this run.

    Two details of the contract, learned while building this: the sandbox hands the result set to the code as docs, and the computed values land under the stage's output_field on each document's payload rather than at the document root. Read the root and the stage looks like it did nothing.

    The general version is that the answer to whether your search can do some specific thing stops being a roadmap question. If it can be written in a few lines against the matched documents, it can run in the pipeline.

    What is real here: the photos behind the rows are Pexels images with every photographer credited, the query and the sandboxed execution ran against the live API, and the landed costs are the ones the stage returned. Prices, tiers and thresholds are demo catalog data and demo rules, so the dollar figures describe the demo and the mechanism is the point.

    Run this on your own data

    Mixpeek turns video, images, audio, and documents in your object storage into searchable, timestamped results through one API.

    Search your own data