Skip to main content

langchain-ckg

LangChain retriever backed by Compact Knowledge Graphs — deterministic, SHA-256 anchored, 4× better than RAG

PyPI Downloads License: MIT Benchmark


CKG vs RAG — the difference that matters

RAG                                    CKG
────────────────────────────────────   ─────────────────────────────────────
Retrieve document chunks               Traverse typed dependency graph
Probabilistic similarity match         Deterministic BFS from matched concept
No provenance                          SHA-256 per node — verify any claim
2,982 tokens/query                     269 tokens/query  (11× cheaper)
F1 = 0.123                             F1 = 0.471  (4× better)
Metric CKG RAG GraphRAG
Macro F1 0.471 0.123 0.120
Tokens/query 269 2,982 2,982
Cost @ $10/1M $0.003 $0.030 $0.030
Source provenance SHA-256 per node none none

Benchmark paper · Dataset · patent-pending methodology


Install

pip install langchain-ckg

Usage

Local retriever — free, no network

Queries run entirely in-process against graphs bundled in ckg-mcp. No API key, no rate limit.

from langchain_ckg import CKGRetriever
from langchain_openai import ChatOpenAI
from langchain.chains import RetrievalQA

retriever = CKGRetriever(domain="nvidia-nemoclaw", depth=3)
qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(), retriever=retriever)
result = qa.invoke("How does NemoClaw handle CUDA kernel fusion?")

Hosted retriever — 48-hour free trial, then $1 / 100 calls

from langchain_ckg import CKGHostedRetriever

# Free for 48 hours from first call
retriever = CKGHostedRetriever(domain="nvidia-nemoclaw")

# After trial: pass a license key
retriever = CKGHostedRetriever(
    domain="nvidia-nemoclaw",
    license_key="CKGAP-...",  # graphifymd.com/pricing
)

After 48 hours the server returns 402 Payment Required with upgrade options. See Payment rails for autonomous payment.


Payment rails

x402 — autonomous USDC on Base L2

Agent pays itself. No human in the loop.

retriever = CKGHostedRetriever(
    domain="nvidia-nemoclaw",
    x402_private_key="0x<evm-private-key>",
)
# On 402: signs $0.010 USDC payment, retries, returns result

License key — human-purchased, unlimited

graphifymd.com/pricing → receive CKGAP-... key → pass once:

retriever = CKGHostedRetriever(domain="nvidia-nemoclaw", license_key="CKGAP-...")
Tier Price Calls
Starter $1 100
Bundle $4 500
Dev $29/mo Unlimited

Lightning — autonomous sats

retriever = CKGHostedRetriever(
    domain="nvidia-nemoclaw",
    lightning_invoice_id="<invoice-id>",  # GET {endpoint}/lightning/invoice
)
# 100 sats/call (~$0.001)

Metered billing with PolarUsageCallback

Track per-retrieval usage in Polar — fires a background thread, never blocks the chain:

from langchain_ckg import CKGRetriever, PolarUsageCallback

cb = PolarUsageCallback(api_key="sk_...", external_customer_id="license_key_abc")
retriever = CKGRetriever(domain="nvidia-nemoclaw", depth=3)
qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(), retriever=retriever, callbacks=[cb])

AgentKit integration

Coinbase AgentKit agents pay x402 natively. Wire CKGHostedRetriever as a LangChain tool:

from coinbase_agentkit_langchain import CoinbaseToolkit
from langchain_ckg import CKGHostedRetriever
from langchain.tools.retriever import create_retriever_tool

retriever = CKGHostedRetriever(
    domain="nvidia-nemoclaw",
    x402_private_key="0x<agentkit-wallet-key>",
)
ckg_tool = create_retriever_tool(
    retriever,
    name="query_knowledge_graph",
    description="Retrieve SHA-256 anchored knowledge about NVIDIA NemoClaw. Pays autonomously via x402.",
)
# Combine with AgentKit tools and run

Trust anchor chain

Every node carries a SHA-256 hash of its source document bytes at extraction time:

source_url:  https://docs.nvidia.com/nemo/...   ← fetch hint
source_hash: sha256:<64-char hex>               ← trust anchor

Verify any claim:

curl -s <source_url> | sha256sum
# mismatch = stale edge or upstream silent edit — no judgment needed

Full audit chain: edge answer → graph commit → source_hash → source_url


Available domains

117 domains — NVIDIA AI stack, NemoClaw, Salesforce AgentForce, finance (Basel III · SEC · IFRS), agent protocols (MCP · A2A · x402), infrastructure (Render · Stripe · PostHog · Cloudflare), and more.

uvx ckg-mcp  # → call list_domains

Links

graphifymd.com · Pricing · PyPI · Benchmark · Dataset

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_ckg-0.5.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_ckg-0.5.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_ckg-0.5.0.tar.gz.

File metadata

  • Download URL: langchain_ckg-0.5.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for langchain_ckg-0.5.0.tar.gz
Algorithm Hash digest
SHA256 83f12d8582b24914a34c04eafd85df7537a60a265709dbec26efaafc17d08e6c
MD5 41aeabb1af67f816db4bf0900c543af9
BLAKE2b-256 255c1fef674e6d6efe91af6596e670a8dd47a4140e2cc46a21f3c6f902a0f245

See more details on using hashes here.

File details

Details for the file langchain_ckg-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_ckg-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for langchain_ckg-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f1e27b0e622987c1cf2918b8d5d6644f0b9a0d6aff502c26052c1b8ed279c37
MD5 b5eca6cb988a19e4ea9e863842e8e605
BLAKE2b-256 91f96844090503519faecc76a020af31048f11ce7e6fda916bdc3b240526b296

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

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