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.5k
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
2.6k
Other Decks in Programming
See All in Programming
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
870
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
180
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
11
6.9k
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
3
230
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
330
CSC509 Lecture 03
javiergs
PRO
0
340
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
330
20251016_Rails News ~Rails 8.1の足音を聴く~
morimorihoge
2
610
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
230
Swift Concurrency - 状態監視の罠
objectiveaudio
2
550
Leading Effective Engineering Teams in the AI Era
addyosmani
7
510
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
350
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Scaling GitHub
holman
463
140k
Become a Pro
speakerdeck
PRO
29
5.6k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
A Modern Web Designer's Workflow
chriscoyier
697
190k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
RailsConf 2023
tenderlove
30
1.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
990
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
It's Worth the Effort
3n
187
28k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
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.