LangChain & RAG
LangChain & RAG
Introduction to
🦜🔗LangChain and Retrieval
Augmented Generation
(RAG)
Sophia Yang, Ph.D.
https://sophiamyang.github.io/slides-langchain-rag-panel/
ABOUT ME
Psychology, Statistics, and Computer Science
5+ years at Anaconda
sophiamyang
https://sophiamyang.github.io/slides-langchain-rag-panel/ sophiamyang
AGENDA
1 LangChain
2 RAG
3 Building a Chatbot
What is 🦜🔗 LangChain?
Code:
🦜🔗 LangChain is a framework for developing applications powered by language
models.
Context-aware Reason
connect a language model reason about how to
to other sources of answer, what actions to
context take
user query
prompt
LLM
Output
user query LLMs
prompt
..
.
LLM
Output
user query
prompt
template
prompt
LLM
Prompt Template
Output
user query
Output
parser
prompt
LLM
Output Parser
Output
user query
prompt
LLM
Memories
Output
Keep the last 1 interaction
creates a summary of the
conversation over time
Combine the two
prompt template
LLM 🔗 memory 🔗 prompt
user query
prompt
🔗
LLM
Chains
LLMChain
prompt
template
🔗
LLM
LLMChain
prompt
template
🔗
LLM
LLMChain
prompt
template
🔗
LLM
LLMChain
prompt
template
🔗
LLM
LLMChain 🔗
prompt
template
🔗
LLM
user query
tools
prompt
LLM
Tools
Output
Tools
🦜🔗 LangChain
Tools
Agent
Use an LLM to
choose a sequence
of actions to take
Agent
Agent
Agent
What is RAG
Retrieval Augmented
Generation?
user query
A few examples:
SelfQueryRetriever:
semantic search + extract filters on the metadata
RAG Fine-tuning
https://arxiv.org/abs/2310.01352
How to build a Chatbot
using Panel?
What is Panel?
Build a basic chatbot
https://holoviz-topics.github.io/panel-chat-examples/basics/
Build an AI chatbot
https://holoviz-topics.github.io/panel-chat-examples/langchain/
Chat with PDF
https://holoviz-topics.github.io/panel-chat-examples/langchain/
Step 1: Define Panel widgets
Step 2: Wrap LangChain Logic
into a Function
Step 2: Wrap LangChain Logic
into a Function
replaced some
values with the
widgets we just
defined
Step 3: Create a chat
interface
Step 4: Customize the look with
a template
Chat with PDF
https://holoviz-topics.github.io/panel-chat-examples/langchain/
SophiaYangDS
sophiamyang
sophiamyang
sophiamyang