test: add retriever deterministic unit tests#25
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a new unit test module Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/unit/test_retriever.py`:
- Around line 20-22: The one-line abstract-method stubs (add, delete, get)
trigger Ruff A002 and the invalid noqa E704 suppression; replace each one-line
form like "def add(self, id, ...): ... # noqa: E704" with a proper multi-line
stub: declare the same signature (keeping the required parameter name id),
remove the invalid "# noqa: E704", add a valid noqa that matches the linter rule
you intend to suppress for using the name "id" (e.g., "# noqa: <correct-rule>"
if you must suppress the builtin-name check), and make the body raise
NotImplementedError (e.g., def add(...): raise NotImplementedError) so Ruff no
longer flags the abstract-method stub or invalid suppression for add, delete,
and get.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 44116fa5-2a46-4df1-85b1-aa1c7370e03c
📒 Files selected for processing (1)
tests/unit/test_retriever.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
AlexanderGardiner
left a comment
There was a problem hiding this comment.
Looks good! There is a fake memory store object in unit_harness.py, but these tests don't necessarily need that added complexity.
Pull Request
Use a Conventional Commit title:
feat: ...,fix: ...,docs: ...,chore: ...,refactor: ...,test: ...,build: ...,ci: ...,perf: ..., orrevert: ....Summary
Adds offline unit tests for
Retriever.retrieve()verifying the adapter contract: query string reachesembed_fn, the resulting embedding andtop_kare forwarded tomemory_store.query, and chunks are returned unchanged. Also covers the missingembed_fnerror path.Linked context
Closes #16
PR Size
PR Type
Context / Motivation
Retrieverhad no unit tests despite defining a clear contract between the embedding function and memory store. This PR documents and enforces that contract with fully offline tests.Changes
Added
tests/unit/test_retriever.pywith 4 tests: normal retrieval path, defaulttop_k=2, multi-chunk passthrough, andRuntimeErroron missingembed_fn. Uses a small inline_SpyStoreto record calls without any Chroma or live embedding dependency.How to test
uv run pytest -m unit -vtest_retriever.pyshould pass with no network or Ollama dependencyChecklist
Notes for reviewers
test_retrieve_default_top_kassertstop_k=2, which follows the current hardcoded default inretriever.py, rather than endorsing it. Exposingtop_kthroughAnchorConfigwould be a separate improvement.Summary by CodeRabbit