The context window problem
Large language models have a fundamental limitation: finite context windows. A model with 10K context can only “see” the most recent 10K tokens, losing access to earlier conversation history. Current solutions include:
- Longer context models: Expensive to train and run (128K+ context)
- Summarization: Lossy compression that discards detail
- Retrieval-augmented generation: Retrieves selected context for a query; embedding and caching choices determine which computations repeat
The HAT approach
HAT takes a different approach: exploit known structure.
AI conversation data can be organized into a hierarchy that retrieval methods may exploit:
- Session conversation boundary
- Document topic or turn
- Chunk individual message
HAT uses centroid-based beam search through that structure. Recall depends on the data and search settings; the reported 100% values below are observations on synthetic hierarchical data, not a guarantee.
Research question. Can known conversation structure make retrieval beyond a model’s context window useful and efficient?
The 60K-token example reports retrieval over a corpus about six times the stated 10K native context allocation. It does not increase the model’s native window. The HAT repository clarifies that the reported recall is synthetic-data retrieval recall, with downstream QA evaluation still unestablished in this record.
Comparing index structures
| Aspect | HNSW | HAT |
|---|---|---|
| Organization | Proximity graph constructed from vectors | Supplied session-document-chunk hierarchy |
| Routing | Graph traversal | Centroid-based beam search |
| Additional structure | Graph links | Container links, centroids and timestamps |
| Main comparison limit | Recall depends on graph and search settings | Recall depends on hierarchy quality and beam settings |
The difference in assumptions:
HNSW: “Here are points, I’ll learn to navigate them.”
HAT: “I know these are containers. I’ll use what I know.”
These are different structural assumptions, not a ranking of all retrieval workloads.
The hippocampus analogy
The following biological analogy motivates the design; it is not a validated model of human memory:
| Human Memory | HAT Equivalent |
|---|---|
| Working memory (7±2 items) | Current context window |
| Short-term memory | Recent session containers |
| Long-term episodic | HAT hierarchical storage |
| Memory consolidation (sleep) | HAT consolidation phases |
| Hippocampal indexing | Centroid-based routing |
Algorithm
HAT organizes points into a tree with four levels:
- Global root
- Session conversation boundaries
- Document topic groupings
- Chunk leaf nodes with points
Each non-leaf container maintains:
- Centroid: Mean of descendant embeddings
- Children: Pointers to child containers
- Timestamp: For temporal locality
Beam search query
def hat_query(query, k, beam_width):
beam = {root}
for level in [Session, Document, Chunk]:
candidates = []
for container in beam:
for child in container.children:
score = cosine(query, child.centroid)
candidates.append((child, score))
beam = top_b(candidates)
return top_k(beam)
Traversal cost: O(b × d × c) container comparisons for beam width b, tree depth d and examined branching factor c, excluding the vector-comparison cost. This becomes logarithmic in n only when depth grows as log n and beam width and branching remain bounded; it is not a general recall or runtime guarantee.
Experimental results
Experiment A: HAT vs HNSW on synthetic hierarchical data
Setup: 1000 points = 20 sessions × 5 documents × 10 chunks, 128 dimensions.
| Metric | HAT | HNSW | Δ |
|---|---|---|---|
| Recall@1 | 100.0% | 76.0% | +24.0 percentage points |
| Recall@5 | 100.0% | 72.0% | +28.0 percentage points |
| Recall@10 | 100.0% | 70.6% | +29.4 percentage points |
| Build Time | 30ms | 2.1s | 70× faster |
| Query Latency | 1.42ms | 0.49ms | HNSW 3× faster |
Tradeoff: In this experiment HAT had higher reported recall and faster construction; HNSW had lower query latency. The appropriate tradeoff depends on recall requirements and baseline tuning. The known hierarchy favors HAT, and the table does not establish how the methods compare on unstructured data or at matched recall.
Recall@k measures retrieval of the relevant top-k items under the benchmark’s ground truth. The exact query set, ground-truth construction, HNSW tuning, hardware, run count and uncertainty are not recorded in this article. The 70× construction ratio is from the rounded table values.
Experiment B: Synthetic scale series
| Points | HAT Build | HNSW Build | HAT R@10 | HNSW R@10 |
|---|---|---|---|---|
| 500 | 16ms | 1.0s | 100% | 55% |
| 1000 | 25ms | 2.0s | 100% | 44.5% |
| 2000 | 50ms | 4.3s | 100% | 67.5% |
| 5000 | 127ms | 11.9s | 100% | 55% |
HAT reports 100% recall in these four synthetic settings. The 1,000-point row differs from Experiment A in both timing and HNSW recall. It is retained as a separate reported series; the source record does not identify the settings or seeds that explain that difference.
Experiment C: Retrieval for a 60K-token corpus
Reported setup: 2,000 synthetic messages (~60K tokens), sentence-transformers embeddings, and a proposed gemma3:1b integration. The recorded recall concerns retrieved messages, not a scored LLM answer benchmark.
| Metric | Value |
|---|---|
| Total tokens | 60,000 |
| Native context sees | 10,000 (16.7%) |
| Reported retrieval recall | 100% |
| Retrieval latency | 3.1ms |
| Memory usage | 3.3 MB |
Retrieving a matching message is a prerequisite for useful question answering, but does not guarantee a correct answer. The repository explicitly separates these retrieval figures from downstream LLM task accuracy.
Reconciling the experiments with the original graphics
The original overview graphics mention a 500K-point, 1,536-dimensional study and 15M tokens while reusing values also shown in a 1,000-point, 128-dimensional build comparison. A run-level mapping connecting those scales is not supplied here. Do not apply the small-benchmark build times or recall to the larger-scale claim.
The original build graphic gives 31 ms versus 2,094 ms (about 67.5×). Its phrase “over two orders of magnitude” is incorrect: that would require more than 100×. The rounded 30 ms/2.1 s journal table yields 70×. These are separately presented values; this revision does not assert they are the same run.
Reported routing variants
Subspace Routing (Grassmann geometry):
- Recall: −8.7% vs centroids
- Latency: +11.8%
Learnable Routing Weights:
- Recall: −2% to +4%
- Latency: ~0%
Interpretation: The reported routing variants did not consistently improve on centroids in these settings. The original recall changes above do not specify relative-percent versus percentage-point units; raw comparisons are needed to settle that distinction. These results do not establish that centroid routing is sufficient for every hierarchy or dataset.
Consolidation phases
Inspired by sleep-staged memory consolidation:
| Phase | Operations | Time |
|---|---|---|
| Light (α) | Recompute centroids | 9ms/1K |
| Medium (β) | + Merge/split containers | 9ms/1K |
| Deep (δ) | + Prune empty, optimize layout | 9ms/1K |
| Full (θ) | Complete rebuild | 10ms/1K |
Implementation
HAT is implemented in Rust with Python bindings via PyO3:
from arms_hat import HatIndex
# Create index
index = HatIndex.cosine(1536)
# Add messages with session/document structure
index.new_session()
id = index.add(embedding)
# Query
results = index.near(query_embedding, k=10)
# Persistence
index.save("memory.hat")
Contributions
- A centroid-based index that uses supplied session-document-chunk structure
- Synthetic retrieval comparisons with explicit construction/query tradeoffs
- A small-scale retrieval pipeline for a corpus beyond a stated context allocation
- Reported negative results for more elaborate routing variants
Conclusion
HAT explores whether supplied conversation structure can help retrieval. The synthetic results motivate testing on realistic workloads, matched recall/latency settings and downstream tasks. This web revision adds scope and accounting corrections without rerunning experiments; the linked PDF is the original paper version.
Get started
HAT is available as the arms-hat crate:
- Rust:
cargo add arms-hat— crates.io | docs.rs - Python: See the repository for current binding and installation instructions
- Source: github.com/Lumi-node/HAT
- Landing Page: research.automate-capture.co/hat
Part of the ARMS (Attention Reasoning Memory Store) project at Automate Capture Research.