]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Prefer higher version ANN profiles when symbol distances are equal
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 20 Jan 2026 11:09:47 +0000 (11:09 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 20 Jan 2026 11:09:47 +0000 (11:09 +0000)
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

index 231c0c7163e8c016b1a07aec34982d1037c49089..f54ea1a5e6efbb0f79ab2572b001f02d64bb111b 100644 (file)
@@ -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