상위 문서와 문장 창 검색
검색하는 청크와 반환하는 청크를 분리해 LLM이 풍부한 맥락과 함께 정확한 일치 결과를 얻도록 해 보세요.
상위 문서와 문장 창 검색은(는) CoddyKit의 무료 LangChain / RAG / Vector DBs 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 LangChain / RAG / Vector DBs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
The Chunk-Size Dilemma
Small chunks search precisely but lack context; large chunks give context but dilute relevance. Parent document retrieval resolves this tension by searching small and returning large.
Two Chunk Sizes
Index small child chunks for accurate similarity matching, but keep a link to the larger parent chunk that surrounds each one.
- Search on child embeddings
- Return parent text to the LLM
ParentDocumentRetriever
LangChain provides a ready-made retriever. You give it a child splitter, an optional parent splitter, a vector store, and a doc store for the parents.
from langchain.retrievers import ParentDocumentRetriever
retriever = ParentDocumentRetriever(
vectorstore=vectorstore,
docstore=store,
child_splitter=child_splitter,
parent_splitter=parent_splitter,
)Adding Documents
The retriever splits each document into parents and children, embeds the children, and stores parents keyed by id so they can be fetched on a hit.
retriever.add_documents(docs)
results = retriever.invoke("What is the refund window?")
print(len(results[0].page_content)) # large parent textSentence-Window Retrieval
A variant indexes single sentences but, on retrieval, expands each hit to include the surrounding sentences. The model sees the exact match plus neighbors.
Storing the Window
During indexing you save the neighboring text in metadata so it can be stitched back at query time.
doc.metadata["window"] = " ".join(
sentences[max(0, i-2): i+3]
)
doc.page_content = sentences[i]Swapping Content After Search
After similarity search returns the matched sentence, replace its content with the stored window before passing it to the LLM.
for r in results:
r.page_content = r.metadata["window"]When to Use Each
Parent document suits structured docs with natural sections. Sentence-window suits dense prose where precise sentences matter most.
Avoiding Duplicate Parents
Multiple child hits can map to the same parent. Deduplicate by parent id so the LLM is not handed the same passage twice.
seen = set()
unique = []
for d in results:
pid = d.metadata["parent_id"]
if pid not in seen:
seen.add(pid)
unique.append(d)Cost and Context Limits
Returning larger parents consumes more of the LLM context window. Balance the parent size against your token budget and the number of results k.
Putting It Together
Index fine-grained children, retrieve precisely, then expand to parents or windows. Your generation step receives focused yet contextual passages.
docs = retriever.invoke("cancellation terms")
context = "\n\n".join(d.page_content for d in docs)
answer = llm.invoke(f"Context:\n{context}\n\nQuestion: ...")Quick Check
Test your understanding of decoupled retrieval.
Recap
You learned to decouple search and return units:
- Parent document: search children, return parents
- Sentence-window: match sentences, expand to neighbors
- Deduplicate parents and watch context limits
자주 묻는 질문
“상위 문서와 문장 창 검색” 강의는 무료인가요?
네 — “상위 문서와 문장 창 검색” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 LangChain / RAG / Vector DBs 강의 전체를 잠금 해제할 수 있습니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.
“상위 문서와 문장 창 검색”에서 뭘 배우나요?
검색하는 청크와 반환하는 청크를 분리해 LLM이 풍부한 맥락과 함께 정확한 일치 결과를 얻도록 해 보세요. 브라우저에서 직접 실행하는 실습 코드로 LangChain / RAG / Vector DBs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
LangChain / RAG / Vector DBs을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 LangChain / RAG / Vector DBs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“상위 문서와 문장 창 검색” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 LangChain / RAG / Vector DBs 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 LangChain / RAG / Vector DBs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 다중 쿼리 검색 전략
- LLM을 활용한 컨텍스트 압축
- 하이브리드 검색과 재순위화
- 상위 문서와 문장 창 검색