In an epidsode of the dystopian near-future series, Black Mirror, a small, implantable device behind the ear grants the ability to remember, access, and replay every moment of your life in perfect detail, like a movie right before your eyes.

Theodore Berger, a biomedical engineer at the University of Southern California, can’t promise that level of perfect recall—perhaps for the better—but he is working on a memory prosthesis. The device, surgically implanted directly into the brain, mimics the function of a structure called the hippocampus by electrically stimulating the brain in a particular way to form memories—at least in rats and monkeys. And now, he’s testing one that could work in humans.

Berger’s device hinges on a theory about how the hippocampus transforms short-term memories, like where you deposited your keys, into long-term memories—so you can find them later. In his early experiments, he played a tone and then puffed air in a rabbit's face, causing it to blink. Eventually, just playing the tone would make the rabbit blink, just like Pavlov’s famous salivating dogs. Berger recorded the hippocampus’ activity with electrodes, and as the rabbits learned to associate the tone with the air puff, patterns in those signals changed in a predictable way.

“The hippocampus was being actively engaged by and modifying its firing pattern by the training,” says Gregory Clark, Berger’s former mentee and a professor of biomedical engineering at the University of Utah. Berger calls this firing pattern a space-time code: It’s defined by where the neurons are in the brain, as well as when they fire. “As the space-time code propagates into the different layers of the hippocampus, it’s gradually changed into a different space-time code,” Berger says. “And we don’t understand why, but when it comes out, that space-time code is what the rest of the brain can recognize and use as a long-term memory.”

The outgoing code represents the memory that the rest of the brain uses as a signal—for the rabbits to blink their eyes when they hear the tone. And Berger says he’s been able to mathematically model the general rule the hippocampus uses to convert short-term memories into long-term memories.

With the general rule in hand, he built rats an artificial hippocampus. To do that, he first had to teach rats to complete a memory task: He would present a rat with one of two levers to press, then distract it with a light. When the turned back to the task, it was trained to press the lever opposite the one it originally pressed, to demonstrate it remembered.

All the while, Berger and his team recorded the firing from the hippocampus, noting which space-time codes corresponded with the lever-pressing memory. They took the data from the incoming and outgoing firing patterns in the hippocampus and developed a mathematical model that could predict the outgoing space-time code corresponding to the incoming one. Later, when Berger gave the memory task rats a drug that blocks memory formation, he used his device to electrically stimulate the brain with the pattern of pulses—the outgoing space-time code—predicted by his model.

Then the rat would press the correct lever. “They recall the correct code as if they’ve created it themselves,” Berger says. “Now we’re putting the memory back into the brain.” Berger has also tried out the prosthesis in rhesus monkeys, in a part of the prefrontal cortex. This area is involved in executive functions like using memories to solve a novel problem. In that context, the implant improved the monkey’s memory, too.

But could a similar implant in a human really work? “All of these prosthetics interfacing with the brain have one fundamental challenge,” says Dustin Tyler, a professor of engineering at Case Western Reserve University. “There are billions of neurons in the brain and trillions of connections between them that make them all work together. Trying to find technology that will go into that mass of neurons and be able to connect with them on a reasonably high-resolution level is tricky.”

Even cochlear implants—which simulates a range of sound frequencies by stimulating the auditory nerve with a couple dozen electrodes—can’t mimic sound perfectly. Scientists are far from simulating entire memories, with all their sensory inputs, especially with an electrical code using only about 100 electrodes. But that didn’t stop a new startup called Kernel from syncing up with Berger, partially bankrolling his research and naming him their Chief Science Officer.

Kernel’s earliest goals are to bring Berger’s implant to the market as a medical device that can help the memory impaired—Berger is currently conducting a human trial with a version of the device, and says that so far, the patients in his human trial are performing well on memory tests. But ultimately, CEO Bryan Johnson wants Kernel to develop devices—implantable in a simple outpatient procedure—that enhance human intelligence in areas like attention, creativity, and focus.

That goal would venture into new waters for regulatory agencies: Are these medical devices or consumer devices, and who should regulate them? Under the Food and Drug Administration’s terms, an implant would count as a medical device if its intent is to diagnose or treat a medical condition or to affect the structure or function of the body. But a subdermal implant that merely suggests it could improve concentration or creativity may slip through the FDA’s regulatory grasp, like the dietary supplements of brain stimulators.

Johnson did not comment on which direction he’ll take Kernel’s yet-unmade devices: It will depend on the individual device, its applications, and potential side effects. Sure, all medical devices and drugs come with possible side effects. Now we wait to see if this one will be a benign annoyance, or the inspiration for a new, chilling episode of Black Mirror.