12 - embeddings, vector search and RAG

pipeline

  • chunk > embed > index > retrieve > augment > generate

embedding

  • a high-dimensional vector that capture the meaning of words, sentences, or chunks of texts so a computer can process them mathematically

textembeddingvRn cosθ=ab|a||b|
chunk overlap

Chunk 1:
A B C D E

Chunk 2:
      D E F G H

Chunk 3:
            G H I J K
retrieval-augmented generation (RAG)

  • retrieval: find relevant information
  • augmented: add that information to the model's context
  • generation have the LLM produce and answer using that context

 OFFLINE

Documents
   ↓
Chunk
   ↓
Embed
   ↓
Index
   │
   │
   │             ONLINE
   │
   │        User question
   │              ↓
   │            Embed
   │              ↓
   └───► Search
		  ↓
	relevant chunks
		  ↓
    question + chunks
		  ↓
		 LLM
		  ↓
		answer