반응형
from langchain.document_loaders import TextLoader, CSVLoader, PyPDFLoader, DirectoryLoader, WikipediaLoader
# 텍스트 파일 로딩
text_loader = TextLoader("example.txt")
documents = text_loader.load()
# CSV 파일 로딩
csv_loader = CSVLoader(file_path="data.csv")
documents = csv_loader.load()
# PDF 파일 로딩
pdf_loader = PyPDFLoader("report.pdf")
documents = pdf_loader.load()
# 디렉토리 내 모든 파일 로딩
dir_loader = DirectoryLoader("docs/")
documents = dir_loader.load()
# 위키피디아 문서 로딩
wiki_loader = WikipediaLoader(query="인공지능", lang="ko")
documents = wiki_loader.load()
문서에 출처 및 요약 추가 방법
LangChain의 Document 객체는 출처(source), 요약(summary) 등의 정보를 문서에 추가할 수 있다. 이를 위해 문서를 로딩한 후 Document 객체의 metadata 필드나 page_content를 활용
Document(
page_content="문서의 실제 내용",
metadata={
"source": "파일 경로 또는 URL",
"title": "문서 제목",
"summary": "요약 내용",
...
}
)
반응형
'Python' 카테고리의 다른 글
BERT 모델을 이용해서 이상 문장 학습 및 탐지하기 (0) | 2025.04.16 |
---|---|
Python - 내장 변수 관리 locals() (0) | 2025.04.09 |
Python - 글로벌 인터프리터 락(GIL) 제거를 위한 주요 기술 (0) | 2025.04.09 |
FastAPI - Docs, Redoc 비활성화 하기 (0) | 2025.03.28 |
Python - (pymysql.err.OperationalError) (1241, 'Operand should contain 1 column(s)') INSERT (0) | 2025.01.13 |