Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
生成AIで本番アプリをリリースするためのAWS, LangChain, ベクターデータ...
Search
吉田真吾
October 18, 2023
Programming
1
1.4k
生成AIで本番アプリをリリースするためのAWS, LangChain, ベクターデータベース実践入門 / LangChain-Bedrock
AWS AI Week For Developers
https://pages.awscloud.com/AIW4Dev.html
10/18(水) Day2トラックで話した資料です。
吉田真吾
October 18, 2023
Tweet
Share
More Decks by 吉田真吾
See All by 吉田真吾
Serverless Meetup #21
yoshidashingo
1
160
リモートMCPサーバーが便利な話
yoshidashingo
1
84
20250728 MCP, A2A and Multi-Agents in the future
yoshidashingo
1
310
20250619 AIコーディング道場 成果発表会
yoshidashingo
0
10
AIコーディング道場成果発表【予告】
yoshidashingo
0
11
20250426 LT
yoshidashingo
0
8
Difyで作る生成AIアプリ完全入門解説
yoshidashingo
1
20
AIエージェント時代のエンジニアになろう #jawsug #jawsdays2025 / 20250301 Agentic AI Engineering
yoshidashingo
10
7.7k
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
2.8k
Other Decks in Programming
See All in Programming
Software Architecture
hschwentner
6
2.3k
Domain-centric? Why Hexagonal, Onion, and Clean Architecture Are Answers to the Wrong Question
olivergierke
3
970
Cursorハンズオン実践!
eltociear
2
1.2k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
480
contribution to astral-sh/uv
shunsock
0
540
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
630
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
3
250
フロントエンド開発のためのブラウザ組み込みAI入門
masashi
7
3.5k
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
18
8.6k
開発組織の戦略的な役割と 設計スキル向上の効果
masuda220
PRO
9
1.6k
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
550
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
110
Featured
See All Featured
Building Adaptive Systems
keathley
44
2.8k
BBQ
matthewcrist
89
9.9k
We Have a Design System, Now What?
morganepeng
53
7.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Being A Developer After 40
akosma
91
590k
GraphQLとの向き合い方2022年版
quramy
49
14k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
353
21k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Designing for Performance
lara
610
69k
Transcript
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS AI Week for Developers ⽣成AIで本番アプリをリリースするための AWS, LangChain, ベクターデータベース実践⼊⾨ 吉⽥真吾 取締役CTO 株式会社サイダス
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 吉田真吾 AWS Serverless Hero n p Oracle SA p 113 / pAWS n ( ) CTO p SaaS ( ) pAWS DevOps n pAWS (2012 ) pAWS Samurai 2014 / 2016 pAWS Serverless Hero AWS AWS Lambda Amazon S3
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. https://www.cydas.co.jp/news/press/202304_people-gpt/ 「CYDAS PEOPLE」に、社員からの問い合わせに⾃動で答 えるChatGPT機能「CYDAS Copilot Chat」をリリース
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 6
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ChatGPT/LangChainによる チャットシステム構築[実践]⼊⾨ 本書ではまず、OpenAI APIとLangChainについて解説します。 ChatGPTのようなしくみを業務システムなどに組み込むために は、単にLLMに1つ⼊⼒して1つ出⼒を得るような実装ではな く、複数のタスクを⼀連のワークフロー処理として実現する必 要があります。また、ChatGPTが知識を持たない専⾨知識を答 えてほしいとか、意図した形式で応答が欲しいなど、実⽤性を ⾼める必要も出てきます。これらを実現するためのLangChain のつかいかたをわかりやすく解説します。 後半では、ステートレスなOpenAI APIに記憶を持たせたり、 必要に応じてWeb検索などを⾏うエージェント処理、さらに それらチャット形式の処理を、ステップバイステップでWeb アプリやSlackアプリとして実装します。 さらに、LLMアプリを本番稼働させるうえで必要となる、 ユーザー体験、セキュリティ、コンプライアンスへの準拠など のためのヒントや注意点も解説します。 7
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ChatGPT/LangChainによるチャットシステム構築[実践]⼊⾨ 8 質問に対してDuckDuckGoで外部検索して 答えるWebアプリ LLM を組み込んだチャットアプリケーションを写経しながら実装できる「ChatGPT/LangChain によるチャットシステム構築[実践]⼊⾨」を読んだ https://kakakakakku.hatenablog.com/entry/2023/10/16/085525 アップロードしたドキュメントについて 答えるSlackアプリ
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ⽣成AIでできること 1.⾔語⽣成 2.画像⽣成・動画⽣成 3.⾳声⽣成 4.マルチモーダル = 画像+⾔語→⾔語、⾔語→動画+⾔語、など ⾔語⽣成 • ⽂章⽣成、⽂章要約 • RAG(検索拡張⽣成) • 外部エージェントを利⽤した さまざまなアシスタント 9 メール⽂章の作成
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ⽣成AIでできること 10 事業企画アシスタント 1on1相⼿ コード⽣成 最新のマーケットリサーチ
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LLMアプリをつくるときに開発者が考えること 1.モデルの開発や選定について 基盤モデルから作る = コスト「超⼤」 カスタマイズ(ファインチューニング) = コスト「中」 RAGなどLLM性能+外部知識を利⽤する = コスト「低」 2.モデルをホストする計算資源(CPU/GPU)について ⾃社でホストする = コスト「⼤」 APIで利⽤する = コスト「低」 3.既存のシステムとの統合(ガバナンス) マルチクラウドで実装する = コスト「中」 ファーストパーティのみで実装する = コスト「低」 → 現有のモデル+API利⽤+ファーストパーティ(AWSユーザーならAWS)が 開発者にとってもっともROIが⾼い 11
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Amazon Bedrock 12 https://aws.amazon.com/jp/bedrock/
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LLMの能⼒をシステムに組み込みたい 1.API経由で使うモデルの選定 Amazon Bedrock > ClaudeやTitanFM、HuggingFace上のモデルの選定 2.アプリケーションフレームワークからユースケースに合わせて抽象化して 利⽤する LangChainなどのフレームワークで - 品質の安定したプロンプティング - モデルやパラメータの変更耐性に強いコード - キャッシュ、データベース、プラグインなどの統合利⽤ 3.ベクターデータベースや追加オプションなど、新たな技術スタックの統合 データ中⼼のアプローチ > Data Gravity tl;dr データ移動やコピーはコストがかかる、ロバスト性や完全性の懸念 13
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangChainとは 14 • LLMをつかったアプリケーション開発 のフレームワークライブラリ • モデル/メモリ/エージェント/Retriever などの機能が抽象化されており、少な いコードで効率的な開発・アウトプッ トが得られる • 開発初期において複雑なプロンプトエ ンジニアリングにかかる⼿間がユース ケースに合致したテンプレートを⾒つ けることで⼀気に短縮することも可能
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ベクターデータベースとは AWSで利⽤可能なベクターDBオプション • Amazon RDS for PostgreSQL - pgvector • Amazon Aurora PostgreSQL – pgvector • Amazon OpenSearch Service • Amazon Neptune ML LangChainでつかえるさまざまなベクターDB • Pinecone • Chroma (ローカル) • Momento Vector Index • PGVector • Redis (Redisearchオプション) • Elasticsearch • MongoDB Atlas • Supabase (Postgres) • OpenSearch • etc… 15 ⽂章や画像から、コンピューターが⾔語処理や解析しやすいベクトル空間の数値データに変換した「⾼次元ベクトル」の データをホストすることで、インプットと類似度で検索が可能なデータベース。 単語やフレーズをインプットとして、意味の類似する⽂書のチャンクを取り出す⽬的などに利⽤される。 https://python.langchain.com/docs/integrations/vectorstores/ https://aws.amazon.com/jp/what-is/vector-databases/ https://aws.amazon.com/jp/about-aws/whats- new/2023/07/amazon-aurora-postgresql-pgvector-vector-storage- similarity-search/
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangChain + Amazon Bedrock(Titan/Claude) + Pinecone 16 aws-samples/amazon-bedrock-workshop https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/03_QuestionAnswering/02_rag_claude_titan_pinecone.ipynb
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 本番リリースする前に[観測・テスト・評価] • ユースケースにあわせたテスト評価セットの事前作成 • 現在、独⾃の知識をもちいたRAGや、エージェントツールに対し て万能に精度を評価する有効性の⾼いソリューションはない。 • LangSmithで以下の値を参考にしてテストする • P99 Latency • Tokens (消費) • Input / Retrival結果 / Output 17
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangSmith 18
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. LangSmith 19
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 本番リリースする前に[セキュリティについて] • 意図しないコンテンツの⼊⼒防⽌ チャットボットの質問など、⼊⼒コンテンツに意図しないものを 含まないよう、アプリケーションのUIでガイダンスを設置する。 ⼊⼒フィルター機能が使える場合は使う • 不適切な出⼒の回避 暴⼒的な発⾔や偏⾒、不快なコンテンツのチェック→排除。 出⼒フィルター機能が使える場合は使う レイテンシと安全性のトレードオフを加味する。 • プロンプトインジェクションの防⽌ ⼊⼒コンテンツで指⽰を上書きし、任意の指⽰を可能にする攻撃。 ⼊⼒プロンプトによって指⽰が上書きされないようなプロンプト テンプレートの構成をおこなうこと。 • トークンを⼤量に消費させる攻撃の防⽌ ⼊⼒コンテンツの⻑さチェックや、⼀定時間内の実⾏回数やトー クン消費量に上限を設けるなどして、リクエスト内容に制限をか ける。 20 • 安全でない出⼒コンテンツのチェック LLMアプリケーションの出⼒内容が、システム全体にとって安全 でない内容(たとえばXSSやCSRFを引き起こすコードなど)を出⼒ しないように、出⼒コンテンツのチェックをおこない、⼀律の⽂ 字列エンコード処理などをおこなう。 • 脆弱性の排除 新しいライブラリやフレームワークの導⼊、リリースパイプライ ンの構築で、脆弱性が混⼊しうるポイントが増える。現⾏システ ムと同等の脆弱性対応を実施する。 • エージェントを暴⾛させない 外部接続性・実⾏性が⾼いエージェントを暴⾛させない。 エージェント = 前⼯程でLLMが⽣成したコンテンツから次⼯程の 指⽰を推論することでワークフローを達成しようと動作する.。 実⾏可能な外部機能を最⼩限にし、操作対象の権限(データの取 得・編集・削除など)を最⼩化する。 ⼗分なケースでテストを実施する。 OWASP Top 10 for Large Language Model Applications https://owasp.org/www-project-top-10-for-large-language-model-applications/
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. Thank you! © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.