langchain-sourcey
Implement Ask AI over a published Sourcey docs site.
langchain-sourcey reads Sourcey's generated search and LLM artefacts and
returns canonical page URLs for citation.
Sourcey already emits the files a retriever needs:
documents.json, its index of every page, operation and schema, for candidates- each document's own Markdown, for the content of a match
- canonical page URLs for citations
No hosted index is required. Point site_url at the docs root and use it.
Install
pip install -U langchain-sourcey
Point site_url at the root of a published Sourcey build:
https://sourcey.com/docshttps://sourcey.com/cheesestorehttps://cheesestore.github.io
Quickstart
from langchain_sourcey import SourceyRetriever
retriever = SourceyRetriever(
site_url="https://sourcey.com/docs",
top_k=3,
)
docs = retriever.invoke("mcp integration")
for doc in docs:
print(doc.metadata["title"])
print(doc.metadata["source"])
print(doc.page_content[:160])
print()
For a runnable script, see examples/live_quickstart.py.
More context: Sourcey guide
Implement Ask AI
Install a chat model package. This example uses OpenAI:
pip install -U langchain-openai
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
from langchain_sourcey import SourceyRetriever
retriever = SourceyRetriever(site_url="https://sourcey.com/docs", top_k=3)
prompt = ChatPromptTemplate.from_template(
"""Answer the question using the documentation context below.
{context}
Question: {question}"""
)
chain = (
RunnablePassthrough.assign(context=(lambda x: x["question"]) | retriever)
| prompt
| ChatOpenAI(model="gpt-4.1-mini")
| StrOutputParser()
)
answer = chain.invoke({"question": "How does Sourcey document MCP servers?"})
print(answer)
For a fuller example, see examples/rag_chain.py.
Sourcey Output Contract
For predictable retrieval, the published Sourcey site should expose:
- publish
documents.jsonand each document's Markdown, as Sourcey 3.7.1 and later do by default - set
siteUrlinsourcey.config.tsso citations are canonical
A site built before Sourcey 3.7.1 publishes search-index.json instead, and
the retriever reads that in its place. When a document's Markdown cannot be
read, the retriever uses its page in llms-full.txt, then the page's HTML.
Returned Metadata
Each returned Document includes:
source: canonical page URL used for citationsmatched_url: original matched URL, including anchors when relevantmatched_title: matched search entry titletitle: hydrated page titlepath: Sourcey output path such asguides/search.htmlanchor: matched fragment, if anytab: Sourcey tab labelcategory: Sourcey search categorysite_url: docs root used for retrievalscore: retriever ranking score
Development
python -m pip install -e .[dev] build twine
PYTHONPATH=src pytest -q
SOURCEY_TEST_SITE_URL=https://sourcey.com/docs PYTHONPATH=src pytest tests/integration_tests/test_live_retriever.py -q
python -m build
python -m twine check dist/*
See CONTRIBUTING.md for the release and verification flow.
LangChain Submission Assets
This repo includes draft docs ready to turn into a LangChain docs PR:
JavaScript Package
This repo also contains the JavaScript package in js.
- npm package:
langchain-sourcey - draft JS docs: docs/langchain-js/provider-sourcey.mdx
- draft JS docs: docs/langchain-js/retriever-sourcey.mdx
Scope
This package ships SourceyRetriever only. No loader yet.
Metadata
Release files for langchain-sourcey 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_sourcey-0.1.8.tar.gz | 70.4 kB | Without provenance | Details for langchain_sourcey-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_sourcey-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for langchain_sourcey-0.1.8-py3-none-any.whl |
Total release size: 103.2 kB
Release files / langchain_sourcey-0.1.8.tar.gz
| Download URL | langchain_sourcey-0.1.8.tar.gz |
|---|---|
| Size | 70.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5205217ed8d623c4028d1d191543a907b54f115ffe2fac0a5c840370aba2edab
|
|
BLAKE2b-256 checksum How to use checksums |
861765bb6edfce8192b6d49ac2203e9ebbac3c3fb14ec166054072454dea79f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / langchain_sourcey-0.1.8-py3-none-any.whl
| Download URL | langchain_sourcey-0.1.8-py3-none-any.whl |
|---|---|
| Size | 32.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60c7ba4e147fc09fb698b993d8f35e8a45c7ceda34aa3801d5128a0a6fbbb423
|
|
BLAKE2b-256 checksum How to use checksums |
82f9cc0d980dfa081a071d3b723e89d7bd6028018c9a20916058d8bfd6a5a97f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for langchain-sourcey 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.