refactor(rag): unify RAG pipeline, fix code review issues#92
Merged
Conversation
…tests Remove duplicate BM25/RRF/reranker logic from chat_service.py and delegate to the dedicated modules (hybrid_search, reranker, parent_expansion). Add _qvac_dict_to_chunk() to convert QVAC response dicts to EvidenceChunk. Refactor answer() to use the unified pipeline end-to-end. Add test_hybrid_search.py covering bm25_search, rrf_fuse, load_bm25_index. Replace test_chat_service.py with tests for answer() and _qvac_dict_to_chunk(). Translate Italian comments in pipeline.py chunking parameters to English.
This was referenced May 13, 2026
config.py: replace passlib.CryptContext with direct bcrypt calls. passlib 1.7.4 is incompatible with bcrypt >= 4.0 (removed __about__), causing all password hashing tests to fail with ValueError. pipeline.py: add _register_module_aliases() to register 'services.ai.app.*' as sys.modules aliases for 'app.*'. Required by test_sys_modules_alias.py to guarantee class identity across different import root paths. test_chunker.py / test_ingester_parser.py: guard legacy module imports (module_1_ingestor, module_2_parser, module_3_micro_chunker) with pytest.importorskip so missing optional modules produce skips, not errors. Result: 169 passed, 11 skipped, 0 failed.
longobucco
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all issues identified in the code review of PR #91.
chat_service.pyhad independent reimplementations of_bm25_search,_rrf_merge,_load_corpus,_resolve_merged, and a second FlashRank singleton (_get_reranker). All replaced by delegation tohybrid_search,reranker, andparent_expansionmodules._qvac_dict_to_chunk()added — converts QVAC/retrieveresponse dicts toEvidenceChunkso the unifiedEvidenceChunk-based pipeline can be used end-to-end.answer()refactored — clean 9-step pipeline:/retrieve→ convert → BM25 → RRF → rerank → parent expand →/generate→ citations.pipeline.pytranslated to English (chunking parameters block).test_chat_service.pyreplaced — removed tests for deleted helpers; added tests for_qvac_dict_to_chunk()andanswer()(happy path, dense-only, ChromaDB fallback,/generatefailure, citation precision).test_hybrid_search.pyadded — new file coveringbm25_search,rrf_fuse,load_bm25_index(migrated and adapted from the oldtest_chat_service.py).rag;.gitignoreentry confirmed.Base.metadata.create_all().Test plan
tests/unit/test_chat_service.py— 12 passedtests/unit/test_hybrid_search.py— 10 passed, 4 skipped (rank_bm25 not installed in CI)tests/unit/test_qvac_pipeline.py— 31 passed, 5 skippedtests/unit/suiteCloses #80