From 94941414e945430eda083bf6025add3f5714a442 Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Mon, 16 Nov 2026 00:14:08 -0300 Subject: [PATCH] fix: normaliza termos do contexto antes de comparar com o chunk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit calculateSemanticSimilarity normalizava o chunk (sem acentos) mas só aplicava toLowerCase em keywords, entidades, tópicos, sinônimos, período e local, e a lista de termos relativos tinha 'último' acentuado. Termos com acento nunca casavam. --- lib/relevance-scorer.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/relevance-scorer.ts b/lib/relevance-scorer.ts index 74cc39b..a7f5332 100644 --- a/lib/relevance-scorer.ts +++ b/lib/relevance-scorer.ts @@ -97,7 +97,7 @@ export function calculateSemanticSimilarity( if (context.keywords.length > 0) { let keywordMatches = 0; for (const keyword of context.keywords) { - const keywordLower = keyword.toLowerCase(); + const keywordLower = normalizeText(keyword); if (normalizedChunk.includes(keywordLower)) { keywordMatches++; } @@ -111,7 +111,7 @@ export function calculateSemanticSimilarity( if (context.entities.length > 0) { let entityMatches = 0; for (const entity of context.entities) { - const entityLower = entity.value.toLowerCase(); + const entityLower = normalizeText(entity.value); // Buscar entidade completa (case-insensitive) if (normalizedChunk.includes(entityLower)) { entityMatches += entity.confidence; // Ponderar por confiança @@ -126,7 +126,7 @@ export function calculateSemanticSimilarity( if (context.topics.length > 0) { let topicMatches = 0; for (const topic of context.topics) { - const topicLower = topic.toLowerCase(); + const topicLower = normalizeText(topic); // Verificar se tópico aparece no chunk (pode ser parcial) const topicWords = topicLower.split(/\s+/); const matches = topicWords.filter(word => @@ -147,7 +147,7 @@ export function calculateSemanticSimilarity( if (context.synonyms.length > 0) { let synonymMatches = 0; for (const synonym of context.synonyms) { - const synonymLower = synonym.toLowerCase(); + const synonymLower = normalizeText(synonym); if (normalizedChunk.includes(synonymLower)) { synonymMatches++; } @@ -163,18 +163,18 @@ export function calculateSemanticSimilarity( // Verificar se contexto temporal/geográfico aparece no chunk let contextualScore = 0; if (context.temporalContext?.period) { - if (normalizedChunk.includes(context.temporalContext.period)) { + if (normalizedChunk.includes(normalizeText(context.temporalContext.period))) { contextualScore += 0.5; } } if (context.temporalContext?.relative) { - const relativeTerms = ['recente', 'atual', 'novo', 'último', 'atualizado']; + const relativeTerms = ['recente', 'atual', 'novo', 'ultimo', 'atualizado']; if (relativeTerms.some(term => normalizedChunk.includes(term))) { contextualScore += 0.3; } } if (context.geographicContext?.location) { - const locationLower = context.geographicContext.location.toLowerCase(); + const locationLower = normalizeText(context.geographicContext.location); if (normalizedChunk.includes(locationLower)) { contextualScore += 0.5; }