여러 개별 파일 통합

여러 개별 파일 통합

LangChain JavaScript로 여러 개별 파일 문서 로더와 통합하는 방법을 안내할게요.

출처: 문서

본문

이 예제는 여러 파일 경로에서 데이터를 로드하는 방법을 다뤄요. 두 번째 인자는 파일 확장자를 로더 팩토리로 매핑하는 맵이에요. 각 파일은 해당하는 로더에 전달되고, 결과 문서는 함께 연결(concatenate)돼요.

예제 파일들:

src/document_loaders/example_data/example/
├── example.txt
└── example.csv

src/document_loaders/example_data/example2/
├── example.json
└── example.jsonl

예제 코드:

import { MultiFileLoader } from "@langchain/classic/document_loaders/fs/multi_file";
import {
  JSONLoader,
  JSONLinesLoader,
} from "@langchain/classic/document_loaders/fs/json";
import { TextLoader } from "@langchain/classic/document_loaders/fs/text";
import { CSVLoader } from "@langchain/classic/document_loaders/fs/csv";

const loader = new MultiFileLoader(
  [
    "src/document_loaders/example_data/example/example.txt",
    "src/document_loaders/example_data/example/example.csv",
    "src/document_loaders/example_data/example2/example.json",
    "src/document_loaders/example_data/example2/example.jsonl",
  ],
  {
    ".json": (path) => new JSONLoader(path, "/texts"),
    ".jsonl": (path) => new JSONLinesLoader(path, "/html"),
    ".txt": (path) => new TextLoader(path),
    ".csv": (path) => new CSVLoader(path, "text"),
  }
);
const docs = await loader.load();
console.log({ docs });

[Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers. [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/document_loaders/file_loaders/multi_file.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).

더 알아보기