When implementing or choosing an algorithm (scoring, aggregation, throttling, parsing), ensure it matches the domain semantics and behaves predictably under edge cases.
Guidelines:
max-style logic; avoid avg/min-style dilution unless the semantics truly require “all” or “average.”Example (semantic routing aggregation):
-- Scores are for alternative examples of the same intent.
-- Semantics: “any example matches => route succeeds”, so aggregate by max.
local function semantic_pick(scores, threshold)
local best = -math.huge
for _, s in ipairs(scores) do
if s > best then best = s end
end
if best >= threshold then
return true
end
return false
end
Apply this standard whenever you change scoring/routing/throttling/parsing logic, especially for user-visible behavior where “almost right” algorithms cause silent misroutes or inconsistent rate-limit outcomes.
Enter the URL of a public GitHub repository