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
24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
"""Regression: FAISS padding index -1 must not map to documents[-1]."""
|
|
from pathlib import Path
|
|
|
|
|
|
def test_search_guards_negative_indices():
|
|
src = Path(__file__).with_name("knowledge_base.py").read_text()
|
|
assert "0 <= idx < len(self.documents)" in src
|
|
|
|
documents = [{"id": i} for i in range(3)]
|
|
indices = [0, -1, -1]
|
|
results = [documents[idx] for idx in indices if 0 <= idx < len(documents)]
|
|
assert results == [{"id": 0}]
|
|
|
|
|
|
def test_index_dimension_tracks_model_and_rebuilds_on_mismatch():
|
|
"""The FAISS index dimension must come from the loaded model (not a fixed
|
|
384), and a persisted index built with a different model must be rebuilt on
|
|
load — otherwise every add()/search() raises a swallowed dimension mismatch
|
|
and semantic search silently degrades to keyword-only."""
|
|
src = Path(__file__).with_name("knowledge_base.py").read_text()
|
|
assert "get_sentence_embedding_dimension()" in src
|
|
assert "self.index.d != self.embedding_dim" in src
|
|
assert "_rebuild_index_from_metadata" in src
|