fiewolf1000 commited on
Commit
8fb64e4
·
verified ·
1 Parent(s): 388b42c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -106,8 +106,10 @@ class CrossEncoderModel:
106
  def rerank(self, query: str, documents: List[str], top_k: int, truncation: bool) -> List[DocumentScore]:
107
  if not documents:
108
  raise ValueError("候选文档不能为空")
109
- if top_k <= 0 or top_k > len(documents):
110
- raise ValueError(f"top_k 需在 1~{len(documents)} 之间")
 
 
111
  doc_scores = []
112
  for doc in documents:
113
  inputs = self.tokenizer(
 
106
  def rerank(self, query: str, documents: List[str], top_k: int, truncation: bool) -> List[DocumentScore]:
107
  if not documents:
108
  raise ValueError("候选文档不能为空")
109
+ if top_k <= 0:
110
+ raise ValueError("top_k 必须为正整数")
111
+ # 自动将 top_k 限制为文档数量(避免超出)
112
+ top_k = min(top_k, len(documents))
113
  doc_scores = []
114
  for doc in documents:
115
  inputs = self.tokenizer(