LangChain - Chat With Your Data
LangChain - Chat With Your Data
Overview
Retrieval Augmented
Generation
Retrieval Augmented Generation (RAG) is a very
popular paradigm.
● Retrieve relevant documents and load into “working
memory” / context window.
URLs
Splits
Documents
PDF
Vector Store Vector
Loading Store
DB
Document Loading
Loaders
Document Splitting
Document Splitting
URLs
Splits
Documents
PDF
Vector
Store
DB
…
on this model. The Toyota Camry has a head-snapping
80 HP and an eight-speed automatic transmission that will
…
Chunk 1: on this model. The Toyota Camry has a head-snapping
Chunk 2: 80 HP and an eight-speed automatic transmission that will
chunk_size
chunk_overlap
Types of splitters
langchain.text_splitter.
● CharacterTextSplitter()- Implementation of splitting text that
looks at characters.
● MarkdownHeaderTextSplitter() - Implementation of splitting
markdown files based on specified headers.
● TokenTextSplitter() - Implementation of splitting text that looks at
tokens.
● SentenceTransformersTokenTextSplitter() - Implementation of
splitting text that looks at tokens.
● RecursiveCharacterTextSplitter() - Implementation of splitting
text that looks at characters. Recursively tries to split by different
characters to find one that works.
● Language() – for CPP, Python, Ruby, Markdown etc
● NLTKTextSplitter() - Implementation of splitting text that looks at
sentences using NLTK (Natural Language Tool Kit)
● SpacyTextSplitter() - Implementation of splitting text that looks at
sentences using Spacy
LangChain
Chat with your data
URLs
Splits
Documents
PDF
Vector
Store
DB
Embeddings
[-0.003530, -0.310379, …,
My dog… 0.005863 ]
Very similar
[-0.003540, -0.010369, …,
Fluffy, my… 0.005265 ]
Not similar
[-0.603530, -0.040329, …,
The Chevy… 0.7058633 ]
compare
Vector Store
create
Vector Store
splits embed
embedding original
vector spits
index
index
[-0.003530, -0.0109, …,
0.00633]
[-0.003530, -0.8187, …,
0.09633]
query
[-0.472409, -0.4287, …,
0.09731]
LLM
Retrieval
Retrieval
Storage Retrieval Output
…
Retrieval
Prompt
Self-query
Information Question Information: Query format
LLM
Query: Question
Query Filter: eq[“section”, “testing”]
Store
Relevant
splits
LLM Aided Retrieval
● There are several situations where the Query
applied to the DB is more than just the
Question asked.
● One is SelfQuery, where we use an LLM to
convert the user question into a query
Query Parser
Question
Store
Relevant
splits
Compression LLM
Compressed
Relevant
splits
LLM
LangChain
Chat with your data
Question Answering
Question Answering
Store
System: Human:
Docs and original
Prompt Question question are sent to an
LLM
LLM
Answer
Retrieval Chain with LLM
selection
RetrievalQA.from_chain_type(, chain_type=“map_reduce",…)
Question
You many have too
many docs to fit into an
Retriever LLM context. The solution
is to use an LLM to select
Relevant the ‘most relevant’
splits information
map-reduce LLM
System: Human:
Prompt Question
LLM
Answer
3 additional methods
1. Map_reduce
LLM
chunks LLM
2. Refine
chunks LLM’s
3. Map_rerank 40
91
Select highest score
33
chunks LLM
LangChain for LLM
Application Development
Agents
Agents