Skip to content

Commit 318d82b

Browse files
emmaling27Convex, Inc.
authored andcommitted
Log instead of error for term diff bug (#27424)
GitOrigin-RevId: 32543f38e09af04528d9e3a6730e2b532017840d
1 parent 7408de9 commit 318d82b

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

crates/search/src/memory_index/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,16 @@ impl MemorySearchIndex {
481481
);
482482
0
483483
});
484-
} else if field == &Field::from_field_id(SEARCH_FIELD_ID) {
485-
stats
486-
.num_terms_by_field
487-
.insert(*field, (*total_term_diff as i64).try_into()?);
484+
} else {
485+
let total_term_diff =
486+
(*total_term_diff as i64).try_into().unwrap_or_else(|e| {
487+
tracing::warn!(
488+
"Inserting 0 for num_terms for field {field:?} with \
489+
{total_term_diff} and error {e}"
490+
);
491+
0
492+
});
493+
stats.num_terms_by_field.insert(*field, total_term_diff);
488494
}
489495
}
490496
for (term, term_id) in &term_ids {

crates/search/src/searcher/searcher.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ impl<RT: Runtime> SearcherImpl<RT> {
958958
// Tantivy's total_num_tokens count is only approximate, so we can't guarantee this won't underflow.
959959
.unwrap_or_else(|| {
960960
tracing::warn!(
961-
"num_terms underflowed for field {field:?}, subtracted num_terms_deleted: {num_terms_deleted} from \
961+
"num_terms underflowed for field {field:?} in query_bm_25_stats_impl, subtracted num_terms_deleted: {num_terms_deleted} from \
962962
total_num_tokens: {total_num_tokens}"
963963
);
964964
0
@@ -971,6 +971,9 @@ impl<RT: Runtime> SearcherImpl<RT> {
971971
num_documents,
972972
doc_frequencies,
973973
};
974+
if stats.is_empty() {
975+
tracing::warn!("Empty BM25 stats");
976+
}
974977
Ok(stats)
975978
},
976979
}
@@ -1360,6 +1363,12 @@ impl Bm25Stats {
13601363
doc_frequencies: BTreeMap::new(),
13611364
}
13621365
}
1366+
1367+
pub fn is_empty(&self) -> bool {
1368+
self.num_terms_by_field.is_empty()
1369+
&& self.num_documents == 0
1370+
&& self.doc_frequencies.is_empty()
1371+
}
13631372
}
13641373

13651374
impl Add for Bm25Stats {

0 commit comments

Comments
 (0)