Ch 5 — RAG Under the Hood
Inside text splitters, embedding math, FAISS indexes, retriever internals, and the LCEL RAG pipeline
Under the Hood
-
Click play or press Space to begin...
AText Splitter InternalsHow RecursiveCharacterTextSplitter actually splits
1description
Raw TextFull document
as a string
split at
list
Separators\n\n → \n → . → " "
recursive fallback
merge
2view_column
Chunkschunk_size limit
+ overlap window
3arrow_downward Embedding model internals: text → dense vector
BEmbedding Model InternalsTokenize → transformer → pool → normalize
text_fields
Input Text"refund policy
for customers"
tokenize
data_array
Token IDs[8134, 4813,
369, 6890]
encode
neurology
TransformerContextual token
representations
pool
4scatter_plot
Dense Vector1536-d normalized
unit vector
5arrow_downward Vector store internals: FAISS index structure
CVector Store & FAISS InternalsHow vectors are indexed and searched efficiently
scatter_plot
VectorsN vectors ×
1536 dimensions
index
account_tree
FAISS IndexIndexFlatIP or
IndexIVFFlat
search
6sort
Top-k ResultsDistances + indices
→ Document objects
7arrow_downward Retriever as a Runnable: the VectorStoreRetriever class
DRetriever Runnable InternalsVectorStoreRetriever wraps the store as a Runnable
text_fields
Query String"refund policy"
raw user input
.invoke()
manage_search
Retriever_get_relevant_
documents()
delegates
database
Vector Storesimilarity_search
(query, k=4)
returns
article
List[Document]page_content +
metadata
8arrow_downward LCEL RAG chain: RunnableParallel and data flow
ELCEL RAG Chain InternalsRunnableParallel branches, then sequential pipeline
call_split
RunnableParallelcontext + question
run concurrently
merge
data_object
Dict Output{context: str,
question: str}
pipe
9linear_scale
Sequentialprompt → model
→ parser
10arrow_downward Advanced: MMR, cross-encoder reranking, parent document retriever
FAdvanced Retrieval InternalsMMR diversity, cross-encoder scoring, parent-child chunks
hub
MMRRelevance minus
redundancy score
+
compare_arrows
Cross-Encoder[query, doc] →
single score
+
account_tree
Parent DocSmall chunks search
→ return full parent