Repository navigation
refactor: separate concerns in RerankService with characterization tests - #126
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
概要
RerankServiceのコード品質向上と責務分離を目的として、create_rerankメソッドの処理を経路別ヘルパーメソッド(_process_tei_proxy,_process_logit_gate,_process_standard_rerank)へ抽出・リファクタリングしました。また、リファクタリングに先立ち仕様を固定するためのキャラクタリゼーションテストを追加しました。各ステップでの変更内容
src/tests/test_rerank_characterization.pyを新規作成し、TEIプロキシのレスポンス整形・ドキュメント返却切替、Logit Gateのuse_ascii_boostフラグ切替、カスタムthreshold評価、トークン計算エラー発生時のフォールバック処理をテスト固定。RerankService.create_rerank内の複合処理を、_process_tei_proxy,_process_logit_gate,_process_standard_rerankの専用プライベートヘルパーメソッドへ分離し、create_rerankをオーケストレーターとして単純化。リファクタリング前後の設計比較
create_rerank内に TEI プロキシ処理、Logit Gate 処理、標準 Cross-Encoder 処理が直列に書かれており、1つのメソッドで複数の責務を負っていました。create_rerankはモデル検証とディスパッチ(オーケストレーション)のみを担当し、実際の評価ロジックは単一責任原則に則り各経路専用ヘルパーメソッドに隠蔽・分離されました。テスト実行結果
uv run pytest src/tests -m "not integration and not slow"270 passed, 7 deselected in 47.61sPR created automatically by Jules for task 12765167999526525587 started by @chottokun