Introduction to
🦜🔗LangChain and Retrieval Augmented Generation (RAG)
Sophia Yang, Ph.D.
ANACONDA
ABOUT ME
5+ years at Anaconda
Psychology, Statistics, and Computer Science
DS/ML book club
sophiamyang
Open-source Python package creator and contributor
condastats, cranlogs, PyPowerUp, intake-stripe, intake-salesforce, HoloViz, etc.
Python & Open-source community
NumFocus, PyData, Scipy Conferences
sophiamyang
sophiamyang
SophiaYangDS
AGENDA
1
2
3
LangChain
RAG
Building a Chatbot
What is 🦜🔗 LangChain?
🦜🔗 LangChain is a framework for developing applications powered by language models.
connect a language model to other sources of context
Context-aware
reason about how to answer, what actions to take
Reason
prompt
LLM
Output
user query
prompt
LLM
Output
...
user query
LLMs
prompt
LLM
Output
prompt template
user query
Prompt Template
prompt
LLM
Output
Output parser
user query
Output Parser
prompt
LLM
Output
user query
Memories
Keep the last 1 interaction
creates a summary of the conversation over time
Combine the two
prompt template
LLM 🔗 memory 🔗 prompt
prompt
LLM
🔗
Output
user query
Chains
LLM
🔗
prompt
template
LLMChain
LLM
🔗
prompt
template
LLMChain
LLM
🔗
prompt
template
LLMChain
LLM
🔗
prompt
template
LLMChain
LLM
🔗
prompt
template
LLMChain
🔗
prompt
LLM
Output
tools
user query
Tools
🦜🔗 LangChain
Tools
Tools
Agent
Use an LLM to
choose a sequence
of actions to take
Agent
Agent
Agent
What is RAG
Retrieval Augmented Generation?
Knowledge base
Relevant
text chunks
LLM
Output
user query
Every step can be optimized!
A few examples:
SelfQueryRetriever:
semantic search + extract filters on the metadata
RAG Fine-tuning
How to build a Chatbot using Panel?
What is Panel?
Build a basic chatbot
Build an AI chatbot
Chat with PDF
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
sophiamyang
sophiamyang
sophiamyang
SophiaYangDS