Skip to content

Commit a7f3d84

Browse files
committed
Errbit | fixing encoder when docs are empty or not predictable
1 parent 78df5b4 commit a7f3d84

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

core/common/search.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,24 @@ def default_model(self):
384384

385385
# private
386386
def _predict_scores(self, hits, txt, name_key, source_attr, should_convert_source_to_dict): # pylint: disable=too-many-arguments
387+
if not hits or not txt:
388+
return []
389+
scores_full = [float("-inf")] * len(hits) # or 0.0
390+
if not isinstance(txt, str) or not txt.strip():
391+
return scores_full # or 0.0
392+
387393
docs = [get(self._get_source(hit, source_attr, should_convert_source_to_dict), name_key) for hit in hits]
388-
return self.encoder.predict([(txt, d) for d in docs])
394+
valid = []
395+
for i, d in enumerate(docs):
396+
if isinstance(d, str) and d.strip():
397+
valid.append((i, d.strip()))
398+
if not valid:
399+
return scores_full
400+
scores = self.encoder.predict([(txt, d) for _, d in valid])
401+
for (i, _), s in zip(valid, scores):
402+
scores_full[i] = float(s)
403+
404+
return scores_full
389405

390406
def _assign_score(self, hits, scores, score_key, order_results):
391407
score_key = score_key or self.SCORE_KEY

0 commit comments

Comments
 (0)