Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Deep Dive into Momento with LangChain
Search
Kazuki Maeda
June 22, 2023
Technology
1
390
Deep Dive into Momento with LangChain
もめんと Meet-up in June #2
Kazuki Maeda
June 22, 2023
Tweet
Share
More Decks by Kazuki Maeda
See All by Kazuki Maeda
敢えて生成AIを使わないマネジメント業務
kzkmaeda
2
680
Amazon Bedrockで実現する 新たな学習体験
kzkmaeda
3
1.7k
日本の教育の未来 を考える テクノロジーは教育をどのように変えるのか
kzkmaeda
1
260
モノリスの認知負荷に立ち向かう、コードの所有者という思想と現実
kzkmaeda
0
250
エンジニアリング価値を黒字化する バリューベース戦略を用いた 技術戦略策定の道のり
kzkmaeda
9
6.7k
現場の種を事業の芽にする - エンジニア主導のイノベーションを事業戦略に装着する方法 -
kzkmaeda
2
6.5k
生成AIを用いた 新しい学びの体験を 提供するまでの道のり
kzkmaeda
0
370
生成AIによって変わる世界 -可能性とリスクについて考える-
kzkmaeda
2
340
新しいことを組織ではじめる、そしてつづける
kzkmaeda
5
1k
Other Decks in Technology
See All in Technology
[CMU-DB-2025FALL] Apache Fluss - A Streaming Storage for Real-Time Lakehouse
jark
0
110
計算機科学をRubyと歩む 〜DFA型正規表現エンジンをつくる~
ydah
3
190
技術以外の世界に『越境』しエンジニアとして進化を遂げる 〜Kotlinへの愛とDevHRとしての挑戦を添えて〜
subroh0508
1
380
“決まらない”NSM設計への処方箋 〜ビットキーにおける現実的な指標デザイン事例〜 / A Prescription for "Stuck" NSM Design: Bitkey’s Practical Case Study
bitkey
PRO
1
580
AWS Bedrock AgentCoreで作る 1on1支援AIエージェント 〜Memory × Evaluationsによる実践開発〜
yusukeshimizu
6
370
AWS re:Invent 2025で見たGrafana最新機能の紹介
hamadakoji
0
130
A Compass of Thought: Guiding the Future of Test Automation ( #jassttokai25 , #jassttokai )
teyamagu
PRO
1
240
日本Rubyの会の構造と実行とあと何か / hokurikurk01
takahashim
4
930
エンジニアリングマネージャー はじめての目標設定と評価
halkt
0
250
eBPFとwaruiBPF
sat
PRO
4
2.5k
[JAWS-UG 横浜支部 #91]DevOps Agent vs CloudWatch Investigations -比較と実践-
sh_fk2
1
240
意外とあった SQL Server 関連アップデート + Database Savings Plans
stknohg
PRO
0
290
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
39k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The Invisible Side of Design
smashingmag
302
51k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Code Reviewing Like a Champion
maltzj
527
40k
Into the Great Unknown - MozCon
thekraken
40
2.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Done Done
chrislema
186
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
Producing Creativity
orderedlist
PRO
348
40k
Transcript
Deep Dive into Momento with LangChain もめんと Meet-up in June
#2 kzk_maeda
Kazuki Maeda @kzk_maeda SRE @atama plus AWS Community Builders AWS
Startup Community Core Member 7+ years of experience of AWS Like: Lambda / Step Functions / Glue / MWAA / Athena 最近はGoogle CloudとLLM系を勉強中 自己紹介
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
Momento Cacheとは • Serverless Cache Service • Web上でセットアップして、SDKを埋め込むだけで クラスターセットアップなど不要で利用開始できる •
キャパシティの管理、プロビジョニング、パフォーマンスモニタリングなど オペレーション業務からの解放
LangChainとは • LLM(大規模言語モデル)を利用したアプリケーション開発に利用できる ライブラリ • 各種LLM APIの抽象化、独自データのLoader、ツール群の組み合わせなどの 様々な機能が提供されている • バージョンアップ頻度が異常
なぜLangChainとMomento? https://twitter.com/LangChainAI/status/1662138670332395520?s=20
なぜLangChainとMomento? https://python.langchain.com/docs/ecosystem/integrations/momento
なぜLangChainとMomento? https://www.gomomento.com/blog/momento-is-now-fully-integrated-into-the-langchain-ecosystem
LangChainでMomentoが使える場所 • LLM Cache • Conversation Memory
LLM Cache 通常LangChainでは、都度OpenAIなどのLLMサービスとやりとりをしますが
LLM Cache Cacheが効いていると、InterceptしてCacheからResponseを返します
LLM Cache 実装 数行のコードで実装可能
LLM Cache クエリ時間比較 同一のPromptであれば実行時間を90%以上低減
LLM Cache Token消費量比較 CacheがAnswerを返すのでOpenAIのToken消費量は0
LLM Cache 時間もコストも削減が見込める!!
Conversation Memory 通常、LangChainからLLMへのRequestは状態を持たないので独立実行 →以前の会話内容をLangChainは記憶しない
Conversation Memory ConversationChainのMemoryとしてMomentoを活用し、会話の流れを作れる
Conversation Memory 実装 こちらもシンプルなコードで実装可能
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
注 ここからLangChainのコードを眺めていきますが、 冒頭で紹介したように、LangChainの更新頻度は異常です。 以降のコードは version 0.0.207 のものとなっております。 また、説明の都合でコードの一部のみ抜粋して表示します。
LLM Cache 中で何が行われているのか追ってみましょう
LLM Cache llm_cache が有効であるとcacheに問い合わせる機構が LLMの基底クラスに定義されている
LLM Cache PromptとLLMのparameterをhash化して str castしたtextをKeyにして、Momentoに格納
LLM Cache こんな感じでCacheが衝突しないようになっている
Conversation Memory 中で何か行われているのか追ってみましょう
Conversation Memory ConversationChainの中でmemoryをセットできる
Conversation Memory デフォルトで message_store: 文字列をprefixに付与して session_id を追加したtextをKeyにしている
Conversation Memory plain textをKeyのprefixに追加することで、 CacheのKey(hash化された文字列)との衝突を 抑制している??という推測(中の人教えてください)
ここまで追ってみて • ライブラリを利用する側はシンプルに使えるようにいろんな処理が抽象化されてい る一方、実装側では衝突を防ぐための仕組みが入っていたりと工夫されていること がわかった • 実際にデバッグしてCache Keyを特定してコンソールから確認することができ、楽し かった
agenda Momento with LangChainを触ってみる Momento with LangChainのコードを追ってみる 今後の期待
今後の期待 • Cache機構の拡大 ◦ (LangChainの対応が必要かもしれませんが) Embeddingの生成など、他にもTokenを利用し、時 間がかかる処理があるので、そこでも Cacheが効かせられると嬉しいなと思った • Vector
Storeとしての利用 ◦ 時限式で消えるVector Storeという用途がLLMアプリケーションの中ではそこそこ求められるケース がありそう ◦ Vector Storeが消えていたら新規に Embedding生成してStoreすることでデータ鮮度を高く保つとか ◦ Momentoでそれが実現できると管理が楽で嬉しいなと思った
今後の期待 • 特にVector Storeとして使えると、こういう仕組みを作る時に使い勝手が 非常にいい(気がします)
Thank you