From 0ca7b8d48961cffee51d072d18b303d7f68aa6dd Mon Sep 17 00:00:00 2001 From: ArmanGrewal007 Date: Mon, 10 Aug 2026 17:35:37 +0530 Subject: [PATCH 1/2] fix(methods): improve error handling in vector similarity calculations --- semantica/semantic_extract/methods.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/semantica/semantic_extract/methods.py b/semantica/semantic_extract/methods.py index 72898deb..06854619 100644 --- a/semantica/semantic_extract/methods.py +++ b/semantica/semantic_extract/methods.py @@ -247,6 +247,8 @@ def find_best_match_index(text: str, candidates: List[str]) -> Tuple[int, float] Find the best matching candidate index and score. Uses hybrid similarity approach: Exact -> Synonym -> Substring -> Embeddings -> Vector -> Fuzzy. Optimized for batch processing to avoid redundant embedding calculations. + Embedding/vector similarity stages are best-effort; if they fail, matching falls back + to remaining strategies instead of raising. Returns: Tuple[int, float]: (best_candidate_index, best_score). Index is -1 if no candidates. @@ -381,8 +383,10 @@ def find_best_match_index(text: str, candidates: List[str]) -> Tuple[int, float] if score > vector_score: vector_score = score vector_idx = i - except Exception: - pass + except Exception as e: + logger.debug(f"Vector similarity calculation failed: {e}") + vector_score = 0.0 + vector_idx = -1 if vector_score > best_score: best_score = vector_score From 6148975e8334df2e201a363cfdbe8e414b5e7a0a Mon Sep 17 00:00:00 2001 From: ArmanGrewal007 Date: Mon, 10 Aug 2026 18:36:37 +0530 Subject: [PATCH 2/2] fix(methods): enhance error logging for vector similarity calculations --- semantica/semantic_extract/methods.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/semantica/semantic_extract/methods.py b/semantica/semantic_extract/methods.py index 06854619..09d98b22 100644 --- a/semantica/semantic_extract/methods.py +++ b/semantica/semantic_extract/methods.py @@ -372,10 +372,12 @@ def find_best_match_index(text: str, candidates: List[str]) -> Tuple[int, float] vector_idx = -1 if nlp and nlp.vocab.vectors.shape[0] > 0: + failing_candidate_idx = -1 try: doc = nlp(text) if doc.vector_norm: for i, candidate in enumerate(candidates): + failing_candidate_idx = i if not candidate: continue cand_doc = nlp(candidate) if cand_doc.vector_norm: @@ -383,8 +385,12 @@ def find_best_match_index(text: str, candidates: List[str]) -> Tuple[int, float] if score > vector_score: vector_score = score vector_idx = i - except Exception as e: - logger.debug(f"Vector similarity calculation failed: {e}") + except Exception: + logger.debug( + "Vector similarity calculation failed at candidate index %s; continuing with fallback scoring.", + failing_candidate_idx if failing_candidate_idx >= 0 else "N/A", + exc_info=True, + ) vector_score = 0.0 vector_idx = -1