本页还没有译文
本页 22 段还没译成日本語,下面显示的是英文原文。SourceyRetriever integration
还没翻译译自英文(docs.langchain.com)本页 22 段都还没译
Overview
Sourcey already emits the files this retriever needs.
Use SourceyRetriever to retrieve from a published Sourcey docs site. It
reads search-index.json, uses llms-full.txt when present, and returns
Document objects with canonical page URLs in metadata.source.
Integration details
| Retriever | Source | Package |
|---|---|---|
SourceyRetriever | Published Sourcey docs sites. | langchain-sourcey |
Setup
Installation
npm install langchain-sourcey @langchain/coreyarn add langchain-sourcey @langchain/corepnpm add langchain-sourcey @langchain/coreNo API key is required.
Instantiation
siteUrl should point at the root of a published Sourcey docs build.
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);
}Use within a chain
Install a chat model package. This example uses OpenAI:
npm install @langchain/openaiyarn add @langchain/openaipnpm add @langchain/openaiimport 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 site requirements
For clean retrieval, the published Sourcey site should:
- publish
search-index.json - publish
llms-full.txt - set
siteUrlinsourcey.config.tsso returned citations are canonical
If llms-full.txt is not available, SourceyRetriever falls back to
extracting text from the matched HTML page.
More
- Sourcey guide: Using Sourcey with LangChain
- Package: langchain-sourcey on npm
AI 翻译查看英文原文