Skip to content

refactor: improve docling option serialization, VLM helpers and metrics formatting - #237

Merged
chottokun merged 2 commits into
mainfrom
jules-17989042495812980440-2719dc3d
Oct 18, 2026
Merged

chottokun merged 2 commits into
mainfrom
jules-17989042495812980440-2719dc3d

Conversation

@chottokun

Copy link
Copy Markdown
Owner

概要 (Overview)

Doclingライブラリの最新コード(docling 2.113.0 / docling-core 2.87.1)を活用し、コード品質の向上、責務分離、パフォーマンス最適化を目的とした反復的なリファクタリングを実施しました。

ステップごとの変更内容 (Changes by Step)

  1. Step 1: ベースライン確認
    • 既存テストを実行し、406 passed, 3 skipped, 0 failed を確認。
  2. Step 2: キャラクタリゼーションテスト補強
    • tests/test_refactor_docling_latest.py を追加し、変換オプションの辞書変換、画像シリアライザのページ番号・インデックスキャッシュ、VLMヘルパー、プロメテウスメトリクス生成の挙動をテストで固定。
  3. Step 3: インクリメンタルなリファクタリング
    • (a) 変換オプションの一元化: DocumentConversionOptions に to_dict() および from_dict() を追加し、server.py および pool.py で重複していた辞書生成ロジックを一元化。
    • (b) 画像シリアライザの最適化: CustomMarkdownPictureSerializer で未使用の _get_closing_delim を削除し、ドキュメントのインデックス作成時に page_no マッピング(_pic_ref_to_page_no)も事前計算してキャッシュ化。
    • (c) VLMクライアントの整理: vlm.py に _compute_backoff_delay ヘルパーを抽出してジッター付指数バックオフ計算を共通化。
    • (d) メトリクス生成のモジュール化: server.py の _MetricsRegistry に _format_conversions_total や _format_memory_used などのプライベートメソッドを抽出し、プロメテウス形式出力の可読性を向上。
  4. Step 4: 最終検証 & クリーンアップ
    • pytest(410 passed)、mypy(0 errors)、ruff(0 errors)をすべてパス。

リファクタリング前後の設計比較 (Design Comparison)

  • オプション管理: 以前は各プロセス間(server.py, pool.py)でオプション辞書の手動マッピングが重複して存在していましたが、DocumentConversionOptions.to_dict() / from_dict() に集約し、単一責任原則(SRP)およびDRYを徹底しました。
  • VLMリトライ: バックオフ遅延計算を独立したピュア関数 _compute_backoff_delay に分離し、非同期・同期の重複コードを解消しました。
  • メトリクス生成: 一つの長大関数で行われていた各種指標(Counter/Gauge/Summary)の文字列整形を専用フォーマッタメソッドへ分解し、拡張性と可読性を向上させました。

テスト実行結果 (Test Results)

  • uv run --extra test pytest: 410 passed, 3 skipped
  • uv run --extra test mypy --ignore-missing-imports src: 0 errors
  • uv run ruff check src tests: 0 errors

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

…cs formatting

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 e6003e7 into main Oct 18, 2026
1 check passed
@chottokun
chottokun deleted the jules-17989042495812980440-2719dc3d branch October 18, 2026 00:35
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