RAG
RAG란?
섹션 제목: “RAG란?”RAG (Retrieval-Augmented Generation)는 에이전트가 문서를 사용하여 질문에 답할 수 있게 합니다. Schift가 전체 파이프라인을 처리합니다:
PDF/DOCX/TXT 업로드 -> OCR -> 청킹 -> 임베딩 -> 벡터 인덱스 | 질의 -> 임베딩 -> 검색 -> 리랭킹 -> 컨텍스트문서를 업로드하면 Schift가 처리하고, 에이전트가 검색하고 답변합니다.
import { Schift, RAG } from "@schift-io/sdk";
const schift = new Schift({ apiKey: "sch_..." });const rag = new RAG({ bucket: "my-docs", topK: 5 }, schift.transport);| 옵션 | 타입 | 기본값 | 설명 |
|---|---|---|---|
bucket | string | 필수 | Schift 버킷 ID |
topK | number | 7 | 검색당 결과 수 |
const results = await rag.search("How do I reset my password?");
for (const r of results) { console.log(r.text); // 매칭된 구절 console.log(r.score); // 관련성 점수 (0-1) console.log(r.metadata); // 문서 메타데이터}채팅 (검색 + LLM 답변)
섹션 제목: “채팅 (검색 + LLM 답변)”const response = await rag.chat("How do I reset my password?");
console.log(response.answer); // LLM이 생성한 답변console.log(response.sources); // 사용된 소스 구절Agent와 함께 RAG 사용
섹션 제목: “Agent와 함께 RAG 사용”RAG 인스턴스를 Agent에 전달하세요. rag_search라는 이름의 도구로 자동 등록됩니다.
const agent = new Agent({ name: "Support Bot", instructions: "Answer questions using the knowledge base.", rag, model: "gpt-4o-mini", transport: schift.transport,});
const result = await agent.run("How do I reset my password?");에이전트는 문서에서 정보가 필요할 때 rag_search를 호출합니다.
문서 업로드
섹션 제목: “문서 업로드”Schift 대시보드 또는 API를 통해 문서를 업로드합니다:
// Schift 클라이언트를 통해await schift.db.upload("my-docs", file);지원 형식: PDF, DOCX, TXT, MD, HTML. Schift가 스캔 문서에 자동으로 OCR을 실행합니다.
Public Buckets
섹션 제목: “Public Buckets”Schift가 운영하는 공용 데이터셋을 문서 업로드 없이 바로 검색할 수 있습니다:
const rag = new RAG({ bucket: "public--korean-law" }, schift.transport);const results = await rag.search("개인정보보호법 동의 철회");Public Buckets 가이드에서 전체 목록과 상세 내용을 확인하세요.
커스텀 도구 이름
섹션 제목: “커스텀 도구 이름”다른 도구 이름이 필요한 경우 (예: 여러 RAG 소스):
const legalDocs = new RAG({ bucket: "legal" }, schift.transport);const supportDocs = new RAG({ bucket: "support" }, schift.transport);
const agent = new Agent({ tools: [ legalDocs.asTool("search_legal_docs"), supportDocs.asTool("search_support_docs"), ], ...});