Memory and Storage
Miku uses an intelligent storage system based on SQLite to manage data efficiently and independently.
Short-Term Memory (Chat Memory)
Chat history is stored in the chat_memory.db file.
- User-Based Isolation: Each user's chat data is separate. User A will not know what User B has said to the bot.
- History Limit: The bot only remembers a certain number of recent conversation turns (according to the
MAX_HISTORYvariable) to maintain context without slowing down the system. - Resource Management: Attached image data will be automatically deleted after a period of time (TTL) to avoid bloating the database size.
TTL (Time To Live) Mechanism
The bot has a background process to clean up memory:
- Delete Inactive Users: If a user does not message the bot for the
MEMORY_IDLE_TTL_SECONDSduration, their entire history is cleared. - Delete Old Image Data: Only heavy image data blobs are deleted; text content is retained to save space.
Other Databases
ban_control.db: Stores information about users banned from using the bot.callnames.db: Stores personalized nicknames (how the bot and user address each other).
Logging
The system uses the JSONL (JSON Lines) format to save chat logs (chat_replay.jsonl). This format makes retrieving and reviewing conversations (Replay) extremely fast and easy for administrators.