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
@@ -0,0 +1,46 @@
import pytest
import sys
from pathlib import Path
ch3_retrieval = Path(__file__).resolve().parent.parent / "chapter3" / "retrieval-pipeline"
if str(ch3_retrieval) not in sys.path:
sys.path.insert(0, str(ch3_retrieval))
from document_store import DocumentStore # noqa: E402
def test_add_document_clears_stale_metadata_keys():
store = DocumentStore()
store.add_document("doc1", "Text 1", {"author": "Alice", "category": "AI"})
assert "author" in store.metadata_index
assert "category" in store.metadata_index
assert store.metadata_index["category"] == ["doc1"]
store.add_document("doc1", "Updated Text 1", {"author": "Alice"})
assert "author" in store.metadata_index
assert "category" not in store.metadata_index
assert store.get_stats()["metadata_fields"] == ["author"]
def test_add_document_clears_all_metadata_when_updated_with_none():
store = DocumentStore()
store.add_document("doc1", "Text 1", {"topic": "Math", "level": "Intro"})
assert "topic" in store.metadata_index
store.add_document("doc1", "Text 1 updated", None)
assert "topic" not in store.metadata_index
assert "level" not in store.metadata_index
assert store.metadata_index == {}
def test_add_document_update_preserves_other_documents_index():
store = DocumentStore()
store.add_document("doc1", "Doc 1", {"tag": "shared", "extra": "doc1_only"})
store.add_document("doc2", "Doc 2", {"tag": "shared"})
assert store.metadata_index["tag"] == ["doc1", "doc2"]
assert store.metadata_index["extra"] == ["doc1"]
store.add_document("doc1", "Doc 1 v2", {"tag": "shared"})
assert store.metadata_index["tag"] == ["doc1", "doc2"]
assert "extra" not in store.metadata_index