From a0bba7173f147f8cf43613d519382ff2d8774ef7 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 16 Mar 2024 15:49:23 +0100 Subject: [PATCH] Avoid division by zero when computing the scalar product of two quotes --- memory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/memory.py b/memory.py index b5989da..bac5b69 100644 --- a/memory.py +++ b/memory.py @@ -55,7 +55,8 @@ We define a similarity measure on sets which counts the number of elements they have in common """ def scalar(a, b): - return len(a.intersection(b))/sqrt(len(a)*len(b)) + sizeProduct = len(a)*len(b) + return len(a.intersection(b))/sqrt(sizeProduct) if sizeProduct > 0 else 0 def find_best_quote(db, user_input): indexed_input = index(user_input)