LIL Lab · Cornell University Preprint

Co-LMLM: Continuous-Query Limited Memory Language Models

Language models that keep facts in an editable external memory instead of their weights, and fetch them with a single continuous query read straight from the model's hidden state.

Yair Feldman, Linxi Zhao, Nathan Godey, Dongyoung Go, Yilun Hua, Kilian Q. Weinberger, Jennifer J. Sun, Yoav Artzi
Department of Computer Science, Cornell University · yairf@cs.cornell.edu

TL;DR

Large language models pack facts into their weights, where you can't inspect, edit, or remove them. Co-LMLM keeps facts in a separate, human-readable memory instead, and fetches them on the fly with a single query read straight from the model's hidden state, with no extra text to generate. Our 360M-parameter model achieves significantly lower perplexity than an off-the-shelf model trained on ~40× more data, and answers short factual questions on par with much larger frontier systems. Unlike an ordinary language model, whose knowledge is baked into its weights, the facts Co-LMLM uses are editable and attributable, while its language understanding is preserved.

  • 0.9-1.4 Lower perplexity than HF/SmolLM2 Co-LMLM reaches lower held-out perplexity than an off-the-shelf model that was trained on 40× more data.
  • 21.7 SimpleQA-Verified In line with gpt-4o-mini and above Claude Sonnet 4.5, at 360M parameters.
  • >18 pts Short-form QA & FactScore Gain over the same-size Standard baselines.
  • 2.2B Facts externalized Co-LMLM scales to a combined FineWeb-Edu + Wikipedia (~100B tokens) memory of about 2.2 billion free-form facts, factual externalization at massive scale.

01 · The problem

The limits of parametric knowledge

Standard large language models store what they know inside their parameters. That makes their knowledge hard to inspect, hard to attribute to a source, hard to edit, and hard to unlearn, and it feeds hallucination and low trustworthiness. Storing facts in the weights also spends model capacity: parameters busy memorizing facts could go toward reasoning and language ability instead. What we would want is a model whose knowledge we can actually see, source, correct, and remove.

  • Inspectsee exactly what the model knows
  • Attributetrace a fact back to its source
  • Editcorrect a fact without retraining
  • Unlearnremove a fact cleanly

02 · The idea

A continuous-query knowledge base

Co-LMLM (the Co- is for continuous-query) keeps a language model's facts in a separate, editable knowledge base (KB) instead of its weights, and reads from that memory while it generates. The KB pairs continuous vector keys with free-form text values, and Co-LMLM queries it with a single continuous vector read directly from its own hidden state.

That query is not text: it is the model's hidden state at a special <FACT> token (the marker Co-LMLM emits when it wants to look something up), so a lookup produces no decoded query tokens at all. Reading the query straight from the hidden state gives Co-LMLM four properties at once:

  • Full context: the hidden state uses the entire generation context, not a short decoded string.
  • Richer facts: free-form spans carry more knowledge than rigid subject–relation triplets.
  • Cheap lookups: no query tokens are ever decoded.

Co-LMLM builds on limited memory language models (LMLMs) (Zhao et al., 2025), that introduced the idea of externalizing facts to a human-readable knowledge base during pre-training instead of memorizing them in weights. The first LMLM, now called Rel-LMLM, stored facts as relational subject–relation–object tuples and looked them up with an explicit text query decoded token by token. That relational design is what limited it: it could only externalize facts that fit a simple tuple, it depended on Wikipedia's entity-centric articles, and every lookup spent extra decoded tokens and grew the context. Co-LMLM's continuous, free-form queries remove those limits.

One consequence turns up in the results: Co-LMLM externalizes facts at real scale, hundreds of millions from Wikipedia alone, and billions once the memory is grown to web-scale text.

Knowledge separation across three regimes. Left, navy: a Standard LLM with RAG retrieves over documents but still keeps its facts in its parameters. Middle, amber: Rel-LMLM externalizes facts to a relational knowledge base queried with an explicit, decoded text query. Right, coral: Co-LMLM externalizes facts to an unstructured index and retrieves them directly from the model's hidden state, with no decoded query.
Knowledge separation across three regimes. Standard LLM + RAG (retrieval-augmented generation) keeps facts in weights; Rel-LMLM uses a relational KB with a decoded query; Co-LMLM uses an unstructured index queried from the hidden state.

03 · How it works

Annotate → pre-train → infer

Co-LMLM is a single decoder-only Transformer that is simultaneously the language model and a dense retriever. We follow one concrete fact (that lycopeneLycopene is a type of nutrient known as a carotenoid. It has a bright red color and is found in various fruits, including tomatoes, grapefruits, apricots, watermelons, and papayas. belongs to the carotenoid family) through all three stages.

Overview of Co-LMLM in three bands. Top (annotation): the corpus is tagged with fact spans and paired questions, leaving the document text unchanged. Middle (pre-training): one decoder-only Transformer processes the annotated document and its questions, trained with next-token prediction over non-fact tokens plus a bidirectional InfoNCE loss that aligns the hidden state at the FACT token with the hidden state at the FACT-q question token. Bottom (inference): emitting a FACT token triggers dense retrieval using that hidden state, the retrieved span is inserted followed by a closing FACT tag, and decoding continues; no textual query is ever decoded.
The Co-LMLM recipe. Annotation (blue) · pre-training (amber) · inference (coral).

1 Annotate

Raw text gets its fact spans bracketed by <FACT></FACT>, and each span is paired with a natural-language question whose answer is the span, marked with a query token <FACT-q>. The document text itself is left unchanged.

Annotated text

Lycopene is a member of the <FACT>carotenoids</FACT> carotenoid family.

Paired question

What is lycopene a member of? <FACT-q>

2 Pre-train

One decoder is trained on two jointly-optimized objectives:

  • Next-token prediction, but not over the bracketed fact tokens. The model is deliberately not trained to memorize the externalized knowledge. The opening <FACT> is trained (so the model learns when to retrieve); the closing </FACT> is appended mechanically. This is the key design choice.
  • Bidirectional contrastive loss (InfoNCE). A contrastive loss teaches a fact's vector and its question's vector to point the same way: the hidden state at a span's <FACT> token and the hidden state at its question's <FACT-q> token are pulled together as a positive pair, while all other questions in the batch act as negatives. The loss averages both directions.

3 Infer

Decode normally. When the model emits <FACT>, take the last-layer hidden state at that position as the query, retrieve the top-1 fact span from the index, splice it in after <FACT>, append </FACT>, and resume.

Each retrieval costs one extra decoding step (the <FACT> token) and one index lookup, and grows the context by the span length. No textual query is ever decoded.

That index is built once, ahead of time: run the trained model over a corpus and store the hidden state at every <FACT> as a key, with the in-text span as its value.

Inference, step by step: what a lookup costs

Trace the retrieval loop on the lycopene example, watching the running cost: a lookup adds exactly one decoding step and grows the context by the retrieved span.

  1. 1 · Decode

    The model generates text normally: Lycopeneisamemberofthe

  2. 2 · <FACT> fires

    Instead of guessing the next word, the model emits <FACT>. Its last-layer hidden state at this position becomes the continuous query; no text is decoded.

  3. 3 · Retrieve top-1

    The query vector hits the index and returns the single best fact span: carotenoids.

  4. 4 · Splice & resume

    The span is inserted after <FACT>, a closing </FACT> is appended, and decoding continues: <FACT>carotenoids</FACT> carotenoid family. Total cost of the fact: one extra decoding step, one index lookup, plus the span's length added to the context.

04 · The annotation pipeline

Getting to scale

Annotating a full pre-training corpus with a frontier model would be prohibitively expensive. Co-LMLM distills the job into a three-stage pipeline that a frontier model seeds and two small, faithful-by-construction annotators finish. This scales cheaply to hundreds of billions of tokens.

The three-stage annotation pipeline. Left (seed): a frontier model annotates a small seed set in the format FACT q equals question a equals answer, span, close FACT. Middle (distill): two lightweight annotators are trained from the seed: a fact-span annotator that BIO-tags spans, and a question generator that emits a question–answer pair per span with the document prefix KV-cached and reused. Right (annotate): both annotators run over the full corpus to produce the Co-LMLM pre-training corpus.
Seed → distill two annotators → annotate the corpus.

1 Seed

Gemini-3.1-Pro annotates a small seed set of documents in the format <FACT q={question} a={answer}>{span}</FACT>.

2 Distill two annotators

A fact-span annotator, a ModernBERT-based masked language model that BIO-tags spans directly on raw text (labels each token begin, inside, or outside a span), and a question generator, a decoder-only model that emits a question–answer pair per span, with the document prefix KV-cached and reused across its spans.

3 Annotate at scale

The two distilled annotators run over the entire pre-training corpus, producing the annotated data that Co-LMLM trains on.

Why two annotators, not one generator?

  • Efficiency: the question generator emits only Q–A pairs, so the document is prefilled once and reused across its spans.
  • Faithful by construction: predicting spans as offsets guarantees the value is a verbatim substring of the text.
  • Creating the final index needs only two forward passes over new data: one by the fact-span annotator to find the spans, and one by Co-LMLM to embed each span into a key vector. (The question generator is used only when building pre-training data, not when indexing.)

Annotation guidelines

  • Spans are the narrowest self-contained substring that answers the question.
  • Each question works as a standalone search query. It fully resolves which entity or thing it is about, so it makes sense on its own without the surrounding document (and doesn't lean on facts stated later).
  • Answers vary the surface form of the span.

05 · Results I

Perplexity: language modeling & scaling the memory

Co-LMLM demonstrates its effectiveness by achieving significantly lower perplexity than other language models of similar size. It is measured on two held-out corpora, Simple English Wikipedia and a FineWeb split. We report two perplexity variants for Co-LMLM models: a Static (Oracle) variant that supplies the correct retrieved spans (an optimistic upper bound), and a Dynamic variant that performs actual lookups during decoding (the realistic setting).

Lower perplexity than model trained on 40× more FineWeb-Edu tokens

9.18.0 Simple-Wiki

12.011.1 FineWeb-Edu

Dynamic perplexity, HF/SmolLM2 → Co-LMLM. Index contains 2.2B facts from FineWeb and Wikipedia.

Lower perplexity than matched Standard LM baselines trained on Wikipedia

14.411.8 at 135M

14.010.5 at 360M

Simple-Wiki dynamic perplexity, Standard → Co-LMLM. Index contains 240M facts from Wikipedia.

Against a size- and token-matched Standard baseline, dynamic perplexity is lower at every model size. On Simple-Wiki, 14.4 → 11.8 at 135M, 14.0 → 10.5 at 360M, and 9.6 → 7.7 at 360M trained on 100B FineWeb-Edu tokens. We also compare our 360M Co-LMLM model trained on 90B FineWeb tokens to the HF/SmolLM2-360M model. On both Simple-Wiki and FineWeb-Edu test sets, Co-LMLM reaches significantly lower perplexity, even though it was trained with 40× less tokens. The evaluation is meaningful because the eval articles are not in pre-training, yet their facts are likely covered by the index in other surface forms. So both models must supply facts they never memorized verbatim, and the score isolates a clean thing for each: for Co-LMLM, how well it retrieves and annotates; for Standard, how well it memorized.

We additionally find that on Simple-Wiki, moving to the roughly 10×-larger index barely changes perplexity (a robust retriever). On the held-out FineWeb split, the Wiki-only index does poorly while the large combined index gives a substantial improvement, showing Wikipedia's limited coverage and the value of scaling the KB beyond it.

Bar chart of perplexity (lower is better) on Simple-Wikipedia, grouped into three model configurations: 135M, 360M, and 360M-FW. Each group has three bars: the Standard baseline, Co-LMLM with Dynamic retrieval (real lookups), and Co-LMLM with Static oracle retrieval (correct spans supplied). Co-LMLM's bars are lower than the Standard baseline in every group. A dashed line marks the off-the-shelf HF/SmolLM2 reference, trained on far more data.
Perplexity by configuration. Simple-Wikipedia perplexity (lower is better) for 135M, 360M, and 360M-FW. Each group compares the Standard baseline against Co-LMLM under Dynamic retrieval (real lookups) and Static oracle retrieval (correct spans supplied); the dashed line is the off-the-shelf HF/SmolLM2 reference. Uses the 240M-entry Wikipedia index.
Perplexity of Standard versus Co-LMLM-360M-FW on the Simple-Wiki and FineWeb test splits, comparing two index scales (a 240M Wikipedia-only index and a 2.2B Wikipedia plus FineWeb-Edu index) with two dynamic variants (one per index scale) plus a static oracle variant. The larger index barely changes Simple-Wiki perplexity but substantially improves FineWeb perplexity.
Scaling the index. 240M Wiki vs. 2.2B Wiki+FineWeb-Edu on the Simple-Wiki and FineWeb splits: two dynamic variants (one per index scale) plus a static oracle variant. To fit the far larger 2.2B-entry index in memory, it is quantized about 2.5× more aggressively than the 240M index used in the figure on the left.

06 · Results II

Factual precision

Co-LMLM lifts short-form QA and FactScore by more than 18 points over the matched Standard baselines, and training on FineWeb-Edu extends the gains beyond Wikipedia.

On SimpleQA-Verified, Co-LMLM-360M-FW scores 21.7, in line with gpt-4o-mini and above Claude Sonnet 4.5 and Grok 2 on the public leaderboard.

The table compares Co-LMLM against its respective (data-matched) Standard baseline, against Rel-LMLM, and against off-the-shelf reference models (marked *). Green subscripts are the absolute gain over the respective Standard baseline.

Factual precision. All metrics higher-is-better.
Model TriviaQA PopQA SimpleQA-Verified T-REx EM FactScore
HF/SmolLM2-135M * 14.718.91.336.19.0
Standard-135M 6.415.20.138.210.4
Rel-LMLM-135M 13.427.26.242.923.1
Co-LMLM-135M 28.4 +22.0 47.3 +32.1 18.2 +18.1 40.5 +2.3 35.0 +24.6
HF/SmolLM2-360M * 25.422.71.445.812.5
Standard-360M 7.516.20.346.310.0
Standard-360M-FW 18.618.91.350.511.9
Rel-LMLM-360M 15.626.65.647.422.9
Co-LMLM-360M 31.4 +23.9 46.5 +30.3 21.2 +20.9 47.4 +1.1 34.2 +24.2
Co-LMLM-360M-FW 36.9 +18.3 50.6 +31.7 21.7 +20.4 54.5 +4.0 33.3 +21.4
HF/SmolLM2-1.7B * 45.124.02.157.217.5

* Off-the-shelf reference models are trained on far more data (2T / 4T / 11T tokens for 135M / 360M / 1.7B). Green subscripts are the absolute gain over the respective (data-matched) Standard baseline. -FW = trained on FineWeb-Edu.

The largest lifts land on the harder short-form QA benchmarks and FactScore; T-REx EM moves less (+2.3 / +1.1 / +4.0), because the Standard baseline already scores relatively high on that controlled factual-completion task (38.2 / 46.3 / 50.5). It also comes out ahead of the earlier relational model, Rel-LMLM, on these benchmarks.

07 · Results III

Language understanding is preserved

Moving facts out of the weights doesn't cost natural-language understanding (NLU). NLU is measured 5-shot on CSQA, HellaSwag, PIQA, SIQA, and ARC-Easy; we report the average (CoreAvg). Co-LMLM stays on par with its Standard counterpart while factuality jumps.

135M

38.5 vs 38.4

Co-LMLM vs. Standard

360M

40.6 vs 41.8

Co-LMLM vs. Standard

360M-FW

55.1 vs 55.0

Co-LMLM vs. Standard

FactScore versus NLU tradeoff scatter. Co-LMLM substantially improves factual precision while keeping NLU comparable to similar-size models; FineWeb-Edu training helps.
Factuality vs. NLU. Co-LMLM improves factual precision while keeping NLU comparable to similar-size models; FineWeb-Edu training helps.

08 · Unlearning

Clean unlearning by editing memory

Because Co-LMLM's knowledge is an editable memory, forgetting a fact is a memory operation, not a retraining job: you delete its entries from the KB. Reaching ideal forgetting needs no retraining and costs no utility, unlike parameter-editing methods.

Tested on TOFU (following Rel-LMLM's setup), the goal is to forget a designated forget set while preserving utility, measured by forget quality: statistical indistinguishability from a model trained only on the retained data. Co-LMLM reaches ideal forgetting (p-value > 0.05) while preserving utility, with no additional training, whereas training-based unlearning (e.g. NPO) updates parameters and trades forgetting against utility.

Machine unlearning on TOFU. Co-LMLM forgets via direct knowledge-base operations with no training, reaching ideal forgetting (p greater than 0.05) while preserving utility, whereas NPO trades utility away for forgetting.
Unlearning on TOFU. Co-LMLM (memory edit, no training) vs. NPO (parameter update).

09 · Ablations

Ablations

Four studies isolate where Co-LMLM's gains come from: it stacks with RAG, the memory really carries the knowledge, a continuous query beats a decoded one, and deciding when to query is a promising lever.

9a

Complementary with RAG

RAG and Co-LMLM solve different problems and stack: RAG expands the inference-time context by retrieving documents, while Co-LMLM externalizes free-form factual knowledge into an editable memory during pre-training. With RAG applied to both, Co-LMLM + RAG still leads the RAG-augmented Standard baseline on the short-form QA benchmarks and matches it on knowledge completion, a viable combined path.

Co-LMLM vs. / with RAG. Higher is better. RAG = BM25 (a classic keyword retriever), top-4 100-word Wikipedia passages prepended.
Model TriviaQA PopQA SimpleQA-Verified T-REx EM
HF/SmolLM2-360M * 25.422.71.445.8
HF/SmolLM2-360M * + RAG 52.236.917.986.7
Standard-360M-FW 18.618.91.350.5
Standard-360M-FW + RAG 42.533.915.386.4
Co-LMLM-360M-FW 36.950.621.754.5
Co-LMLM-360M-FW + RAG 48.851.827.886.5

* Off-the-shelf, trained on far more data.

9b

Is the knowledge really out of the weights?

Turn the memory off and factual accuracy collapses. Disabling the KB at inference forces the model onto its parameters alone, and factuality drops substantially. For Co-LMLM-135M, FactScore falls 35.0 → 18.0 and PopQA 47.3 → 15.4, with similar large drops at 360M and 360M-FW. The knowledge genuinely resides in external memory, rather than being duplicated in the weights.

No-KB ablation: full → without KB (change).
Model TriviaQA PopQA SimpleQA-Verified T-REx EM FactScore
Co-LMLM-135M 28.4 → 4.7 −23.7 47.3 → 15.4 −31.9 18.2 → 1.0 −17.2 40.5 → 21.7 −18.8 35.0 → 18.0 −17.0
Co-LMLM-360M 31.4 → 6.0 −25.4 46.5 → 13.5 −33.0 21.2 → 0.7 −20.5 47.4 → 27.4 −20.0 34.2 → 18.7 −15.5
Co-LMLM-360M-FW 36.9 → 9.2 −27.7 50.6 → 17.3 −33.3 21.7 → 0.5 −21.2 54.5 → 33.3 −21.2 33.3 → 16.2 −17.1
9c

Continuous query vs. decoded query

A continuous hidden-state query beats a decoded text query on every metric while costing far less to form. LMLM-Asker is a Co-LMLM variant that decodes a free-form <QUESTION>…</QUESTION> and retrieves with that text, trained on the same corpus. Co-LMLM beats it on every accuracy metric and is far cheaper: forming a query costs Co-LMLM ~2.2 ms (a single <FACT> hidden-state forward, no decoding) vs. ~28 ms for the Asker (dominated by decoding a ~13-token question), about 13× less model-side overhead. Decoded questions are constrained by the structure of language; continuous queries can learn an arbitrary retrieval mechanism.

Continuous vs. natural-language queries. Red = degradation vs. Co-LMLM. Times are model-side query-formation cost per retrieval; the shared faiss (vector-search library) lookup is excluded.
Model TriviaQA PopQA SimpleQA-Verified T-REx EM FactScore LM overhead (ms)
LMLM-Asker-360M-FW 15.4 −21.5 43.2 −7.4 7.5 −14.2 38.5 −16.0 25.0 −8.3 28.6 (13× more)
Co-LMLM-360M-FW 36.9 50.6 21.7 54.5 33.3 2.2

Model-side query-formation cost per retrieval

LMLM-Asker 28.6 ms
Co-LMLM 2.2 ms

≈ 13× less overhead.

9d

When to query is the next lever

Making the model always look up before answering improves accuracy further. Forcing a retrieval before answering (the query content is still model-generated) helps across scales and benchmarks, e.g. Co-LMLM-360M-FW improves TriviaQA 36.9 → 43.3 and T-REx EM 54.5 → 59.3. Retrieval is partly bottlenecked by the timing decision (when to query) and there is headroom to improve it. (At 135M, PopQA is roughly flat.)

Enforced-lookup ablation: base → with EnforceLookup (change).
Model TriviaQA PopQA SimpleQA-Verified T-REx EM
Co-LMLM-135M 28.4 → 31.7 +3.3 47.3 → 47.2 −0.1 18.2 → 19.3 +1.1 40.5 → 49.8 +9.3
Co-LMLM-360M 31.4 → 33.4 +2.0 46.5 → 46.9 +0.4 21.2 → 21.5 +0.3 47.4 → 53.0 +5.6
Co-LMLM-360M-FW 36.9 → 43.3 +6.4 50.6 → 53.3 +2.7 21.7 → 27.6 +5.9 54.5 → 59.3 +4.8

10 · Conclusion

Takeaways & Limitations

Summary

  • A scalable way to train LLMs for verifiable and controllable knowledge use, with an annotation pipeline applicable to hundreds of billions of tokens at modest cost. Beyond pre-processing, training departs only modestly from conventional LLM training, which is known to scale.
  • A flexible free-form span substrate for studying how externalized knowledge scales across domains, memory sizes, and retrieval mechanisms, a foundation for knowledge scaling laws.
  • It advances factuality, transparency, and controllability: qualities today's LLMs lack.

Open problems

  • Experiments remain modest in model and data scale; larger-scale pre-training and downstream adaptation are future work.
  • Factual evaluations mainly target Wikipedia-style knowledge, though FineWeb-Edu shows the pipeline extends further.
  • Building the index is a one-time compute cost; refreshing it after fine-tuning or continual learning is an open problem. This is especially important for post-training, and is left for future work.

11 · Cite

Authors & citation

Co-LMLM is from the LIL Lab (Cornell Language, Interaction, and Learning Lab), Department of Computer Science, Cornell University.

Yair Feldman, Linxi Zhao, Nathan Godey, Dongyoung Go, Yilun Hua, Kilian Q. Weinberger, Jennifer J. Sun, Yoav Artzi

Department of Computer Science, Cornell University · Contact: yairf@cs.cornell.edu

Author contributions
  • Yair Feldman: designed and implemented the core method, trained the models, implemented the Standard and LMLM-Asker baselines, ran the perplexity and loss evaluations, and wrote the paper.
  • Linxi Zhao: designed and implemented the Rel-LMLM baseline, ran the FactScore, TOFU, QA, and NLU evaluations, and wrote the paper.
  • Nathan Godey: helped design the pre-training runs.
  • All authors took part in discussions, planning, and revisions.
BibTeX
@misc{feldman2026colmlmcontinuousquerylimitedmemory,
      title={Co-LMLM: Continuous-Query Limited Memory Language Models},
      author={Yair Feldman and Linxi Zhao and Nathan Godey and Dongyoung Go and Yilun Hua and Kilian Q. Weinberger and Jennifer J. Sun and Yoav Artzi},
      year={2026},
      eprint={2607.07707},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2607.07707},
}