कोड फ़ाइलें लोड करना और विभाजित करना

LangChain के साथ Retrieval Augmented Generation (RAG)

Meri Nova

Machine Learning Engineer

और डॉक्यूमेंट लोडर्स...

विभिन्न फ़ाइल फ़ॉर्मैट्स का चयन.

LangChain के साथ Retrieval Augmented Generation (RAG)

LangChain के GitHub रिपॉज़िटरी में README फ़ाइल बनाने के लिए उपयोग किया गया रॉ मार्कडाउन.

LangChain के साथ Retrieval Augmented Generation (RAG)

LangChain की GitHub README.md फ़ाइल से रेंडर किया गया मार्कडाउन.

LangChain के साथ Retrieval Augmented Generation (RAG)

Markdown फ़ाइलें (.md) लोड करना

from langchain_community.document_loaders import UnstructuredMarkdownLoader

loader = UnstructuredMarkdownLoader("README.md")
markdown_content = loader.load() print(markdown_content[0])
Document(page_content='# Discord Text Classification ![Python Version](https...'
         metadata={'source': 'README.md'})
LangChain के साथ Retrieval Augmented Generation (RAG)

Python फ़ाइलें (.py) लोड करना

from abc import ABC, abstractmethod

class LLM(ABC):
  @abstractmethod
  def complete_sentence(self, prompt):
    pass

...
  • RAG एप्लिकेशन में कोड लिखने/ठीक करने, डॉक बनाने आदि में इंटिग्रेटेड.
  • Imports, classes, functions, आदि.
from langchain_community.document_loaders \
    import PythonLoader

loader = PythonLoader('chatbot.py')

python_data = loader.load() print(python_data[0])
Document(page_content='from abc import ABC, ...

class LLM(ABC):
  @abstractmethod
...',
metadata={'source': 'chatbot.py'})
LangChain के साथ Retrieval Augmented Generation (RAG)

कोड फ़ाइलें विभाजित करना

python_splitter = RecursiveCharacterTextSplitter(
    chunk_size=150, chunk_overlap=10
)

chunks = python_splitter.split_documents(python_data) for i, chunk in enumerate(chunks[:3]): print(f"Chunk {i+1}:\n{chunk.page_content}\n")
LangChain के साथ Retrieval Augmented Generation (RAG)
Chunk 1:
from abc import ABC, abstractmethod

class LLM(ABC):
  @abstractmethod
  def complete_sentence(self, prompt):
    pass

Chunk 2:
class OpenAI(LLM):
  def complete_sentence(self, prompt):
    return prompt + " ... OpenAI end of sentence."

class Anthropic(LLM):

Chunk 3:
def complete_sentence(self, prompt):
    return prompt + " ... Anthropic end of sentence."

LangChain के साथ Retrieval Augmented Generation (RAG)

भाषा के आधार पर विभाजन

  • separators
    • ["\n\n", "\n", " ", ""]
    • ["\nclass ", "\ndef ", "\n\tdef ", "\n\n", " ", ""]
from langchain_text_splitters import RecursiveCharacterTextSplitter, Language

python_splitter = RecursiveCharacterTextSplitter.from_language(

language=Language.PYTHON, chunk_size=150, chunk_overlap=10
)
chunks = python_splitter.split_documents(data)
for i, chunk in enumerate(chunks[:3]): print(f"Chunk {i+1}:\n{chunk.page_content}\n")
LangChain के साथ Retrieval Augmented Generation (RAG)
Chunk 1:
from abc import ABC, abstractmethod

Chunk 2:
class LLM(ABC):
  @abstractmethod
  def complete_sentence(self, prompt):
    pass

Chunk 3:
class OpenAI(LLM):
  def complete_sentence(self, prompt):
LangChain के साथ Retrieval Augmented Generation (RAG)

अभ्यास करते हैं!

LangChain के साथ Retrieval Augmented Generation (RAG)

Preparing Video For Download...