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.3k
生成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 吉田真吾
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
2
420
AOAI Dev Day - Opening Session
yoshidashingo
2
1.6k
LLMアプリにエージェントらしさを組み込む/Build LLM Apps Agentically
yoshidashingo
6
1.5k
マルチエージェントで性能が上がったText-to-SQLのいま/Text-to-SQL
yoshidashingo
2
2.8k
AIエージェントをちゃんと作る/How to build agentic AI
yoshidashingo
5
2.2k
OCI Generative AI Serviceの話/20240222
yoshidashingo
0
130
ChatGPTでちゃんと成果を出していく/20240215
yoshidashingo
3
5.9k
この先を生き残るために!!「生存戦略としてのLLMアプリ開発技術」/20240124_PE-BANK
yoshidashingo
0
140
LangChainとフルサーバーレスですばやくセキュアなRAGアプリをつくるための実践解説/LangChain_Book
yoshidashingo
8
4.2k
Other Decks in Programming
See All in Programming
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
590
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
53
18k
WebDriver BiDiとは何なのか
yotahada3
1
150
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.5k
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
0
200
React 19アップデートのために必要なこと
uhyo
2
590
チームリードになって変わったこと
isaka1022
0
210
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
180
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
280
Open source software: how to live long and go far
gaelvaroquaux
0
650
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.4k
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
8
1.1k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
35
1.6k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
RailsConf 2023
tenderlove
29
1k
The Language of Interfaces
destraynor
156
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
Automating Front-end Workflow
addyosmani
1368
200k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
366
25k
Faster Mobile Websites
deanohume
306
31k
Git: the NoSQL Database
bkeepers
PRO
427
64k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
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.