Knowledge Base
intermediateBuild a self-organizing knowledge base with causal links, automatic clustering, and consolidation. No manual tagging required.
What you'll build
A knowledge base that organizes itself — facts link together automatically, clusters emerge from patterns, and knowledge quality improves over time through consolidation.
Prerequisites
| Requirement | Details |
|---|---|
| Account | Starter tier or above (500+ patterns recommended) |
| API key | From your dashboard |
| SDK | Python or JavaScript |
| Time | ~20 minutes |
Why not a traditional knowledge base?
| Traditional KB | Engramma KB |
|---|---|
| Manual categorization | Auto-clusters by meaning |
| Explicit links between articles | Causal links form from usage |
| Search returns text matches | Search returns connected knowledge |
| Stale content stays forever | Consolidation prunes outdated facts |
| Rigid hierarchy | Organic, evolving structure |
Steps
Bulk-store your knowledge
Query with natural language
Discover causal links
Trigger consolidation
Monitor and iterate
Complete code
import os
from engramma_cloud import EngrammaClient
client = EngrammaClient(api_key=os.environ["ENGRAMMA_API_KEY"])
# Step 1: Bulk-store knowledge
facts = [
"Python 3.12 introduced type parameter syntax",
"Type parameter syntax uses square brackets after class/function names",
"TypeVar is no longer needed for simple generic functions in 3.12+",
"Python 3.11 added exception groups and TaskGroups",
"Exception groups allow multiple exceptions to propagate simultaneously",
"TaskGroups replace gather() for structured concurrency",
"Python 3.10 introduced structural pattern matching",
"Pattern matching uses match/case keywords",
"Pattern matching supports guards with 'if' clauses",
]
for fact in facts:
client.store(fact, metadata={"domain": "python", "type": "fact"})
print(f"Stored {len(facts)} facts")
# Step 2: Query with natural language
results = client.retrieve("What changed with generics in recent Python?")
for r in results[:3]:
print(f" [{r.confidence:.2f}] {r.text}")
# Step 3: Discover causal connections
results = client.retrieve(
"What replaced TypeVar?",
causal=True
)
print(f"\nAnswer: {results[0].text}")
if results[0].causal_chain:
print(f"Chain: {' → '.join(results[0].causal_chain)}")
# Step 4: Consolidate after bulk import
result = client.consolidate()
print(f"\nConsolidation: {result.patterns_before} → {result.patterns_after} patterns")
print(f"Merged: {result.merged}, Pruned: {result.pruned}")
# Step 5: Check KB health
stats = client.stats()
print(f"\nKB health:")
print(f" Patterns: {stats.patterns_count}")
print(f" Causal links: {stats.causal_links_count}")
print(f" Redundancy: {stats.redundancy_score}")
print(f" Regime: {stats.regime}")Keeping knowledge fresh
As your domain evolves, the knowledge base adapts:
# Store contradicting information — the engine handles belief revision
client.store(
"Python 3.13 deprecates the old typing.TypeVar for new syntax",
metadata={"domain": "python", "type": "fact"}
)
# After consolidation, the causal graph updates:
# Old: TypeVar → needed for generics
# New: TypeVar → deprecated, replaced by type parameter syntax
# Query reflects the latest understanding
results = client.retrieve("Should I use TypeVar?")
print(results[0].text)
# "TypeVar is no longer needed for simple generic functions in 3.12+"Scaling tips
| Pattern count | Recommendation |
|---|---|
| < 100 | Free tier, no consolidation needed |
| 100-1,000 | Consolidate after bulk imports |
| 1,000-10,000 | Automatic consolidation handles most cleanup |
| 10,000+ | Monitor redundancy score, consider domain-based metadata filtering |
Use metadata domains to organize large knowledge bases. Filter retrievals by domain to keep results focused: metadata_filter={"domain": "python"} avoids cross-contamination with unrelated facts.
Unlike traditional knowledge bases that require manual maintenance, Engramma's consolidation cycle automatically merges near-duplicate facts, prunes outdated information, and strengthens frequently-validated knowledge.
Next steps
- Causal Queries — Ask "what if?" and "why?" questions to your knowledge base
- Triggering Consolidation — When and how to trigger sleep cycles
- Regimes — How the engine adapts when it encounters new topics