Mock embedding model for test coverage of semantic search path #2

Open
opened 2026-10-23 22:48:23 +00:00 by lichenblankie · 0 comments

src/tinyweb/embeddings.py has zero test coverage. The entire semantic search path — chunking, ONNX inference, HNSW indexing, hybrid search with RRF fusion — is untested because tests cannot download the model.

Affected code paths:

  • embed() — ONNX inference path never exercised
  • store_embeddings() / store_remote_embeddings() — chunk + embed + store cycle never run
  • build_index() — HNSW index construction never tested
  • hybrid_search() / semantic_search() — ANN query + RRF fusion never tested
  • reindex_all() — full reindex path never tested

Current test coverage only hits the BM25 fallback path. Tests that enable semantic_search setting still never call into ONNX because the model isn't downloaded in CI.

Fix: Abstract the model behind a protocol/base class. Swap a FakeEmbeddingModel in tests that returns deterministic random vectors of the correct dimension. Build a real HNSW index from fake vectors and verify:

  • hybrid_search() returns results in correct order
  • RRF fusion weights BM25 and semantic scores correctly
  • store_embeddings() inserts correct chunk rows
  • reindex_all() clears and rebuilds

The fake model should be zero-dependency (numpy only, no ONNX/tokenizers). Set via env var or monkeypatch.


Synced from Codeberg issue #2 — opened by @fluffblankie on 2026-07-04.

src/tinyweb/embeddings.py has zero test coverage. The entire semantic search path — chunking, ONNX inference, HNSW indexing, hybrid search with RRF fusion — is untested because tests cannot download the model. Affected code paths: - embed() — ONNX inference path never exercised - store_embeddings() / store_remote_embeddings() — chunk + embed + store cycle never run - build_index() — HNSW index construction never tested - hybrid_search() / semantic_search() — ANN query + RRF fusion never tested - reindex_all() — full reindex path never tested Current test coverage only hits the BM25 fallback path. Tests that enable semantic_search setting still never call into ONNX because the model isn't downloaded in CI. Fix: Abstract the model behind a protocol/base class. Swap a FakeEmbeddingModel in tests that returns deterministic random vectors of the correct dimension. Build a real HNSW index from fake vectors and verify: - hybrid_search() returns results in correct order - RRF fusion weights BM25 and semantic scores correctly - store_embeddings() inserts correct chunk rows - reindex_all() clears and rebuilds The fake model should be zero-dependency (numpy only, no ONNX/tokenizers). Set via env var or monkeypatch. --- *Synced from [Codeberg issue #2](https://codeberg.org/tinyweb/tinyweb/issues/2) — opened by @fluffblankie on 2026-07-04.* <!-- codeberg-issue: 2 -->
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lichenblankie/tinyweb#2
No description provided.