SourceyRetriever 통합
SourceyRetriever 통합
LangChain JavaScript로 SourceyRetriever 검색기와 통합하는 방법을 알아봅니다.
Sourcey는 이미 이 검색기가 필요로 하는 파일을 생성해요.
SourceyRetriever를 사용해 게시된 Sourcey 문서 사이트에서 검색하세요. search-index.json을 읽고, llms-full.txt가 있으면 사용하며, metadata.source에 canonical 페이지 URL을 담은 Document 객체를 반환합니다.
출처: 문서
본문
개요
통합 세부 정보
| 검색기(Retriever) | 소스(Source) | 패키지(Package) |
|---|---|---|
SourceyRetriever |
게시된 Sourcey 문서 사이트(Published Sourcey docs sites). | langchain-sourcey |
설정
설치
npm install langchain-sourcey @langchain/core
yarn add langchain-sourcey @langchain/core
pnpm add langchain-sourcey @langchain/core
API 키가 필요하지 않습니다.
인스턴스화(Instantiation)
siteUrl은 게시된 Sourcey 문서 빌드의 루트를 가리켜야 합니다.
import { SourceyRetriever } from "langchain-sourcey";
const retriever = new SourceyRetriever({
siteUrl: "https://sourcey.com/docs",
topK: 3,
});
사용법(Usage)
const docs = await retriever.invoke("mcp integration");
for (const doc of docs) {
console.log(doc.metadata.title);
console.log(doc.metadata.source);
}
체인 내에서 사용하기
채팅 모델 패키지를 설치하세요. 이 예제는 OpenAI를 사용합니다:
npm install @langchain/openai
yarn add @langchain/openai
pnpm add @langchain/openai
import type { Document } from "@langchain/core/documents";
import { StringOutputParser } from "@langchain/core/output_parsers";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { RunnablePassthrough, RunnableSequence } from "@langchain/core/runnables";
import { ChatOpenAI } from "@langchain/openai";
import { SourceyRetriever } from "langchain-sourcey";
const retriever = new SourceyRetriever({
siteUrl: "https://sourcey.com/docs",
topK: 3,
});
const prompt = ChatPromptTemplate.fromTemplate(
`Answer the question using the documentation context below.
{context}
Question: {question}`
);
const formatDocs = (docs: Document[]) =>
docs.map((doc) => doc.pageContent).join("\n\n");
const chain = RunnableSequence.from([
{
context: retriever.pipe(formatDocs),
question: new RunnablePassthrough(),
},
prompt,
new ChatOpenAI({ model: "gpt-4.1-mini" }),
new StringOutputParser(),
]);
await chain.invoke("How does Sourcey document MCP servers?");
Sourcey 사이트 요구 사항(Sourcey site requirements)
깔끔한 검색을 위해 게시된 Sourcey 사이트는 다음을 해야 합니다:
search-index.json게시llms-full.txt게시- 반환된 인용이 canonical이 되도록
sourcey.config.ts에서siteUrl설정
llms-full.txt를 사용할 수 없으면 SourceyRetriever는 일치하는 HTML 페이지에서 텍스트를 추출하는 것으로 폴백합니다.
더 보기(More)
- Sourcey 가이드: LangChain과 함께 Sourcey 사용하기
- 패키지: npm의 langchain-sourcey
더 알아보기 (Learn more)
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.