Schema einer Gedächtnisschicht: Aus einem Wort entsteht eine Suchanfrage, die mit Millionen Schlüsseln in einer großen Tabelle verglichen wird; nur die wenigen besten Treffer geben ihre Werte weiter an die nächste Schicht des Modells.

Memory Layer

A memory layer is a component in an AI model that stores knowledge in a huge lookup table instead of spreading it across the entire model. For each request, the model retrieves only a handful of entries from it, allowing it to store vastly more factual knowledge without slowing down when answering.

An AI model consists of many computational stages arranged one after another, known as layers. Most of these layers perform their full computation for every single request. A memory layer works differently: it is a very large table containing millions of entries. For each request, the model searches through it for only a handful of matching entries and continues computing using only those. Picture it like a giant reference work from which you don’t read every page, but instead look up three specific keywords. The rest of the table simply goes unused for that request.

Why knowledge costs space but doesn’t have to cost computation time

Knowledge in an AI model is normally stored in its parameters. Parameters are numbers that are adjusted during training and that store the learned relationships. Until now, an uncomfortable rule applied: more knowledge means more parameters, and more parameters mean more computational work per answer. A model meant to know more facts therefore becomes more expensive to operate.

Memory layers break this coupling apart. The table is allowed to grow gigantic without the computation time growing along with it. That’s because only a few rows are ever used per request. Research from Meta has shown that a model with memory layers performs significantly better on factual questions than an equally fast model without them.

The key point is the difference between two kinds of costs. Storage space is relatively cheap, while computation time per answer is expensive, because it is incurred on every single user request. Memory layers shift the burden from the expensive resource to the cheap one. This is precisely why they are of interest to companies that operate models for millions of people.

Search keys, values, and the glance into the table

The table consists of pairs. Each entry has a key and a corresponding value. The key is a sequence of numbers that describes what this entry is responsible for. The value is the information the model goes on to use, likewise represented as a sequence of numbers.

When a word arrives in the text, the model generates a search query from it. This search query is compared against the keys. The four to eight best-matching entries win out. Their values are combined and passed on to the next layer. All the other millions of entries are left untouched entirely.

Comparing against millions of keys would actually be very costly in itself. That’s why the keys are broken down into groups, so that the search proceeds in two smaller steps. The whole thing is trained just like the rest of the model: the entries adjust themselves during learning. Nobody types in which entry contains which fact. A common misconception, therefore, is to imagine the table as a dictionary with readable sentences. In reality it only contains numbers, which cannot be directly interpreted by humans.

Related concepts: Mixture of Experts and external databases

Memory layers appear mainly in technical articles and in news about new model architectures. You rarely encounter them as a product name, but rather as an explanation for why a model stays fast despite its size. Mixture of Experts works similarly, where a model activates only some of its building blocks per request. Both approaches follow the same basic idea, except that with memory layers, the activated unit is a single table entry.

This should be distinguished from two other things that are also called memory. One is the context window: the amount of text a chatbot can currently keep track of within a conversation. The other is connected databases in which a model searches for actual documents while generating an answer. A memory layer, by contrast, is permanently built into the model and is learned during training.

The technique becomes practically noticeable wherever factual knowledge matters. Such models answer questions about capital cities, years, or technical terms more reliably. For providers, it also matters that large tables are easier to distribute across multiple graphics cards than classical layers. In the coming years, the term is likely to appear more often whenever the discussion turns to models that are efficient yet knowledge-rich.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.