Getiriciler ve Bağlamsal Sıkıştırma
Bir vektör deposunu ayarlanabilir bir getiriciye dönüştürün, dönecek belge sayısını denetleyin ve LLM'ye ulaşmadan önce ilgisiz metni ayıklamak için bağlamsal sıkıştırmayı kullanın.
Getiriciler ve Bağlamsal Sıkıştırma, CoddyKit'te ücretsiz bir AI Agents with LangChain & Autonomous Workflows dersidir. Bu, 4 dersinin 4. 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.
From Vector Store to Retriever
A vector store knows how to search, but agents talk to a retriever — a thin interface with one job: given a query, return relevant documents.
Any vector store exposes as_retriever() to produce one.
retriever = vectorstore.as_retriever()
docs = retriever.invoke('How do I reset my password?')Controlling k
The k parameter sets how many documents to return. Too few misses context; too many wastes tokens and adds noise.
retriever = vectorstore.as_retriever(
search_kwargs={'k': 4}
)Similarity Score Thresholds
Instead of a fixed count, you can return only documents above a relevance score. This avoids forcing irrelevant chunks when nothing good matches.
retriever = vectorstore.as_retriever(
search_type='similarity_score_threshold',
search_kwargs={'score_threshold': 0.7}
)Maximal Marginal Relevance
MMR balances relevance with diversity, avoiding near-duplicate chunks. It is great when documents repeat similar text.
retriever = vectorstore.as_retriever(
search_type='mmr',
search_kwargs={'k': 4, 'fetch_k': 20}
)Metadata Filtering
Documents carry metadata (source, date, category). You can filter retrieval to a subset, e.g. only the current product version.
retriever = vectorstore.as_retriever(
search_kwargs={'filter': {'version': 'v2'}}
)The Noise Problem
Even relevant chunks often contain unrelated sentences. Sending that noise to the LLM dilutes the answer and burns tokens.
Contextual compression shrinks each retrieved document to only the parts that matter for the query.
ContextualCompressionRetriever
This wrapper sits in front of a base retriever and post-processes its results with a compressor.
from langchain.retrievers import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import LLMChainExtractor
compressor = LLMChainExtractor.from_llm(llm)
compression_retriever = ContextualCompressionRetriever(
base_compressor=compressor,
base_retriever=retriever
)How Extraction Works
LLMChainExtractor asks the LLM to pull only the sentences from each document that are relevant to the query, discarding the rest before it reaches the final prompt.
docs = compression_retriever.invoke(
'What is the refund window?'
)Cheaper Filters
LLM extraction costs tokens. EmbeddingsFilter is a faster, cheaper alternative that drops documents below a similarity threshold using embeddings only — no extra LLM call.
from langchain.retrievers.document_compressors import EmbeddingsFilter
compressor = EmbeddingsFilter(
embeddings=embeddings,
similarity_threshold=0.76
)Chaining Compressors
Combine steps in a DocumentCompressorPipeline: first a cheap embeddings filter, then LLM extraction on what survives. This keeps quality high while controlling cost.
from langchain.retrievers.document_compressors import DocumentCompressorPipeline
pipeline = DocumentCompressorPipeline(
transformers=[embeddings_filter, extractor]
)Plugging Into RAG
Because a compression retriever has the same interface as any retriever, you swap it into your RAG chain without changing the rest of the pipeline. Cleaner context usually means better, cheaper answers.
Quick Check
Test your retriever knowledge.
Recap
You learned to tune and refine retrieval:
- Convert a store with
as_retriever()and tunek - Use score thresholds, MMR, and metadata filters
- Contextual compression removes noisy text
EmbeddingsFilteris a cheap alternative to LLM extraction- Chain compressors for quality plus efficiency
Better retrieval is often the biggest lever for RAG quality.
Yapay zeka eğitmeniyle AI Agents with LangChain & Autonomous Workflows öğren — ücretsiz
Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.
- Kurslar
- 12
- Dersler
- 50
Sıkça Sorulan Sorular
“Getiriciler ve Bağlamsal Sıkıştırma” dersi ücretsiz mi?
Evet — “Getiriciler ve Bağlamsal Sıkıştırma” 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.
“Getiriciler ve Bağlamsal Sıkıştırma” dersinde ne öğreneceğim?
Bir vektör deposunu ayarlanabilir bir getiriciye dönüştürün, dönecek belge sayısını denetleyin ve LLM'ye ulaşmadan önce ilgisiz metni ayıklamak için bağlamsal sıkıştırmayı kullanı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 4. dersidir.
“Getiriciler ve Bağlamsal Sıkıştırma” 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
- Belge Yükleyicileri Açıklaması
- Metin Bölücüler ve Gömüler
- Getirme için Vektör Depoları
- Getiriciler ve Bağlamsal Sıkıştırma