fix: guard cosine_similarity against empty pagination page - #1058
fix: guard cosine_similarity against empty pagination page#1058IshanMaheshwari-777 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. Summary by CodeRabbit
WalkthroughChangesThe paginated CRE and node similarity searches now skip empty embedding pages. New tests cover empty final pages while preserving matches from earlier pages. Paginated similarity search
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Paginated similarity lookups now skip empty embedding pages rather than failing, while preserving matches from earlier pages. Both CRE and node paths have regression coverage, with no remaining merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Follow-up to #1048 — guards the paginated embedding similarity fallback against a page that comes back with zero embeddings.
Problem
If a page's stored vectors all fail to parse (e.g. malformed/corrupted
embedding_vecdata),get_embeddings_by_doc_type_paginatedreturns an empty dict for that page. Both_paginatedsimilarity methods still handed that empty page straight tocosine_similarity, which raises:"ValueError: Found array with 0 feature(s) (shape=(1, 0)) while a minimum of 1 is required by check_pairwise_arrays."
This crashes the whole lookup (chatbot query or importer run) instead of just skipping the bad page and continuing to the next one.
Changes
get_id_of_most_similar_cre_paginatedandget_id_of_most_similar_node_paginated: skip the embedding-load/similarity-comparison step entirely when the current page'sembeddingsdict is empty (if embeddings:), while still advancing to the next page as before.test_node_paginated_skips_empty_final_page,test_cre_paginated_skips_empty_final_page) covering a final page that comes back empty while the real match sits on an earlier page.Testing
pytest application/tests/prompt_client_pgvector_similarity_test.py -v— 10 passedValueErrorabove; restored the guard and confirmed both passmypy --stricton the modified test file — no errorspytest application/tests/pci_dss_parser_test.py(real caller of the fixed CRE method) — 8 passedpytest application/tests/) — 978 passed, 2 pre-existing unrelated failures (unchanged from before this branch, confirmed by rerunning them with this branch's changes stashed out)CC: @northdpole