Set Up TypeDB for ZettelForge¶
Configure TypeDB as the knowledge graph backend. TypeDB stores STIX 2.1 entities, relationships, and alias-of mappings for structured CTI queries.
Prerequisites¶
- Docker and Docker Compose installed
- ZettelForge installed (
pip install zettelforge)
Steps¶
1. Start TypeDB with Docker Compose¶
From the ZettelForge project root:
Verify the container is running:
Expected output:
[!NOTE] TypeDB exposes port
1729(gRPC) and port8100(HTTP health). Data persists in thetypedb-dataDocker volume across restarts.
2. Verify connectivity¶
from zettelforge.typedb_client import TypeDBKnowledgeGraph
try:
kg = TypeDBKnowledgeGraph()
print("TypeDB connection successful")
except Exception as e:
print(f"Connection failed: {e}")
Or via the health endpoint:
3. Load the STIX schema¶
The schema is loaded automatically on first connection via TypeDBKnowledgeGraph. To verify:
from zettelforge.knowledge_graph import get_knowledge_graph
kg = get_knowledge_graph()
print(f"Backend: {type(kg).__name__}")
If TypeDB is reachable, this prints TypeDBKnowledgeGraph. If unreachable, it falls back to KnowledgeGraph (JSONL).
4. Seed alias relations¶
This inserts alias-of relations for known threat actors (APT28, APT29, Lazarus Group, Volt Typhoon, Sandworm, Kimsuky, Turla, MuddyWater) and tools (Cobalt Strike, Metasploit, Mimikatz).
5. Configure config.yaml¶
Copy the default configuration:
Edit the TypeDB section:
typedb:
host: localhost
port: 1729
database: zettelforge
username: admin
password: password
backend: typedb
[!TIP]
config.yamlis in.gitignore. Safe for credentials. Environment variables override config file values.
6. Override with environment variables (optional)¶
export TYPEDB_HOST=localhost
export TYPEDB_PORT=1729
export TYPEDB_DATABASE=zettelforge
export ZETTELFORGE_BACKEND=typedb
Configuration resolution order (highest priority first):
- Environment variables (
TYPEDB_HOST,TYPEDB_PORT, etc.) config.yamlin working directoryconfig.yamlin project rootconfig.default.yamlin project root- Hardcoded defaults in
config.py
7. Verify the full stack¶
from zettelforge.memory_manager import MemoryManager
mm = MemoryManager()
# Store a test note
note, status = mm.remember(
content="APT28 deployed Cobalt Strike against NATO targets in 2026.",
source_type="test",
domain="cti"
)
print(f"Store: {status}")
# Query the graph
rels = mm.get_entity_relationships("actor", "apt28")
print(f"Graph relationships: {len(rels)}")
# Verify alias resolution through TypeDB
notes = mm.recall_actor("Fancy Bear")
print(f"Alias resolution: {len(notes)} notes found for 'Fancy Bear'")
Troubleshooting¶
TypeDB container fails to start¶
Common causes:
- Port 1729 already in use: lsof -i :1729
- Insufficient memory: TypeDB needs ~1GB RAM minimum
Connection refused on port 1729¶
# Check container health
docker compose ps
# Restart if unhealthy
docker compose restart typedb
# Wait for health check to pass
docker compose exec typedb curl -f http://localhost:8000/health
Fallback to JSONL backend¶
If TypeDB is unreachable, ZettelForge logs a warning and falls back to JSONL:
To force JSONL mode (skip TypeDB entirely):
Or:
[!WARNING] JSONL fallback stores identical relationship data but does not support TypeQL queries or the
alias-ofrelation type. Use the local JSON alias file (~/.amem/entity_aliases.json) for alias resolution in JSONL mode.
LLM Quick Reference¶
Task: Set up TypeDB as the ZettelForge knowledge graph backend.
Docker: docker compose up -d from the docker/ directory. Ports: 1729 (gRPC), 8100 (HTTP health). Volume: typedb-data.
Schema: Loaded automatically on first TypeDBKnowledgeGraph() instantiation. STIX 2.1 entity types: threat-actor, tool, malware, vulnerability, campaign, identity.
Aliases: python -m zettelforge.schema.seed_aliases inserts alias-of relations. Covers APT28, APT29, APT31, Lazarus, Sandworm, Volt Typhoon, Kimsuky, Turla, MuddyWater, Cobalt Strike, Metasploit, Mimikatz.
Config keys: TYPEDB_HOST (default "localhost"), TYPEDB_PORT (default 1729), TYPEDB_DATABASE (default "zettelforge"), TYPEDB_USERNAME, TYPEDB_PASSWORD, ZETTELFORGE_BACKEND ("typedb" or "jsonl").
Fallback: If backend: typedb and TypeDB is unreachable, falls back to JSONL with a warning. Set backend: jsonl to skip TypeDB entirely.
Health check: curl -f http://localhost:8100/health or docker compose ps for container status.