Skip to content

Knowledge Base

intermediate

Build 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

RequirementDetails
AccountStarter tier or above (500+ patterns recommended)
API keyFrom your dashboard
SDKPython or JavaScript
Time~20 minutes

Why not a traditional knowledge base?

Traditional KBEngramma KB
Manual categorizationAuto-clusters by meaning
Explicit links between articlesCausal links form from usage
Search returns text matchesSearch returns connected knowledge
Stale content stays foreverConsolidation prunes outdated facts
Rigid hierarchyOrganic, evolving structure

Steps

1

Bulk-store your knowledge

Import existing documentation, FAQs, or facts into Engramma. Each fact becomes an independent memory.
2

Query with natural language

Ask questions in plain English. The engine connects facts across your knowledge base automatically.
3

Discover causal links

As you query, the engine builds a causal graph. Ask 'why?' and 'what if?' questions.
4

Trigger consolidation

After bulk import, trigger a consolidation cycle to let the engine organize, merge duplicates, and build links.
5

Monitor and iterate

Check stats to see how your knowledge base is evolving. Add new facts as they emerge.

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 countRecommendation
< 100Free tier, no consolidation needed
100-1,000Consolidate after bulk imports
1,000-10,000Automatic consolidation handles most cleanup
10,000+Monitor redundancy score, consider domain-based metadata filtering
Tip

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.

Info

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