For the more recent games, it's memory, but for the older ones, I mostly just remember the really important stuff, ask all my players what they recall, and then check my old notes about the session (which invariably can't predict what the players would do). Then I pretty it up and type it out.
For instance, in Savannah Knights, everything was pretty much as it happened, except for some of the dialogue being polished to make us sound like better roleplayers.

I wrote SK only a few months after we played the game, so it was still fresh.
For Tides of Homeland, my other storyhour, I played the game back about 3 years ago, so I'm having to scour everyone who played in the game to put together a coherent picture of what happened. A couple of times it's been like, wait, _why_ did they go there? I know they fought the benevolent death cultists, but how did they figure out where they were? I thought the PCs were in _this_ part of the country at that time.
Eventually, though, we figure it out, and it all makes a bizarre sort of nostalgic sense.