langchain-kapa-ai
LangChain integration for Kapa.ai. It provides a retriever, a document tool, and a toolkit that returns both as agent tools, so Python LangChain applications and agents can search a Kapa knowledge base and look up whole documents for the sources a search returns.
KapaRetrieverreturns the most relevant chunks for a query as LangChain documents, each with its source link inmetadata["source"].KapaGetDocumentsToollets an agent fetch whole documents by the source links that search results cite, or by document ID.KapaToolkitreturns both as agent tools, configured from one set of settings.
Installation
pip install langchain-kapa-ai
Usage
The package searches a Kapa project that already has knowledge sources indexed; Index your first source sets one up. Create an API key for that project in the Kapa platform, then set it and the project ID:
export KAPA_API_KEY="your-api-key"
export KAPA_PROJECT_ID="your-project-id"
from langchain_kapa_ai import KapaRetriever
retriever = KapaRetriever()
for document in retriever.invoke("How do I rotate an API key?"):
print(document.metadata["source"])
print(document.page_content)
KapaGetDocumentsTool fetches whole documents by the source links that search results cite:
from langchain_kapa_ai import KapaGetDocumentsTool
tool = KapaGetDocumentsTool()
print(tool.invoke({"urls": ["https://docs.example.com/guide"]}))
The retriever also works in a chain. This one passes the chunks and their source links to a chat model named in LangChain's provider:model form:
import os
from langchain.chat_models import init_chat_model
from langchain_core.documents import Document
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_kapa_ai import KapaRetriever
def format_documents(documents: list[Document]) -> str:
return "\n\n".join(
f"Source: {document.metadata['source']}\n{document.page_content}"
for document in documents
)
prompt = ChatPromptTemplate.from_template(
"Answer from the chunks and cite their sources.\n\n"
"Chunks:\n{context}\n\nQuestion: {question}"
)
chain = (
{"context": KapaRetriever() | format_documents, "question": RunnablePassthrough()}
| prompt
| init_chat_model(os.environ["KAPA_EXAMPLE_MODEL"])
| StrOutputParser()
)
print(chain.invoke("How do I rotate an API key?"))
KapaToolkit gives an agent both tools, a search tool that shows each chunk with its source link and the document tool, from one set of settings:
from langchain_kapa_ai import KapaToolkit
tools = KapaToolkit().get_tools()
The agent example attaches the toolkit to an agent, and the reference describes every setting, the document tool, and the errors.
Examples
examples/: search without a model, a fixed question-to-answer pipeline, and an agent that searches and follows citations into whole documents.
The examples work with any chat model that supports tool calling, for example from OpenAI or Anthropic. Install that provider's LangChain package, set its API key, and name the model in LangChain's provider:model form:
export KAPA_EXAMPLE_MODEL="<provider>:<model>"
Development
The repository uses uv.
uv sync
make format-check lint typecheck test
make integration-test runs the live tests against a project you choose. It reads KAPA_API_KEY and KAPA_PROJECT_ID, takes its queries from KAPA_TEST_QUERIES (one per line) or tests/integration_tests/queries.local.txt, and skips without them.
The live example tests also need the LangChain package of the provider named in KAPA_EXAMPLE_MODEL available to the project interpreter, so run them with uv run --with langchain-<provider> pytest tests/integration_tests.
Releasing
Releases are published from version tags by the publish workflow.
- Set the version with
uv version <version>and add a## <version>section to CHANGELOG.md. - Merge the change to
main. - Tag the merged commit with the bare version, for example
git tag 0.1.0 origin/main, and push the tag.
The workflow checks that the tag matches the package version, the tagged commit is on main, and the changelog has the entry. It then runs the quality gates, publishes to TestPyPI and installs the result, and waits for a reviewer to approve the pypi environment before publishing to PyPI and installing the published package.
License
Metadata
Release files for langchain-kapa-ai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_kapa_ai-0.1.0.tar.gz | 11.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_kapa_ai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.2 kB
Release files / langchain_kapa_ai-0.1.0.tar.gz
| Download URL | langchain_kapa_ai-0.1.0.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26c740f21a3ed16b9a34f7009d44b5897b9823f5186e12eff4a60db22fc30292
|
|
BLAKE2b-256 checksum How to use checksums |
56a7f7da51c2427a10ca413548637043ccb48fc77072c22afce5370e4deedb41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logRelease files / langchain_kapa_ai-0.1.0-py3-none-any.whl
| Download URL | langchain_kapa_ai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9197249ca079fd5a4658e7d81b6bb054181c2e39244a3c3f2cee209e6d57de81
|
|
BLAKE2b-256 checksum How to use checksums |
f8bebed2c663727dd462fbaef30004195c1a0dfc8696c606233aec1c0f2594e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency log