Turning documents into nodes in LlamaIndex
Understanding the first step of LlamaIndex indexing before embedding.
Goal: Preparing text for retrieval with overlapping chunks.
from langchain_text_splitters import RecursiveCharacterTextSplitter
text = ("مكتبة MONAI مخصصة للصور الطبية. توفر تحويلات ثلاثية الأبعاد وشبكات جاهزة.\n\n"
"مكتبة SimpleITK تقرأ صيغ DICOM وNIfTI. وتدعم إعادة المعاينة والتسجيل.\n\n"
"مكتبة TorchIO تقدم زيادة بيانات واقعية لصور الرنين المغناطيسي.")
splitter = RecursiveCharacterTextSplitter(chunk_size=80, chunk_overlap=15)
chunks = splitter.split_text(text)
print("Number of chunks:", len(chunks))
for i, c in enumerate(chunks, 1):
print(i, len(c), c.replace("\n", " "))
RecursiveCharacterTextSplitter tries to cut at paragraphs, then sentences, then words so as not to exceed chunk_size, with a chunk_overlap to keep context between chunks. Chunk size is one of the most important parameters of RAG quality.
Number of chunks: 3 1 73 مكتبة MONAI مخصصة للصور الطبية. توفر تحويلات ثلاثية الأبعاد وشبكات جاهزة. 2 69 مكتبة SimpleITK تقرأ صيغ DICOM وNIfTI. وتدعم إعادة المعاينة والتسجيل. 3 62 مكتبة TorchIO تقدم زيادة بيانات واقعية لصور الرنين المغناطيسي.
This example was actually run and tested on 21 November 2026 on a CPU — langchain-text-splitters 1.1.3, python 3.13.18
Understanding the first step of LlamaIndex indexing before embedding.
Building the retrieval stage of RAG and running it locally.
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the AI Frameworks & Libraries Assistant. Describe your project or ask me about a library, a comparison or a code example, and I will answer from the encyclopedia's database with links and sources.
Answers from the encyclopedia's database only, without a language model and without sending your question to any third party.
The assistant can make mistakes, so check the attached sources.