Skip to content

refactor: separate concerns in RerankService with characterization tests - #126

Merged
chottokun merged 2 commits into
mainfrom
jules-12765167999526525587-6da62c19
Oct 18, 2026
Merged

chottokun merged 2 commits into
mainfrom
jules-12765167999526525587-6da62c19

Conversation

@chottokun

Copy link
Copy Markdown
Owner

概要

RerankService のコード品質向上と責務分離を目的として、create_rerank メソッドの処理を経路別ヘルパーメソッド(_process_tei_proxy, _process_logit_gate, _process_standard_rerank)へ抽出・リファクタリングしました。また、リファクタリングに先立ち仕様を固定するためのキャラクタリゼーションテストを追加しました。

各ステップでの変更内容

  1. Step 1: ベースライン確認
    • 既存の全単体テスト(265件)を実行し、全てグリーンであることを確認。
  2. Step 2: キャラクタリゼーションテスト追加
    • src/tests/test_rerank_characterization.py を新規作成し、TEIプロキシのレスポンス整形・ドキュメント返却切替、Logit Gateの use_ascii_boost フラグ切替、カスタム threshold 評価、トークン計算エラー発生時のフォールバック処理をテスト固定。
  3. Step 3: インクリメンタルなリファクタリング
    • RerankService.create_rerank 内の複合処理を、_process_tei_proxy, _process_logit_gate, _process_standard_rerank の専用プライベートヘルパーメソッドへ分離し、create_rerank をオーケストレーターとして単純化。
  4. Step 4: 事前チェック
    • Ruff によるフォーマットチェックおよび全テストスイート (270件) の Green 通過を確認。

リファクタリング前後の設計比較

  • リファクタリング前:
    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.61s

PR created automatically by Jules for task 12765167999526525587 started by @chottokun

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chottokun
chottokun merged commit 0c21446 into main Oct 18, 2026
2 checks passed
@chottokun
chottokun deleted the jules-12765167999526525587-6da62c19 branch October 18, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant