How Memory Works
Every conversation turn is stored in~/.hiroshi/hiroshi.db the moment it occurs. When a new message arrives, the memory engine runs two retrieval branches in parallel and fuses their results before passing context to the agent:
- Vector search — Hiroshi calls Ollama’s embed API (default model:
nomic-embed-text) to generate a vector embedding for the incoming message. It then performs a cosine similarity lookup against all stored embeddings, ranking matches by semantic closeness. - FTS5 keyword search — A SQLite FTS5 virtual table indexes the full text of every message. Hiroshi runs a keyword query against it to catch exact and near-exact term matches that vector search might rank lower.
- Reciprocal Rank Fusion (RRF) — The two result sets are merged using RRF scoring: vector results contribute 70% of the final score and FTS5 results contribute 30%. Duplicates are removed and the top matches are injected into the agent’s context window before generating a response.
Memory Files
Hiroshi organizes all persistent state under~/.hiroshi/:
| File | Description |
|---|---|
hiroshi.db | The main SQLite database. Contains the history table, the history_fts FTS5 virtual table, and the history_vectors blob table. |
memory/MEMORY.md | A Markdown summary of long-term learnings, decisions, and configurations. Updated automatically by the dreaming sweep when SOP is enabled. |
memory/DREAMS.md | A log of each memory consolidation cycle — timestamps, how many records were processed, and consolidation status. |
memory/YYYY-MM-DD.md | Raw daily conversation logs exported by the cron scheduler. One file per day, named by date. |
Clearing History
In terminal mode, use the/clear command to wipe the conversation history for the current session:
history, history_fts, and history_vectors tables. It does not delete MEMORY.md or the daily log files — those remain on disk.
Memory Consolidation (Dreaming)
When the SOP engine is enabled, Hiroshi runs a background memory consolidation sweep every 12 hours. The sweep reads recent conversation history fromhiroshi.db, summarizes it using the configured LLM, de-duplicates repeated context, and writes a refined summary into MEMORY.md. Reasoning logs from each cycle are appended to DREAMS.md.
This process runs automatically — you do not need to trigger it manually. Enable it by setting [sop] enabled = true in config.toml.
Configuring the Embedding Model
The embedding model is configured under the[ollama] section in ~/.hiroshi/config.toml:
embedding_model and pull the model with Ollama before starting Hiroshi:
/api/embed endpoint.
Automatic Database Backups
The cron scheduler automatically backs uphiroshi.db to ~/.hiroshi/backups/ every Sunday at 3:00 AM. Each backup is named with a timestamp: hiroshi_backup_YYYY-MM-DD_HH-MM-SS.db. Backups are created using SQLite’s VACUUM INTO command, which produces a clean, defragmented copy of the database.
See Cron Tasks for more on the weekly maintenance schedule.
The database runs in SQLite WAL (Write-Ahead Logging) mode, which allows concurrent reads while writes are in progress. You can safely inspect
hiroshi.db with any external SQLite client — such as the sqlite3 CLI or DB Browser for SQLite — while Hiroshi is running, without risking corruption or lock contention.