From d16db9dd67072df1dbb8d14fbdef467d29232e82 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 20 Jan 2026 11:09:47 +0000 Subject: [PATCH] [Fix] Prefer higher version ANN profiles when symbol distances are equal When multiple ANN profiles have the same symbol distance, the profile selection would pick the first one encountered rather than the newest. This caused issues when a newly trained ANN (version 1) existed alongside the initial profile (version 0) - the scanner would select version 0 which had no actual ANN data. Fix by adding a secondary selection criterion: when distances are equal, prefer the profile with the higher version number. --- src/plugins/lua/neural.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/lua/neural.lua b/src/plugins/lua/neural.lua index 231c0c7163..f54ea1a5e6 100644 --- a/src/plugins/lua/neural.lua +++ b/src/plugins/lua/neural.lua @@ -754,7 +754,8 @@ local function process_existing_ann(_, ev_base, rule, set, profiles) local dist = lua_util.distance_sorted(elt.symbols, my_symbols) -- Check distance if dist < #my_symbols * .3 then - if dist < min_diff then + -- Prefer profiles with smaller distance, or higher version when distance is equal + if dist < min_diff or (dist == min_diff and sel_elt and elt.version > sel_elt.version) then min_diff = dist sel_elt = elt end -- 2.47.3