Persistent, incremental, searchable persona knowledge base — the data layer between raw sources and persona training.
Architecture: MemPalace (storage + search) + Knowledge Graph (relationships + timeline) + Karpathy LLM Wiki (knowledge accumulation)
Dependency chain: data sources → persona-knowledge → anyone-skill / persona-model-trainer
Trigger phrases:
Not suitable when:
Create a new persona dataset:
bash
python scripts/init_knowledge.py --slug {slug} --name "Display Name"
This creates ~/.openpersona/knowledge/{slug}/ with:
text
~/.openpersona/knowledge/{slug}/
dataset.json # metadata: slug, name, created_at, stats
.mempalace/ # MemPalace local data (per-dataset isolation via palace_path)
palace/ # MemPalace internal store (ChromaDB + KG)
sources/ # immutable source file backups
.source-index.json # per-file metadata: hash, import time, line count, PII flags
wiki/ # Karpathy wiki (LLM-maintained derived artifact)
_schema.md # wiki maintenance rules
identity.md
voice.md
values.md
thinking.md
relationships.md # generated from Knowledge Graph
timeline.md # generated from Knowledge Graph
_contradictions.md
_changelog.md
_evidence.md
MemPalace palace structure:
hall_facts — Identity (background, career, education)hall_events — Memory (key events, turning points)hall_preferences — Personality (values, preferences, boundaries)hall_discoveries — Procedure (mental models, decision heuristics)hall_voice — Interaction (vocabulary, rhythm, humor, emotional temperature)Gate: Confirm slug and display name with the user before proceeding.
Import data sources into the dataset. Can be called multiple times for incremental ingestion.
bash
python scripts/ingest.py --slug {slug} --source <path> [--adapter <name>] [--since <date>]
Three adapters cover all supported formats:
SourceAdapterDetectionObsidian vaultuniversalDirectory containing .obsidian/ or *.md filesGBrain export diruniversalMarkdown directory with .raw/ sidecar dirs.md / .txt / .csv / .pdf``universalFile extension.jsonl / .json``universalFile extensionGBrain JSON exportuniversal``.json with memories key or --entity flagWhatsApp .txt exportchat_exportMatches WhatsApp timestamp patternTelegram result.json``chat_exportJSON with chats keySignal exportchat_exportJSON with Signal message formatiMessage .db``chat_exportSQLite with message + handle tablesX (Twitter) archivesocialDirectory containing data/tweets.jsInstagram archivesocialDirectory containing content/posts_1.json
Ingest pipeline (per source):
[{role, content, timestamp, source_file, source_type}]After each source is ingested, report:
text
✅ whatsapp-2024.txt → 1,247 messages (892 assistant turns)
PII: none detected
KG: +3 entities, +7 relationships
→ sources/whatsapp-2024.jsonl
After ingesting new data, the agent reads MemPalace content and Knowledge Graph relationships, then builds or updates the wiki pages following the Karpathy LLM Wiki pattern.
This phase is driven by agent intelligence (SKILL.md instructions), not by automated scripts. The LLM decides which pages to update, how to phrase entries, and how to tag evidence.
[L1:source] — direct quote, traceable[L2] — reported/paraphrased, verifiable[L3:inferred] — reasonably inferred from multiple signals[L4:inspired] — impression-based[[page]] wikilink syntax_contradictions.md with both sides cited_changelog.md_evidence.mdWhen the user asks a question about the persona:
Run periodically or before export:
bash
python scripts/lint_wiki.py --slug {slug}
Checks:
[[links]] (referenced page doesn't exist)references/wiki-schema.md for full spec)#Each page follows this template:
markdown
# {Page Title}
> One-sentence summary of this page's scope.
## Content
{Structured content with [L?:source] evidence tags and [[backlinks]]}
## Sources
- {source_file}: {what was extracted} [L?]
## See also
- [[related_page]]
relationships.md and timeline.md are generated from the Knowledge Graph, not written freehand:
python
from mempalace.knowledge_graph import KnowledgeGraph
kg = KnowledgeGraph(palace_path)
kg.timeline(slug) # → chronological event list for timeline.md
kg.query_entity(slug) # → current relationships for relationships.md
After generating, the agent may annotate with evidence tags and additional context.
Generate a training/ directory compatible with persona-model-trainer:
bash
python scripts/export_training.py --slug {slug} --output training/
Each export is automatically versioned ( v1, v2, …). Override with --version:
bash
python scripts/export_training.py --slug {slug} --output training/ --version v3
List export history:
bash
python scripts/export_training.py --slug {slug} --list
# v1 2026-04-01 10:00 142 turns sha256:a3f9c2d1 3 sources
# v2 2026-04-10 14:22 198 turns sha256:c7d2e1f3 4 sources
Output:
text
training/
raw/ # copied from sources/ (authentic voice, unmodified)
conversations.jsonl # generated from wiki pages (structured Q-A pairs)
profile.md # summarized from wiki identity/voice/values
metadata.json # slug, source count, turn count, export version + hash
How each file is built:
training/raw/ — direct copy of sources/*.jsonl and sources/*.txt files
training/conversations.jsonl — the agent reads wiki pages and generates distilled user/assistant turn pairs representing the persona's voice, knowledge, and values
training/profile.md — 300-500 word character sheet derived from identity.md, voice.md, values.md
training/metadata.json — slug, name, subject_type, created_at, source_count, total_words, distilled_turns, raw_files + versioning fields:
export_version — version tag (e.g. "v2")export_hash — SHA-256 of conversations.jsonl (e.g. "sha256:c7d2e1f3...")source_snapshot — {filename: sha256_hash} dict of all source files at export timeExport history is appended to dataset.json → export_history[] after each run.
Downstream traceability: persona-model-trainer's pipeline.sh reads export_version and export_hash from metadata.json and injects them as dataset_version / dataset_export_hash into training_summary.json, forming a complete provenance chain from source data to trained model adapter.
This output is directly consumable by persona-model-trainer's prepare_data.py — no changes needed downstream.
→ Next step — train a local persona model:
bash
bash skills/persona-model-trainer/scripts/pipeline.sh \
--slug {slug} \
--model google/gemma-4-E4B-it \
--source ./training \
--method mlx \ # or: unsloth (NVIDIA GPU) / colab (no GPU)
--preset gemma4 \
--probes ./training/probes.json
Full guide:
persona-model-trainer/references/pipeline-guide.md
Query the dataset using MemPalace's semantic search and Knowledge Graph:
bash
# Semantic search across all stored memories
mempalace search "how does this person handle conflict" --wing {slug}
# Knowledge Graph: look up an entity's relationships
python scripts/query_kg.py --slug {slug} --entity "Tom"
# Knowledge Graph: shortest path between two entities
python scripts/query_kg.py --slug {slug} --path "Tom" "Alice"
# Knowledge Graph: overall statistics
python scripts/query_kg.py --slug {slug} --stats
# Knowledge Graph: JSON output (for programmatic use)
python scripts/query_kg.py --slug {slug} --entity "Tom" --json
# Wake-up summary (~170 tokens)
mempalace wake-up --wing {slug}
The agent can also search programmatically during wiki build or distillation:
python
from mempalace.searcher import search_memories
results = search_memories("vocabulary patterns", palace_path="~/.openpersona/knowledge/{slug}/.mempalace/palace")
Ongoing dataset management:
sources/ + re-index → run wiki lint to flag orphaned contentpython scripts/lint_wiki.py --slug {slug} — health checkpython scripts/init_knowledge.py --slug {slug} --stats — show current statsls ~/.openpersona/knowledge/ — all available datasetsToolPurposeBashRun init, ingest, export, lint scripts; MemPalace CLI commandsReadLoad source files, wiki pages, dataset.jsonWriteUpdate wiki pages, write training exportsWebSearchFetch public figure data for ingestion
ScriptPurposescripts/init_knowledge.pyInitialize knowledge directory + MemPalace wing + KGscripts/ingest.pyUnified ingestion: adapter dispatch + PII scan + dedup + MemPalace + KGscripts/export_training.pyExport sources/ + wiki → training/ directoryscripts/lint_wiki.pyWiki health check: broken links, contradictions, coverage gapsscripts/query_kg.pyKnowledge Graph query: entity lookup, shortest path, statistics
AdapterSourcesFormatuniversalObsidian vault, GBrain export, .md, .txt, .csv, .pdf, .jsonl, .jsonAll pure file readingchat_exportWhatsApp / Telegram / Signal / iMessage.txt / JSON / SQLite (special parsing)socialX (Twitter) / Instagram archiveJS wrapper stripping + archive dirs
references/wiki-schema.md — Karpathy wiki structure specification and maintenance rulesreferences/source-formats.md — supported data source formats and adapter details