1. Learn
  2. /
  3. Courses
  4. /
  5. Retrieval Augmented Generation (RAG) with LangChain

Connected

Exercise

Splitting Python files

Although text and code files contain the same characters, code files contain structures beyond natural language. To retain this code-specific context during document splitting, you should program the splitter to first try to split on the most common code structure. Fortunately, LangChain provides functionality to do just that!

All of the necessary classes have been imported for you, including Language from langchain_text_splitters.

Instructions

100 XP
  • Create a recursive character splitter that will split on common Python code structures.
  • Split the python_data document loader into chunks.