LangChain From 0 To 1 Public 1 PpuSgEN
LangChain From 0 To 1 Public 1 PpuSgEN
https://github.com/Stell0/fosdem2024
- Presentation
- Code
- Useful links
Our Journey
1. Introduction to LangChain
2. Document loaders
3. Text Splitters
4. Embeddings
5. Vectorstores
6. Retrievers
7. Prompts and Templates
8. Large Language Models
9. Chains
10. RAG - Retrieval Augmented Generation
11. Demo
Retrieval Augmented Generation (RAG) 🔥🔥🔥
data
Answer
~~~
~~~~~~
~~~~~~ LLM
~~~
Question
Example of RAG use case: QA over unstructured data
~~
~~~
~~~
~~~~~~
~~~
~~~
~~~
[0.2, 0.3, 2.1, 0.2, …]
~~~~ ~~~~~~
YouTube ~~~~~~
transcript ~~~
video
~~ ~~~
~~~
~~~
~~~
[1.2, 4.7, 0.1, 0.1, …]
~ ~~~ ~~~
Prompt Answer
[0.9, 1.2, 2.1, 1.1, …]
~~~
~~~~~~ Template LLM
~~~~~~
~~~
Instructions
+
Question {Context}
+
{Question}
LangChain
~~~
~~~
~~~ [0.2, 0.3, 2.1, 0.2, …] [0.2, 0.3, 2.1, 0.2, …]
~~~
HTML ~~~
PDF ~~~ [1.2, 4.7, 0.1, 0.1, …]
[0.9, 1.2, 2.1, 1.1, …]
JSON ~~~
~~~ [1.2, 4.7, 0.1, 0.1, …]
TXT
~~~
[0.4, 0.4, 1.5, 0.6, …]
…
~~~
~~~
~~~
~~~
~~~
~~~ ~~~
~~~ [0.9, 1.2, 2.1, 1.1, …]
~~~
~~~ ~~~
~~~ ~~~
~~~ ~~~
~~~
~~~
~~~
~~~
~~~
~~~
~~~ [0.4, 0.4, 1.5, 0.6, …]
~~~
~~~
Document Loaders
Microsoft Word
MongoDB
Open Document Format (ODT)
Arxiv Pandas DataFrame
CSV PubMed
Discord ReadTheDocs Documentation
HTML
PDF Email Reddit
EPub RSS Feeds
JSON EverNote Slack
TXT Facebook Chat Snowflake
… Figma Telegram
Git X
GitHub URL
HTML WhatsApp Chat
JSON Wikipedia
~~~
~~~ Markdown XML
~~~ Mastodon YouTube audio
MediaWiki Dump YouTube transcripts
Document Loaders
~~~
~~~
~~~
~~~
~~~
~~~
~~~
~~~
~~~
~~~ ~~~
~~~ ~~~
~~~ ~~~
~~~
~~~
~~~
https://chunkviz.up.railway.app
Characters / Tokens
of text splitting
Document structure
Semantic Chunker
Agent-like Splitting
Text Splitters
RecursiveCharacterTextSplitter
Embeddings
- Numerical representation
- Vectors in High-dimensional space
- Each dimension reflects an aspect
- Similarity = Proximity in embedding space ~~~
~~~ [0.2, 0.3, 2.1, 0.2, …]
~~~
~~~
~~~ [1.2, 4.7, 0.1, 0.1, …]
~~~
~~~
~~~ [0.9, 1.2, 2.1, 1.1, …]
~~~
~~~
~~~ [0.4, 0.4, 1.5, 0.6, …]
~~~
Embeddings
- Complexity is hidden
- We rely on an external provider
- note: data is sent to the external provider
Vectorstore
Storing embeddings
- Stores
- Search [0.2, 0.3, 2.1, 0.2, …]
- Retrieve
[1.2, 4.7, 0.1, 0.1, …]
[0.9, 1.2, 2.1, 1.1, …]
[0.4, 0.4, 1.5, 0.6, …]
Vectorstore
https://blog.langchain.dev/langchain-state-of-ai-2023/
Using data
Prompt Answer
[0.9, 1.2, 2.1, 1.1, …]
~~~
~~~~~~ Template LLM
~~~~~~
~~~
Instructions
+
Question {Context}
+
{Question}
Retriever Prompt/Template LLM Chain
{
T }
~~~ ~~~
~~~ ~~~
~~~ ~~~
~~~
~~~
~~~
~~~~
~
Retriever
Relevant Documents
~~~ ~~~
~~~ ~~~
~~~ ~~~
~~~
~~~
~~~
Retriever
Another Retriever
{
Question
T }
+
Documents
⬇
~~~~
~
context
Prompt
Prompt from Hub
LLM
https://python.langchain.com/docs/integrations/llms/
LLM
“Nobody Gets Fired For Buying
IBM OpenAI”
Most Used LLM Providers
https://blog.langchain.dev/langchain-state-of-ai-2023/
Most Used OSS Model Providers
https://blog.langchain.dev/langchain-state-of-ai-2023/
Put everything together
Chains
Sequence of calls
- Advantages:
- Simple
- Modular
- Efficient
- compose your own
- Off-the-shelf
- Legacy Class
- LCEL
- Streaming
- Async (and sync) support
- Optimized parallel execution
- integrated with LangSmith and LangServe
- …
Put everything together using LCEL
Other use cases