Skip to main content

langchain-kapa-ai

PyPI - Version PyPI - Downloads

LangChain integration for Kapa. Kapa is an ingestion and retrieval system: it indexes content such as documentation sites, wikis, PDFs, tickets, Slack threads, and API specifications into a knowledge base, keeps it up to date, and lets your agents get context from it through agentic retrieval.

This package gives Python LangChain chains and agents access to Kapa's retrieval over the knowledge sources in your Kapa project.

  • KapaRetriever: a retriever that returns the most relevant chunks for a query as LangChain documents.
  • KapaGetDocumentsTool: an agent tool that fetches whole documents by source URL or document ID.
  • KapaToolkit: returns search and document lookup as two agent tools, search_knowledge_sources and get_knowledge_documents, configured from one set of settings.

Documentation

Requirements

  • Python 3.10 or later.
  • langchain-core 1.4 or later, before 2.0.
  • A Kapa project with indexed knowledge sources. To set one up, follow Set up with a coding agent.

Installation

pip install langchain-kapa-ai

Credentials

In the Kapa platform, create an API key for your project under Deploy > API Keys, and copy the project ID from Settings > Projects. All components read both from the environment, so export them:

export KAPA_API_KEY="your-api-key"
export KAPA_PROJECT_ID="your-project-id"

Or put them in a .env file. The package does not read the file itself, so load it in your application, for example with python-dotenv:

KAPA_API_KEY=your-api-key
KAPA_PROJECT_ID=your-project-id

Usage

Use in an agent

KapaToolkit gives an agent both tools. This example also needs langchain and your model provider's LangChain package. Replace <provider>:<model> with a tool-capable model and configure the provider's credentials.

from langchain.agents import create_agent
from langchain.chat_models import init_chat_model
from langchain_kapa_ai import KapaToolkit

agent = create_agent(
    init_chat_model("<provider>:<model>"),
    tools=KapaToolkit().get_tools(),
    system_prompt="Search the knowledge base before answering and cite your sources.",
)

search_knowledge_sources returns each chunk with its source link, and get_knowledge_documents fetches the whole document behind a link when a chunk is not enough.

Search without an agent

KapaRetriever works anywhere LangChain accepts a retriever, including chains. It supports invoke, ainvoke, batch, and abatch:

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)

Retrieval mode

The retriever has two modes. default is faster. deep searches further and returns only relevant chunks, at the cost of latency. Set the mode on the retriever, or for a single call:

retriever = KapaRetriever(mode="deep")
documents = retriever.invoke("How do I rotate an API key?", mode="default")

Choose a retrieval mode helps you pick one. KapaToolkit takes the same setting, for example KapaToolkit(mode="deep"). The reference lists every other setting, such as top_k, source_group_ids, and analytics attribution.

Fetch whole documents

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"]}))

Errors and retries

A failed request raises an exception that derives from KapaError; it never becomes an empty result. No component retries a failed request: in a chain, wrap a component with LangChain's with_retry(), and in an agent, use LangChain's ToolRetryMiddleware. The reference lists every exception.

Examples

See examples/ for full code examples.

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.

  1. Set the version with uv version <version> and add a ## <version> section to CHANGELOG.md.
  2. Merge the change to main.
  3. 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

MIT

Metadata

Release files for langchain-kapa-ai 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-kapa-ai 0.1.1
File Size Uploaded Provenance Actions
langchain_kapa_ai-0.1.1.tar.gz 12.3 kB With provenance Details for langchain_kapa_ai-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-kapa-ai 0.1.1
File Interpreter ABI Platform Actions
langchain_kapa_ai-0.1.1-py3-none-any.whl Python 3 none any Details for langchain_kapa_ai-0.1.1-py3-none-any.whl

Total release size: 26.7 kB

Release files / langchain_kapa_ai-0.1.1.tar.gz

Download URL langchain_kapa_ai-0.1.1.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b9e49c4b0fd89897631ed82746290c08f1856345eeb8fa8b8098a1edb69bb35a
BLAKE2b-256 checksum
How to use checksums
009e77df8b6418e5ac6fce9fc6761026ca88d266b72ed472543db1cacbcbf2af
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 12, 2026.

Transparency log

Release files / langchain_kapa_ai-0.1.1-py3-none-any.whl

Download URL langchain_kapa_ai-0.1.1-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3df79649b56f421c50d62f18b0d093cf3cf83703a64262dec84e9e7318eb6bd5
BLAKE2b-256 checksum
How to use checksums
410eff8c8c5dfb0750181b058d785d97ebad36e43f9deb785d9b8081ade0b29e
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 12, 2026.

Transparency log

Security for langchain-kapa-ai 0.1.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_kapa_ai-0.1.1.tar.gz

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 12, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page