ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s

This commit is contained in:
2026-08-20 13:12:50 +00:00
commit b119135836
10275 changed files with 3284984 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import pytest
import os
import sys
sys.path.insert(0, os.path.abspath("chapter3/sparse-embedding"))
from collections import Counter
from bm25_engine import InvertedIndex, BM25
def test_bm25_calculate_term_score_zero_avgdl():
"""Prove that calculating term score when avgdl is 0 handles division by zero safely."""
index = InvertedIndex()
bm25 = BM25(index)
assert bm25.avgdl == 0
index.term_frequency[1] = Counter({"python": 2})
index.doc_lengths[1] = 5
index.index["python"].add(1)
score = bm25.calculate_term_score("python", doc_id=1)
assert isinstance(score, float)
def test_bm25_calculate_raw_idf_n_less_than_df():
"""Prove that calculate_raw_idf when total_documents N < df does not raise math domain error."""
index = InvertedIndex()
index.index["python"].add(1)
bm25 = BM25(index)
idf = bm25.calculate_raw_idf("python")
assert isinstance(idf, float)