AI Photo Critique

LangChain、Pinecone、GPT-4o Vision を使った RAG パイプラインで、実践的な写真講評を生成。

AI/MLRAGLangChainベクトルデータベースプロンプトエンジニアリング
AI Photo Critique

課題

写真上達に必要なのは、具体的で実行可能なフィードバックです。

しかし現実には、

  • 感想が曖昧
  • 意見がバラバラ
  • 専門的レビューは高コスト

という問題がありました。

解決アプローチ

AI Photo Critique では、モデル任せではなく知識を明示的に与える設計を採用しました。

  • 微調整(fine-tuning)ではなく RAG を選択
  • 知識ベースを更新すれば、モデル再学習なしで品質改善可能

処理フロー:

  1. 画像アップロード
  2. GPT-4o Vision で画像記述を生成
  3. 記述を使って Pinecone から関連知識を検索
  4. 検索結果を統合したプロンプトで講評を生成

出力設計

講評は次の 2 セクションで固定しました。

  • ## 良い点
  • ## 改善点

この構造により、読みやすさと実行可能性が大きく向上しました。

RAG パイプライン例

ステップ 1:画像記述

{
  "image_description": "A vertical photograph of the Golden Gate Bridge, partially obscured by a thick layer of fog. The iconic red-orange tower on the right is prominent, rising above the low-hanging clouds. The foreground is the dark, choppy water of the bay. The composition follows the rule of thirds, with the main tower positioned off-center. The mood is somber and atmospheric due to the fog."
}

ステップ 2:関連知識の取得

{
  "retrieved_chunks": [
    {
      "source": "composition_guide.pdf",
      "text": "The Rule of Thirds is a fundamental principle. By placing key elements along the lines or at their intersections, you create a more balanced and engaging photograph than simply centering the subject."
    },
    {
      "source": "landscape_photography.pdf",
      "text": "Atmospheric conditions like fog or mist can be powerful tools for creating mood and a sense of depth. Use them to obscure parts of the scene, adding mystery and drawing focus to your primary subject."
    }
  ]
}

ステップ 3:拡張プロンプトで生成

{
  "system_prompt": "You are an expert, objective photography critic. Your goal is to provide honest, professional feedback to help a photographer improve their craft.",
  "context": [
    "The Rule of Thirds is a fundamental principle. By placing key elements along the lines or at their intersections, you create a more balanced and engaging photograph than simply centering the subject.",
    "Atmospheric conditions like fog or mist can be powerful tools for creating mood and a sense of depth. Use them to obscure parts of the scene, adding mystery and drawing focus to your primary subject."
  ],
  "image_description": "A vertical photograph of the Golden Gate Bridge, partially obscured by a thick layer of fog. The iconic red-orange tower on the right is prominent, rising above the low-hanging clouds. The composition follows the rule of thirds, with the main tower positioned off-center.",
  "instructions": "Generate a critique formatted in Markdown. Structure your response with two main headings: '## What Works Well' and '## Areas for Improvement'."
}

運用面の工夫

  • レート制限:Upstash Redis による IP 制御でコストと濫用を抑制
  • 入力検証:画像形式・サイズを事前チェック
  • 障害時の劣化運転:Pinecone 障害時は非 RAG モードで継続

学び

  • RAG はドメイン知識の継続改善に向いている
  • プロンプト設計は品質に直結する
  • マルチモーダル構成は観測性とフォールバック設計が重要