For a marketplace that reviews code changes and returns structured findings, build the long document summarization API around chunked map reduce and a compact tenant accounting record. Keep full coverage of the submitted change. The bill needs an explanation that survives after the diagnostic payloads expire.
TL;DR: Prefer map reduce over retrieval for long document summarization when every submitted change must be considered and work must be attributable to a tenant. Use embeddings and reranking for a bounded evidence search when selective coverage is acceptable. Chat completions supplies a generation interface; it does not determine which material the workflow actually examines.
First quantify what is being retained. Consider a hypothetical workload of 10,000 reviews per day, with 20 chunk records per review and 2 KiB of logged content per chunk. Those payloads alone occupy about 391 MiB per day, or 11.4 GiB over 30 days, before indexes, replicas, or other storage overhead. A hypothetical 512 byte accounting record per review occupies about 4.9 MiB per day. In this example, retained chunk content is 80 times the size of the accounting records. These are planning assumptions and arithmetic, not observed performance or provider prices.
Count the bytes.
The change that moves this storage term is to stop retaining every chunk's text as routine telemetry. Keep compact accounting records for the proposed 30 day reconciliation window, and give diagnostic content a separately justified, shorter lifetime. This reduces retained content; it does not reduce the model work already performed.
How should a long document summarization API account for each tenant?
A tenant needs to distinguish one expensive review from repeated execution of the same review. For the proposed design, record the tenant, immutable change revision, logical review identifier, execution attempt, processing stage, and configuration version. Associate reported usage with the attempt that incurred it. Record unavailable usage as unknown. A timeout without a response is not evidence of zero consumption.
The accounting record and operational metrics serve different questions. An accounting record identifies a particular tenant's work; a metric should describe a bounded operational population. Putting every review identifier into a metric label turns each new review into another possible series. As a planning example, 500 tenants multiplied by 4 stages and 3 outcomes already allow 6,000 label combinations. Add one independently varying label and the possible combinations multiply again. Actual emitted series depend on which combinations occur, so this is a cardinality budget, not a measured series count.
Keep review identifiers in records.
For a Node.js service exposing an authorized accounting export, this client command measures the downloaded representation while saving it for inspection. Set the variable to your own export URL; this example assumes no particular API route or authentication scheme. Supply the credentials required by your service separately.
curl --silent --show-error --fail \
--header 'Accept: application/json' \
--output review-accounting.json \
--write-out 'download_bytes=%{size_download}\n' \
"${REVIEW_ACCOUNTING_URL:?Set REVIEW_ACCOUNTING_URL to your authorized accounting export URL}"
Downloaded bytes are a useful inspection point, not a storage bill. Measure the stored representation and its indexes separately before accepting a retention estimate.
For a marketplace, a single change can include a long patch, related source files, and policy text. Treat these as separately identified inputs. Otherwise a charge for processing repository context can look like unexplained growth in the cost of summarizing the patch itself. The proposed accounting schema should distinguish input categories while keeping source content out of the ordinary billing trail. This gives the tenant an explanation without making indefinite source retention a prerequisite for reconciliation.
Coverage makes the comparison consequential
The decision is about what a structured finding may claim. A review that promises to consider the whole submitted change needs a processing path for all eligible chunks. A retrieval workflow can instead select a subset relevant to a query. That difference belongs in the review contract before either workflow is deployed.
| Design choice | Proposed accounting unit | Coverage obligation | Retention consequence |
|---|---|---|---|
| Chunked map reduce | Chunk attempts plus reduction attempts | Account for every eligible chunk | Keep a compact coverage manifest |
| Retrieval with embeddings and reranking | Indexing, candidate selection, ranking, and generation attempts | Declare the selected evidence scope | Keep selection identifiers and versions |
For the stated review contract, choose map reduce. Split the long document along meaningful boundaries, map each chunk into structured candidate findings, and reduce those findings into the final review. Preserve source locations through both stages. A reduction that loses the link between a finding and its source cannot support a useful review comment, even if its prose reads well. The Prompt Engineering Guide provides background on prompting techniques; the coverage and accounting contract here is a proposed application design.
Chunk overlap deserves its own accounting field. If context is copied into adjacent chunks, track repeated input separately from unique source coverage. Otherwise a tenant can appear to have submitted more material merely because the chunking policy changed. Likewise, a reducer should merge duplicate findings using source identity and the finding's meaning, rather than treating repeated mentions as independent evidence. These requirements can increase implementation work, but they make the result explainable.
Use retrieval when the task changes to a bounded question, such as finding policy passages relevant to a particular finding. Embeddings can support candidate selection, and reranking can order those candidates before generation. Neither step establishes that excluded material contains nothing relevant. Preserve that boundary in the output. A query about one policy exception and a review of every changed file have different completeness obligations.
Retain the accounting trail and sample the explanation
In the proposed policy, retain every compact accounting event and sample verbose diagnostics. Sampling both together would leave some tenants with missing evidence for completed work. Sampling only successful traces would also bias the available diagnostic material toward the path that already behaves as expected.
A hypothetical 1% sample of the chunk payloads above would retain about 3.9 MiB per day before overhead, provided the sample is applied uniformly to those payload records. That calculation describes retained volume only. It says nothing about whether the sample contains the one execution needed for an investigation. Error retention, size limits, and any additional diagnostic categories require their own budget; adding them invalidates a simple uniform-sampling estimate.
The trade-off is deliberate: retain complete accounting evidence while accepting incomplete diagnostic detail. Record the sampling policy with the execution so that absence of a payload is distinguishable from absence of a processing stage. For a large tenant, aggregate usage by a bounded time interval for reporting, but preserve enough underlying accounting identity to reconcile retries and partial reviews during the retention window.
A coverage manifest can be small without being empty. In this design it records chunk identifiers, input revision, eligible and completed counts, stage outcomes, and configuration version. It should identify an incomplete review explicitly. A fluent reduction must never silently convert missing chunk results into a claim that the submitted change has no findings.
Retry semantics belong in the accounting model
RFC 9110 distinguishes idempotent methods and constrains automatic retries of non-idempotent requests. A client should not infer that repeating a generation request is safe merely because the first response never arrived. Application-level duplicate suppression requires an explicit service contract.
Separate logical work from attempts.
For this review pipeline, use one stable logical identity for a revision and distinct attempt identities for executions. If an attempt is retried, retain its relationship to the original operation. The design should account for incurred work even when only one final review is delivered. An idempotency mechanism, where supported by the service contract, can help control duplicate effects; it is not proof that an interrupted attempt consumed no resources.
Deploy changes to chunk boundaries, prompts, and selection policy as versioned changes. Test a change containing a finding across a boundary, a duplicated finding in overlapping chunks, and a missing map result. Compare source coverage and structured output alongside usage. If the application uses chat completions, validate the returned structure at its boundary before accepting findings; the interface name alone does not establish conformance to the application's schema. These checks address concrete failure paths without requiring production source text to remain in ordinary logs.
The evidence deliberately left behind
For complete marketplace change reviews, the proposed default remains map reduce with full accounting records and bounded diagnostic retention. Retrieval becomes appropriate when the requested result explicitly permits evidence selection. The deciding criterion is the coverage promise attached to the output.
Stop keeping raw patches, repeated chunk text, and unrestricted generation payloads in routine telemetry. Retain revision references, coverage manifests, attempt relationships, usage records, and the versions needed to interpret them for the defined reconciliation period. Give any retained diagnostic content its own expiration policy.
There is a cost. Once diagnostic content expires, an accounting record can explain which stages ran and what usage was reported, but it cannot reconstruct the exact intermediate text that produced a disputed finding. Reproduction may require access to the original revision and execution configuration; even then, a new generation should not be assumed to reproduce the original output. Accept that investigative limit explicitly. It is the consequence of keeping less on purpose.
References
The HTTP specification supports the retry discussion. The prompting reference supplies background for designing generation instructions; neither source establishes the hypothetical workload or retention policy used in this analysis.
Further reading
- RFC 9110, HTTP Semantics, especially sections 9.2.2 and 9.2.3: https://www.rfc-editor.org/rfc/rfc9110
- Prompt Engineering Guide: https://www.promptingguide.ai
Top comments (0)