8. Transformers8.2 Aside: Content-Addressable Memory / Key-Value Store

Section 8.2
Aside: Content-Addressable Memory / Key-Value Store

To build intuition for the following section we take a detour to discuss content-addressable memories (also known as key-value stores or vector databases). Imagine that we have a database containing paired keys and values, \((k, v)\). For example, the keys may represent pets’ names and the values their animal type such as (“Fluffy”, “cat”) and (“Bluey”, “dog”). The actual keys and values would typically be encoded as vectors. This is illustrated graphically in Figure 110. Now to retrieve a value from the database we provide a query, say “Bluie”. Note that an exact matching key does not appear in the database due to the misspelling, but we can still return the value “dog” associated with the closest key, “Bluey”. Mathematically we find \(i^{\star} = \argmax \left\{q^T k_i \mid i = 1, \ldots, n\right\}\) and return \(v_{i^\star}\) where the inner-product between the query and keys is used to determine similarity.

Example of a content-addressable memory or key-value store. A query is compared against keys in a database. The value associated with the matching key (or close
Figure 110: Example of a content-addressable memory or key-value store. A query \(q\) is compared against keys \(k_1, \ldots, k_n\) in a database. The value \(v_i\) associated with the matching key (or closest matching key) \(k_i\) is returned.