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, ベクターデータベース実践入門 / LangChain-Bedrock
Search
吉田真吾
October 18, 2023
Programming
1
870
生成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 吉田真吾
OCI Generative AI Serviceの話/20240222
yoshidashingo
0
80
ChatGPTでちゃんと成果を出していく/20240215
yoshidashingo
1
1.7k
この先を生き残るために!!「生存戦略としてのLLMアプリ開発技術」/20240124_PE-BANK
yoshidashingo
0
52
LangChainとフルサーバーレスですばやくセキュアなRAGアプリをつくるための実践解説/LangChain_Book
yoshidashingo
8
3.8k
LLM App with Momento
yoshidashingo
0
180
AWSでLLMアプリをつくろう / LLM App on AWS
yoshidashingo
0
480
Azure OpenAIをもちいたLLMアプリの企画から本番構築までの道のり/Microsoft Build Japan
yoshidashingo
8
8.5k
RAGアプリにおけるプロンプトとtemperatureの応答品質への影響ほんとのところ/the real case about temperature and template language
yoshidashingo
0
720
Momento Meetup 2
yoshidashingo
0
110
Other Decks in Programming
See All in Programming
ServerAction で Progressive Enhancement はどこまで頑張れるか? / progressive-enhancement-with-server-action
takefumiyoshii
0
130
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
2
190
Java 22 Overview
kishida
1
190
Apache Hive 4 on Treasure Data
ryukobayashi
0
380
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
200
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
43
19k
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
2
120
Ruby Pattern Matching
bkuhlmann
0
930
Kotlin Multiplatform at Stable and Beyond (Android Makers 2024)
zsmb
0
390
新宿ダンジョンを可視化してみた
satoshi7190
2
270
Ruby Function Composition
bkuhlmann
1
330
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
150
Featured
See All Featured
KATA
mclloyd
16
12k
Faster Mobile Websites
deanohume
300
30k
Art, The Web, and Tiny UX
lynnandtonic
290
19k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
245
20k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
19
6.9k
Code Review Best Practice
trishagee
56
15k
Product Roadmaps are Hard
iamctodd
45
9.7k
From Idea to $5000 a Month in 5 Months
shpigford
378
45k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
Stop Working from a Prison Cell
hatefulcrawdad
267
19k
Music & Morning Musume
bryan
41
5.6k
Why Our Code Smells
bkeepers
PRO
331
56k
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.