Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix bge rerank normalize issue (#988)

KevinHuSh77363a087562
diff --git a/rag/llm/rerank_model.py b/rag/llm/rerank_model.py
index c1c12f1130..5039e11a04 100644
--- a/rag/llm/rerank_model.py
+++ b/rag/llm/rerank_model.py
@@ -24,6 +24,8 @@ import numpy as np
from api.utils.file_utils import get_home_cache_dir
from rag.utils import num_tokens_from_string, truncate
+def sigmoid(x):
+ return 1 / (1 + np.exp(-x))
class Base(ABC):
def __init__(self, key, model_name):
@@ -69,6 +71,7 @@ class DefaultRerank(Base):
res = []
for i in range(0, len(pairs), batch_size):
scores = self._model.compute_score(pairs[i:i + batch_size], max_length=2048)
+ scores = sigmoid(np.array(scores))
res.extend(scores)
return np.array(res), token_count