0% found this document useful (0 votes)
134 views62 pages

LangChain & RAG

The document introduces LangChain, a framework for developing applications powered by language models, and discusses Retrieval Augmented Generation (RAG). It outlines the steps to build a chatbot using LangChain and Panel, including defining widgets, wrapping logic into functions, and creating a chat interface. The author, Sophia Yang, has a background in psychology, statistics, and computer science, and has contributed to various open-source Python projects.

Uploaded by

Paul Cohen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views62 pages

LangChain & RAG

The document introduces LangChain, a framework for developing applications powered by language models, and discusses Retrieval Augmented Generation (RAG). It outlines the steps to build a chatbot using LangChain and Panel, including defining widgets, wrapping logic into functions, and creating a chat interface. The author, Sophia Yang, has a background in psychology, statistics, and computer science, and has contributed to various open-source Python projects.

Uploaded by

Paul Cohen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 62

ANACONDA

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

Open-source Python package creator and contributor


condastats, cranlogs, PyPowerUp, intake-stripe, intake-salesforce, HoloViz, etc.

Python & Open-source community


NumFocus, PyData, Scipy Conferences
SophiaYangDS
DS/ML book club
https://dsbookclub.github.io/ sophiamyang

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

Knowledge base Relevant Output

text chunks LLM


Every step can be optimized!

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

You might also like