sk heavy industries

Hacking MemGPT

This one started with the MemGPT paper, "Towards LLMs as Operating Systems." The idea of treating the LLM as a first-class citizen of the OS, with its own memory hierarchy, was too good not to poke at. The paper turned out to be a bit different from what I expected going in, but I set it up anyway.

Getting started

Standard drill: a virtualenv, pip install the deps, drop in an OpenAI API key. The default setup is genuinely neat. It keeps recent context in working memory and pages older data out to a vector database, so the assistant "remembers" across a long conversation instead of forgetting the moment the window fills.

The problem: importing a database

The docs say you can preload archival memory from a .db file and then chat with it:

MemGPT docs: loading your own database

In practice that blew up:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 ...

Root cause

Reading the code, the importer opens every archival file as UTF-8 text and splits it into chunks. That's fine for .txt or .csv, but a .db is a binary SQLite file. Feeding binary bytes into a text decoder is exactly what produces that error.

Workaround and fix

CSV worked immediately, which confirmed the diagnosis:

main.py --archival_storage_files=somedata.csv

That loaded 13,625 chunks into archival memory with no complaints. The real fix is to special case the binary format instead of assuming everything is text:

if file.endswith('.db'):
    lines = read_database_as_list(file)

I cleaned that up and sent a pull request to the MemGPT maintainers.

Thanks to everyone who poked at this with me. Next up was MetaGPT. Until next time, sk out.