LangChain integration for Konstruct - Typed Knowledge Graph for AI Agents
Project description
Konstruct × LangChain
LangChain retriever classes powered by Konstruct's typed knowledge graph engine.
What This Does
Standard RAG gives your LLM chunks of text. Konstruct gives it structured knowledge — concepts connected by typed relationships like causes, requires, contradicts, and enables.
Your LLM stops guessing and starts reasoning.
Installation
pip install langchain-konstruct
Get an API key at aerware.ai.
Quick Start
from langchain_konstruct import KonstructRetriever
from langchain.chains import RetrievalQA
from langchain_anthropic import ChatAnthropic
retriever = KonstructRetriever(
api_key="your_konstruct_api_key",
pack_ids=["causal-startup-failure", "market-dynamics"],
)
qa = RetrievalQA.from_chain_type(
llm=ChatAnthropic(model="claude-sonnet-4-20250514"),
retriever=retriever,
)
response = qa.invoke({"query": "What causes startups to fail?"})
print(response["result"])
Using the Hosted Corpus
Konstruct ships with 2,800+ pre-built knowledge packs across business, science, health, law, and engineering. Reference them by ID:
retriever = KonstructRetriever(
api_key="your_api_key",
pack_ids=["causal-startup-failure", "market-dynamics", "monetary-policy"],
)
Browse available packs at aerware.ai/library.
Using Your Own Knowledge Packs
Load custom packs from JSON files or dicts:
retriever = KonstructRetriever(api_key="your_api_key")
# From file
retriever.load_pack_from_file("packs/my-domain.json")
# From dict
retriever.load_pack({
"id": "my_pack",
"name": "My Domain Knowledge",
"concepts": [
{
"id": "concept_a",
"name": "Concept A",
"category": "strategy",
"importance": 0.9,
"description": "What this concept means"
}
],
"edges": [
{
"source": "concept_a",
"target": "concept_b",
"relation": "causes",
"weight": 0.85
}
]
})
Retriever Options
retriever = KonstructRetriever(
api_key="your_api_key", # From aerware.ai
pack_ids=["pack-1"], # Hosted packs to load
max_concepts=10, # How many concepts to retrieve
max_depth=2, # Edge traversal depth (1 or 2)
search_type="advisory", # "advisory" or "concepts"
category_filter="strategy", # Optional: filter by category
)
search_type:
"advisory"— Returns structured guidance (key concepts + relationships + frameworks). Best for chat/QA."concepts"— Returns raw concepts as separate documents. Best for custom pipelines.
Causal Reasoning
Use KonstructCausalRetriever when you need answers about prerequisites, dependencies, or causal chains:
from langchain_konstruct import KonstructCausalRetriever
retriever = KonstructCausalRetriever(
api_key="your_api_key",
pack_ids=["fintech-compliance"],
)
docs = retriever.get_relevant_documents("What must be in place before AML compliance?")
# Prioritizes "requires", "causes", "enables", "prevents" edges
Knowledge Pack Format
Packs are validated JSON with concepts, typed edges, and optional frameworks:
{
"id": "my_pack",
"name": "My Knowledge Pack",
"concepts": [
{
"id": "product_market_fit",
"name": "Product-Market Fit",
"category": "strategy",
"importance": 0.95,
"description": "When a product satisfies strong market demand"
}
],
"edges": [
{
"source": "customer_discovery",
"target": "product_market_fit",
"relation": "enables",
"weight": 0.9
}
],
"frameworks": [
{
"id": "pmf_framework",
"name": "PMF Checklist",
"trigger_concepts": ["product_market_fit"],
"questions": ["Are users actively requesting access?"],
"red_flags": ["Building without user feedback"],
"green_lights": ["Users paying before launch"]
}
]
}
Supported relation types: causes, requires, enables, prevents, conflicts_with, supports, contradicts, is_a, part_of, precedes, amplifies, diminishes, implements, depends_on, correlates_with, replaces, triggers, validates, similar_to
Reverse edges are inferred automatically — add causes and caused_by is created for you.
Explore Concept Relationships
# Explore outward from a specific concept
docs = retriever.explore_concept("product_market_fit", depth=2)
# List all loaded concepts
docs = retriever.get_all_concepts(category="strategy")
# Graph statistics
stats = retriever.get_stats()
print(f"Concepts: {stats['concept_count']}, Edges: {stats['edge_count']}")
Environment Variables
ANTHROPIC_API_KEY=your_anthropic_key
KONSTRUCT_API_KEY=your_konstruct_key # from aerware.ai
Links
- Get API Key: aerware.ai
- Browse Packs: aerware.ai/library
- Docs: docs.aerware.ai/konstruct
- Issues: github.com/AerwareAI/konstruct-v2/issues
© 2026 AerwareAI — Proprietary
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_konstruct-0.2.0.tar.gz.
File metadata
- Download URL: langchain_konstruct-0.2.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14775e8a695d2534d058792804f6e409b44ead8498d4aa1ceb9b72df39d93ca7
|
|
| MD5 |
d19fcf4055208ee329e4b2c0e50111e2
|
|
| BLAKE2b-256 |
d1f531e043dc3b3800e0de29b2fce68d6996f7718d8de070efd9e0ecc28d1c47
|
File details
Details for the file langchain_konstruct-0.2.0-py3-none-any.whl.
File metadata
- Download URL: langchain_konstruct-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad1c09d31b47966cf6d63ee23aaa6f70dffb4b31a791a5428c269fa2cd4e6008
|
|
| MD5 |
3bfd00d41c4120f26074326c343da4fa
|
|
| BLAKE2b-256 |
4d446a52db269776f3b302fc43da5589d41420c87349bae259de8fa16433d57c
|