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.4.0.tar.gz (9.2 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.4.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_ckg-0.4.0.tar.gz
  • Upload date:
  • Size: 9.2 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.4.0.tar.gz
Algorithm Hash digest
SHA256 b42361cb9e2d8626a40b4d151c6c50792f6fef18715e841f5ba0ad87f239f1ce
MD5 a70566783a2aa4e20166cde6af23f98f
BLAKE2b-256 c0504fd9b6871cf6b603a95da4f8a54c443dab7caa82048695e8cdcec95cfd94

See more details on using hashes here.

File details

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

File metadata

  • Download URL: langchain_ckg-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3596f0794642a4829b20ad876b2d756bff97de2c6528208d555f81fa07cb983
MD5 d49e417d6d00c5ef89fc6eb26e812757
BLAKE2b-256 55f49c16e2735ece88c403edc9684739e488be106ac80105e41ea92928565f04

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.0

2 files

0.5.0

2 files

This release

0.4.0 This release

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