0Pricing
AI Agents with LangChain & Autonomous Workflows · Ders

Metin Bölücüler ve Gömüler

Büyük belgeleri yönetilebilir parçalara ayırma ve anlamsal arama için sayısal gömmeler oluşturma tekniklerinde uzmanlaşın.

Metin Bölücüler ve Gömüler, CoddyKit'te ücretsiz bir AI Agents with LangChain & Autonomous Workflows dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, AI Agents with LangChain & Autonomous Workflows öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. AI Agents with LangChain & Autonomous Workflows kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Split & Embed Text?

When working with large documents, directly feeding them to a Large Language Model (LLM) often causes problems. LLMs have strict input limits, known as context windows.

This lesson teaches you how to prepare large texts for LLMs using two key techniques: text splitting and embeddings. These are essential for building advanced AI agents.

The Problem: Long Documents

Imagine you have a 100-page PDF document. If you try to ask an LLM a question about it, you can't just send the whole document.

  • Context Window Limits: LLMs can only process a certain amount of text at once (e.g., 4,000 to 128,000 tokens).
  • Cost: Longer inputs mean higher API costs.
  • Relevance: Filling the context window with irrelevant information can make the LLM 'forget' the important parts.

Text splitting solves this by breaking documents into smaller, manageable chunks.

Introducing Text Splitters

LangChain provides various text splitters to divide documents efficiently. Their goal is to keep semantically related pieces of text together while respecting size limits.

Instead of just cutting at arbitrary character counts, smart splitters try to break text at logical points, like paragraphs or sentences.

A common and versatile splitter is the RecursiveCharacterTextSplitter.

Recursive Character Text Splitter

The RecursiveCharacterTextSplitter is a powerful tool. It attempts to split text using a list of characters, trying them in order until the chunks are small enough.

  • It starts by trying to split by \n\n (double newline for paragraphs).
  • If chunks are still too big, it tries \n (single newline for lines).
  • Then spaces, and finally individual characters.

This recursive approach helps maintain semantic coherence.

Code: Basic Splitting Demo

Let's see how RecursiveCharacterTextSplitter works. We'll split a short story into chunks.

from langchain_text_splitters import RecursiveCharacterTextSplitter

story = (
    "Alice was beginning to get very tired of sitting by her sister on the bank, "
    "and of having nothing to do: once or twice she had peeped into the book her "
    "sister was reading, but it had no pictures or conversations in it, 'and what "
    "is the use of a book,' thought Alice 'without pictures or conversation?'"
    "So she was considering in her own mind (as well as she could, for the hot "
    "day made her feel very sleepy and stupid), whether the pleasure of making "
    "a daisy-chain would be worth the trouble of getting up and picking the "
    "daisies, when suddenly a White Rabbit with pink eyes ran close by her."
)

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=100,
    chunk_overlap=0
)

chunks = text_splitter.split_text(story)

for i, chunk in enumerate(chunks):
    print(f"Chunk {i+1}: {chunk}\n")

Chunk Size & Overlap Explained

Two crucial parameters for text splitting are chunk_size and chunk_overlap:

  • Chunk Size: This is the maximum number of characters (or tokens, depending on the splitter) in each chunk. Choose a size that fits within your LLM's context window.
  • Chunk Overlap: This specifies how many characters (or tokens) should overlap between consecutive chunks. Overlap helps preserve context across splits, ensuring that important information isn't lost at chunk boundaries.

Finding the right balance for these parameters is key to effective retrieval.

Code: Splitting with Overlap

Let's modify our previous example to use a chunk_overlap. Notice how parts of the text are repeated in adjacent chunks, providing continuity.

from langchain_text_splitters import RecursiveCharacterTextSplitter

story = (
    "Alice was beginning to get very tired of sitting by her sister on the bank, "
    "and of having nothing to do: once or twice she had peeped into the book her "
    "sister was reading, but it had no pictures or conversations in it, 'and what "
    "is the use of a book,' thought Alice 'without pictures or conversation?'"
    "So she was considering in her own mind (as well as she could, for the hot "
    "day made her feel very sleepy and stupid), whether the pleasure of making "
    "a daisy-chain would be worth the trouble of getting up and picking the "
    "daisies, when suddenly a White Rabbit with pink eyes ran close by her."
)

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=100,
    chunk_overlap=20 # Added overlap
)

chunks = text_splitter.split_text(story)

for i, chunk in enumerate(chunks):
    print(f"Chunk {i+1}: {chunk}\n")

What are Text Embeddings?

Once you've split your documents, how do you find the most relevant chunks for a user's query? This is where text embeddings come in.

  • An embedding is a numerical representation (a vector) of text.
  • Texts with similar meanings have embeddings that are 'closer' to each other in a high-dimensional space.
  • This allows us to perform semantic search: finding chunks that are conceptually similar to a query, not just keyword matches.

Embeddings are the backbone of Retrieval Augmented Generation (RAG).

Generating Embeddings with LangChain

LangChain makes it easy to generate embeddings using various models. You interact with an Embeddings object, which abstracts away the underlying model details.

Popular embedding models include those from OpenAI, Hugging Face, Cohere, and many open-source options like `all-MiniLM-L6-v2`.

You typically initialize an embedding model and then call its embed_query() for a single text or embed_documents() for a list of chunks.

Code: Creating Embeddings

Here's how to generate an embedding for a simple text using OpenAI's embedding model. Remember, you'll need an OpenAI API key for this to run successfully.

import os
# Set your OpenAI API key as an environment variable
# os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"

from langchain_openai import OpenAIEmbeddings

# Initialize the embedding model
# Requires OPENAI_API_KEY env var or direct pass
embeddings_model = OpenAIEmbeddings()

text_to_embed = "The quick brown fox jumps over the lazy dog."

# Generate the embedding vector
embedding_vector = embeddings_model.embed_query(text_to_embed)

print(f"Original Text: '{text_to_embed}'")
print(f"Embedding Vector (first 5 values): {embedding_vector[:5]}...")
print(f"Vector Dimension: {len(embedding_vector)}")

Quick Check: Splitting & Embeddings

Consider the following statements about text splitting and embeddings:

Recap: Splitting & Embedding for RAG

You've learned two fundamental techniques for handling large documents in AI agents:

  • Text Splitting: Breaking large texts into smaller, manageable chunks using tools like RecursiveCharacterTextSplitter, controlled by chunk_size and chunk_overlap.
  • Embeddings: Converting text chunks into numerical vectors using embedding models (e.g., OpenAIEmbeddings) to enable semantic similarity search.

These techniques are crucial for building effective Retrieval Augmented Generation (RAG) systems, allowing your agents to intelligently find and use relevant information from vast knowledge bases.

Sıkça Sorulan Sorular

“Metin Bölücüler ve Gömüler” dersi ücretsiz mi?

Evet — “Metin Bölücüler ve Gömüler” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve AI Agents with LangChain & Autonomous Workflows kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. AI Agents with LangChain & Autonomous Workflows kursu toplamda 4 dersten oluşur.

“Metin Bölücüler ve Gömüler” dersinde ne öğreneceğim?

Büyük belgeleri yönetilebilir parçalara ayırma ve anlamsal arama için sayısal gömmeler oluşturma tekniklerinde uzmanlaşın. AI Agents with LangChain & Autonomous Workflows ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

AI Agents with LangChain & Autonomous Workflows öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te AI Agents with LangChain & Autonomous Workflows, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Metin Bölücüler ve Gömüler” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu AI Agents with LangChain & Autonomous Workflows dersinde kod yazıp çalıştırabilir miyim?

Evet. Her AI Agents with LangChain & Autonomous Workflows dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Belge Yükleyicileri Açıklaması
  2. Metin Bölücüler ve Gömüler
  3. Getirme için Vektör Depoları
  4. Getiriciler ve Bağlamsal Sıkıştırma
← AI Agents with LangChain & Autonomous Workflows Sayfasına Dön