I’m a SQL Guy - Not an MD-File-System Guy
I store everything I can in SQL. I’ve been doing it that way since the mid-’90s. But I was reluctant to store documents and images as BLOBs until I started using a React tech stack and getting some help from my pal Claude. Once I got it working, all I can say is wow! Who cares if a database has steady, predictable growth? We have shared media across the organization. It’s worth it.
Your AI's memory belongs in a database, not in a pile of Markdown files. Do both if you want. Migrate your organization’s MDs to SQL, if you can even find ’em all. Categorize by user, function, and scrape them for business rules.
Markdown Shmarkdown
Right now every AI coding tool wants a Markdown file. CLAUDE.md, AGENTS.md, memory banks, a folder full of notes. I have some too, dropped in by my AI coding assistant. For one developer working in one repo, maybe it works. Not scalable, people.
Markdowns are rules. And they are exceptions to the rules. But what’s an exception to an exception called? A rule? A double negative? But I thought three lefts made a right? (They do, but you’ll end up on the wrong street.) Confusion is the enemy of AI.
Keep the Markdown - put it in a column
The models read and write it beautifully, and a memory that says "always quote this customer delivered, never FOB mill" is best written as a sentence. So keep the Markdown. Just store it in a column, and wrap that column with structured fields the database can index, join, permission and expire. The Markdown needs context. The database delivers. Everybody wins.
Why won’t you just shut up about SQL?
Because SQL is awesome. I’m still pissed off we didn’t have a database class at Dartmouth, even if it was in the 1980s. Instead we wasted our time trying to figure out how to structure a few lines of graphics routines that wouldn’t break when compiled. Dumb. Had to get that one off my chest.
Skip ahead if you already know this. Simply put, SQL databases are tables which consist of strongly typed fields, aka columns; individual columns or sets of columns can have indexes for ultra-fast sorting and lookups. Sure am glad I wasted months of my precious youth writing sorting routines. Not. And then there are primary keys and foreign keys - the magic of connected data with rules. So elegant. But only when normalized. Do all you AI researchers out there even realize that the training data from the mainframe guys, which you clearly used, has created some really stupid database designs?
Moving on. SQL views are these amazing SQL queries on the raw tables that merge your data into usable data sets. We have one at Nova that has SKU-level revenue and gross profit by customer transaction with geolocation data. Totally rad, dude.
A few words of advice for all you wannabe SQL guys
AI doesn’t know how to build great database models. Don’t trust it. Use primary keys with no embedded information in the key. Call it id or {table name}_id. It’s an int or unique identifier depending on the expected table size. Don’t be tempted to denormalize; just connect the tables with joins. Use views. Never use fixed char fields; use varchar, and don’t cap it. Use defaults for field values - so powerful.
And then there are stored procedures and triggers - shit is happening, all the time. Agents running SPs. Updates hitting triggers that do real stuff. So cool.
The memory data model
OK, enough database talk - back to AI. In the first article we logged everything in evt. tables: what happened. The mem. tables hold what the system learned from it.
Here's the abstract model. Notice it reuses the tables from Step One - Actors, Category, Module and Event. Don't build new ones. Memory hangs off the exact same keys as events, and that's the whole point.
- Memory Type - what kind of memory this is. A scientific fact, a procedure, a lesson learned, a customer's preference. They behave very differently, and the type table holds the rules for each kind
- Memory - one row per thing the system knows. Its type, who it applies to, which module, the Markdown body, a confidence score and a status
- Memory Source - the events that taught it. Every learned memory has to be able to point at its evidence. If it can't, it's a rumor
- Memory Use - every time a memory gets loaded into an agent's context, and how things turned out
Follow the advice above, and prefix everything with mem. so you can find it. There are more memory types than you'd think - they each get their own article.
Scope - whose memory is it?
Some things the whole company knows: how we handle a credit hold. Some things belong to a module: order entry always defaults the ship-to to the customer’s normal location. And some things belong to one person: Bob had given a deal to his pet customer because of… well, we don’t actually know what Bob did now, do we? Make module and actor nullable on the memory row and you get that whole hierarchy for free - global, module, personal.
Permissions come along for the ride. An agent working for a sales rep shouldn't be loading memories that belong to accounting. In a database that's a WHERE clause. In a folder full of Markdown, it’s a “let Claude take the wheel” and pray.
Point at your data, don't copy it
Here's a trap I can see happening. Somebody writes a memory that says "Charge Acme National $2,500/MBF for the 6x6 DF FOHC that’s at the reload." Now you have two prices - one in your invoice history table and one in a memory. They used to pay $2,800/MBF. Now the AI has to be smart enough to ask again, wasting everyone’s time. Isn’t Acme late again paying us? Yup. They are.
So when a memory is about a specific customer, vendor or item, link it with a small join table: mem.MemoryCustomer, mem.MemoryVendor, mem.MemoryItem. Each one is just two foreign keys. The memory says "check the invoice history before finalizing an order for this customer," and the link points at the customer records where the real numbers live. What if the salesperson that set the memory misspoke? That’s why we have to build an interactive and iterative algorithm. That’s why we need to forget the stupid things we sometimes say. Occasionally, we need a delete button - just ask my wife.
Teaching the system to forget
Every learned memory carries a confidence score and a last-used date - shall we add a dumbness score, honey? - and those two (or three) columns are how the system forgets. Stale rules fade, contradicted rules drop, and the raw events get boiled down into (life) lessons before they age out. That's a whole article on its own. It’s how we get rid of dumb stuff.
Why bother?
- It's searchable. "Show me everything the system believes about order entry" is one query
- It's auditable. Every memory traces back to the events and the actors that created it
A memory that keeps everything can't find anything. Store it where you can query it. What street am I on now, anyways? Prepare to make a right, and then another left. Whew. Back on track.
References
- Tulving, E. (1985). How many memory systems are there? American Psychologist, 40(4), 385-398.
- Squire, L. R. (2004). Memory systems of the brain: A brief history and current perspective. Neurobiology of Learning and Memory, 82(3), 171-177.
- Kumaran, D., Hassabis, D. & McClelland, J. L. (2016). What Learning Systems do Intelligent Agents Need? Complementary Learning Systems Theory Updated. Trends in Cognitive Sciences, 20(7), 512-534. Free preprint.
- Park, J. S. et al. (2023). Generative Agents: Interactive Simulacra of Human Behavior. arXiv:2304.03442.
- Packer, C. et al. (2023). MemGPT: Towards LLMs as Operating Systems. arXiv:2310.08560.
- Claude Code documentation. Memory - how CLAUDE.md files work.