LangChain / RAG / Vector DBs · 강의

문서 메타데이터 처리와 필터링

문서 메타데이터를 추가하고 보강하고 필터링해 RAG 처리 흐름의 검색 범위를 올바른 출처로 제한하는 방법을 학습해 보세요.

레슨 4/413개 단계

문서 메타데이터 처리와 필터링은(는) CoddyKit의 무료 LangChain / RAG / Vector DBs 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 LangChain / RAG / Vector DBs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Metadata Matters

Every document chunk in LangChain carries a page_content string and a metadata dictionary. While the content feeds the embedding model, metadata drives filtering, attribution, and traceability.

  • Source file or URL
  • Page number or section
  • Author, date, language

The Document Object

A LangChain Document is a lightweight container. You can construct one directly and pass any JSON-serializable values in metadata.

from langchain_core.documents import Document

doc = Document(
    page_content="Annual revenue grew 12%.",
    metadata={"source": "report.pdf", "page": 4, "year": 2025}
)
print(doc.metadata["source"])

Automatic Metadata from Loaders

Most loaders inject metadata for free. A PyPDFLoader adds source and page, while a WebBaseLoader adds the URL and page title.

from langchain_community.document_loaders import PyPDFLoader

loader = PyPDFLoader("handbook.pdf")
pages = loader.load()
print(pages[0].metadata)
# {"source": "handbook.pdf", "page": 0}

Enriching Metadata After Load

You often need to add fields the loader does not know about, like a category or tenant id. Iterate and mutate the dictionary.

for d in pages:
    d.metadata["department"] = "finance"
    d.metadata["sensitive"] = False
print(pages[0].metadata["department"])

Metadata Survives Splitting

When you split documents, the splitter copies the parent metadata onto each child chunk. This means filters set before splitting still apply afterward.

from langchain_text_splitters import RecursiveCharacterTextSplitter

splitter = RecursiveCharacterTextSplitter(chunk_size=200)
chunks = splitter.split_documents(pages)
print(chunks[0].metadata["source"])

Filtering at Retrieval Time

Vector stores accept a filter argument so you only search the relevant slice. This is faster and reduces irrelevant matches.

results = vectorstore.similarity_search(
    "vacation policy",
    k=3,
    filter={"department": "hr"}
)

Self-Query Retrieval

A SelfQueryRetriever lets the LLM translate a natural-language query into both a semantic search and a metadata filter automatically.

You describe the metadata schema once, and the model decides when to filter.

Cleaning Noisy Metadata

Loaders sometimes produce verbose or nested metadata that vector stores reject. Flatten or whitelist the keys you need.

def clean(d):
    keep = {"source", "page", "department"}
    d.metadata = {k: v for k, v in d.metadata.items() if k in keep}
    return d

cleaned = [clean(d) for d in chunks]

Metadata for Citations

Storing the source and page lets you cite where an answer came from. After retrieval, format the metadata into a human-readable reference.

for r in results:
    src = r.metadata["source"]
    pg = r.metadata.get("page", "?")
    print(f"[{src} p.{pg}]")

Type Constraints

Many vector databases only allow scalar metadata values: strings, numbers, and booleans. Lists or dicts must be serialized to JSON strings or removed.

  • Good: {"page": 4}
  • Reject: {"tags": ["a","b"]}

A Practical Filter Pipeline

Combine enrichment, cleaning, and filtered search into one flow so every query is scoped to the correct subset of your corpus.

docs = PyPDFLoader("policy.pdf").load()
for d in docs:
    d.metadata["region"] = "EU"
chunks = splitter.split_documents(docs)
# index chunks, then:
vectorstore.similarity_search("data retention", filter={"region": "EU"})

Quick Check

Test your understanding of metadata handling.

Recap

You learned to work with document metadata:

  • Loaders auto-add fields like source and page
  • Enrich and clean metadata for filtering and citations
  • Metadata propagates through splitting
  • Use filter or a self-query retriever to scope searches
무료로 시작

AI 튜터와 함께 LangChain / RAG / Vector DBs을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“문서 메타데이터 처리와 필터링” 강의는 무료인가요?

네 — “문서 메타데이터 처리와 필터링” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 LangChain / RAG / Vector DBs 강의 전체를 잠금 해제할 수 있습니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.

“문서 메타데이터 처리와 필터링”에서 뭘 배우나요?

문서 메타데이터를 추가하고 보강하고 필터링해 RAG 처리 흐름의 검색 범위를 올바른 출처로 제한하는 방법을 학습해 보세요. 브라우저에서 직접 실행하는 실습 코드로 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 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 다양한 문서 유형 로딩
  2. 텍스트 분할 전략 이해
  3. 문서 분할 사용자 지정
  4. 문서 메타데이터 처리와 필터링
← LangChain / RAG / Vector DBs(으)로 돌아가기