Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DWX 2024 - Advanced RAG

DWX 2024 - Advanced RAG

Slides for my talk at DWX 2024 about Advanced RAG

Avatar for Sebastian Gingter

Sebastian Gingter

July 03, 2024
Tweet

More Decks by Sebastian Gingter

Other Decks in Programming

Transcript

  1. ▪ Was Sie ▪ Hintergrundwissen und Theorie zu RAG ▪

    Überblick über ▪ die auftreten können ▪ Pragmatische Methoden für die Verwendung im RAG ▪ Demos ( ) ▪ Was Sie erwartet ▪ ChatGPT, CoPilot(s) ▪ Grundlagen von ML ▪ Deep Dives in LLMs, Vektor-Datenbanken, LangChain Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 2
  2. ▪ Generative AI in business settings ▪ Flexible and scalable

    backends ▪ All things .NET ▪ Pragmatic end-to-end architectures ▪ Developer productivity ▪ Software quality [email protected] @phoenixhawk https://www.thinktecture.com Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! Developer Consultant @ Thinktecture AG 3
  3. 4 ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪

    Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 4
  4. 5 ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ Real-World

    Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 5
  5. 6 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 6
  6. Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"!

    Indexing & (Semantic) search Cleanup & Split Text Embedding Question Text Embedding Save Query Relevant Text Question LLM 8 Vector DB Embedding model Embedding model Indexing / Embedding QA
  7. 9 ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪

    ▪ Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 9
  8. 10 ▪ ▪ ▪ ▪ ▪ ➔ Real-World Chat mit

    Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 10
  9. 11 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 11
  10. 13 ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ Real-World

    Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 13
  11. 14 ▪ ▪ ▪ ▪ ▪ Real-World Chat mit Unternehmensdaten:

    Advanced RAG jenseits von "Hallo Welt"! 14
  12. 15 ▪ ▪ Ԧ 𝑎 = 𝑎𝑥 𝑎𝑦 Real-World Chat

    mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 15
  13. 18 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Ԧ 𝑎 = 𝑎𝑢 𝑎𝑣 𝑎𝑤 𝑎𝑥 𝑎𝑦 𝑎𝑧 18
  14. 20 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 − 𝑀𝑎𝑛 + 𝑊𝑜𝑚𝑎𝑛 ≈ 𝑆𝑖𝑠𝑡𝑒𝑟 Real-World Chat

    mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! Man Woman Brother Sister https://arxiv.org/abs/1301.3781 20
  15. 23 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! [ 0.50451 , 0.68607 , -0.59517 , -0.022801, 0.60046 , -0.13498 , -0.08813 , 0.47377 , -0.61798 , -0.31012 , -0.076666, 1.493 , -0.034189, -0.98173 , 0.68229 , 0.81722 , -0.51874 , -0.31503 , -0.55809 , 0.66421 , 0.1961 , -0.13495 , -0.11476 , -0.30344 , 0.41177 , -2.223 , -1.0756 , -1.0783 , -0.34354 , 0.33505 , 1.9927 , -0.04234 , -0.64319 , 0.71125 , 0.49159 , 0.16754 , 0.34344 , -0.25663 , -0.8523 , 0.1661 , 0.40102 , 1.1685 , -1.0137 , -0.21585 , -0.15155 , 0.78321 , -0.91241 , -1.6106 , -0.64426 , -0.51042 ] 23 http://jalammar.github.io/illustrated-word2vec/
  16. 25 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! http://jalammar.github.io/illustrated-word2vec/ 25
  17. 26 ▪ ▪ ▪ ▪ ▪ Real-World Chat mit Unternehmensdaten:

    Advanced RAG jenseits von "Hallo Welt"! 26
  18. 29 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 29
  19. 30 ▪ ▪ ▪ ▪ ▪ Real-World Chat mit Unternehmensdaten:

    Advanced RAG jenseits von "Hallo Welt"! 30
  20. ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪

    ▪ ▪ ▪ Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! Vector-Databases ▪ 31
  21. 32 ▪ ▪ 𝑆𝐶(a,b) = a ∙𝑏 𝑎 × 𝑏

    ▪ ▪ ▪ ~ ▪ ∞ ▪ ▪ ▪ ▪ Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 32
  22. 34 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 34
  23. 35 ▪ ▪ ▪ ▪ ▪ Real-World Chat mit Unternehmensdaten:

    Advanced RAG jenseits von "Hallo Welt"! 35
  24. 36 ▪ Import documents from different sources, in different formats

    ▪ LangChain has very strong support for loading data ▪ Support for cleanup ▪ Support for splitting Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 36 https://python.langchain.com/docs/integrations/document_loaders
  25. 37 ▪ HTML Tags ▪ Formatting information ▪ Normalization ▪

    lowercasing ▪ stemming, lemmatization ▪ remove punctuation & stop words ▪ Enrichment ▪ tagging ▪ keywords, categories ▪ metadata Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 37
  26. 38 ▪ Document is too large / too much content

    / not concise enough Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! ▪ by size (text length) ▪ by character (\n\n) ▪ by paragraph, sentence, words (until small enough) ▪ by size (tokens) ▪ overlapping chunks (token-wise) ▪ by semantics (semantic chunker) 38
  27. 40 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 40
  28. 41 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! 𝑎 𝑏 𝑐 … “What is the name of the teacher?” Doc. 1: 0.86 Doc. 2: 0.84 Doc. 3: 0.79 … (Answer generation) 41
  29. LangChain, Chroma, local embedding model, OpenAI GPT Real-World Chat mit

    Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 42
  30. 43 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 43
  31. 46 ▪ Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von

    "Hallo Welt"! LLM, e.g. GPT-3.5-turbo Embedding 𝑎 𝑏 𝑐 … Vector- Database Doc. 3: 0.86 Doc. 2: 0.81 Doc. 1: 0.81 Weighted result Hypothetical Document Embedding- Model Write a company policy that contains all information which will answer the given question: {QUERY} “What should I do, if I missed the last train?” https://arxiv.org/abs/2212.10496 46
  32. 47 ▪ ▪ ▪ ▪ ▪ ▪ ▪ Real-World Chat

    mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 47
  33. 48 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Write 3 questions, which are answered by the following document. 𝑎 𝑏 𝑐 … 48
  34. 49 ▪ Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von

    "Hallo Welt"! 𝑎 𝑏 𝑐 … Doc. 3: 0.89 Doc. 1: 0.86 Doc. 2: 0.76 “What should I do, if I missed the last train?” 49
  35. 51 ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪

    ▪ ▪ Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"! 51
  36. 52 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! Introduction Embeddings Vector-DBs Indexing Retrieval Indexing II RAG 52
  37. 53 Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo

    Welt"! 𝑎 𝑏 𝑐 … “You can get a hotel room or take a cab. € 200 to € 300 might still be okay to get you to your destination. Please make sure to ask the cab driver for a fixed fee upfront.” Answer the user’s question. Relevant document: {SearchResult} Question: {Query} “What should I do, if I missed the last train?” 53
  38. Real-World Chat mit Unternehmensdaten: Advanced RAG jenseits von "Hallo Welt"!

    Indexing & (Semantic) search Cleanup & Split Text Embedding Question Text Embedding Save Query Relevant Text Question LLM 54 Vector DB Embedding model Embedding model Indexing / Embedding QA