mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-12 20:59:00 +08:00
Fix xinference rerank issue. (#4499)
### What problem does this PR solve? #4495 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
a75cda4957
commit
3805621564
@ -172,6 +172,10 @@ class XInferenceRerank(Base):
|
|||||||
def similarity(self, query: str, texts: list):
|
def similarity(self, query: str, texts: list):
|
||||||
if len(texts) == 0:
|
if len(texts) == 0:
|
||||||
return np.array([]), 0
|
return np.array([]), 0
|
||||||
|
pairs = [(query, truncate(t, 4096)) for t in texts]
|
||||||
|
token_count = 0
|
||||||
|
for _, t in pairs:
|
||||||
|
token_count += num_tokens_from_string(t)
|
||||||
data = {
|
data = {
|
||||||
"model": self.model_name,
|
"model": self.model_name,
|
||||||
"query": query,
|
"query": query,
|
||||||
@ -183,7 +187,7 @@ class XInferenceRerank(Base):
|
|||||||
rank = np.zeros(len(texts), dtype=float)
|
rank = np.zeros(len(texts), dtype=float)
|
||||||
for d in res["results"]:
|
for d in res["results"]:
|
||||||
rank[d["index"]] = d["relevance_score"]
|
rank[d["index"]] = d["relevance_score"]
|
||||||
return rank, res["meta"]["tokens"]["input_tokens"] + res["meta"]["tokens"]["output_tokens"]
|
return rank, token_count
|
||||||
|
|
||||||
|
|
||||||
class LocalAIRerank(Base):
|
class LocalAIRerank(Base):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user