FlyHash for LLM Agent Memory: An Empirical Validation and a New Application

Mohan Bheemadolu, Chrisogonas O. OdhiamboarXiv 2026

This paper explores whether a bio-inspired hashing algorithm, modeled after the fruit fly's olfactory system, can improve how Large Language Model (LLM) agents store and retrieve memories. While the "quality" of these hashes is impressive, the authors provide a sobering reality check on the practical resource trade-offs involved when compared to industry standards like HNSW.

TL;DR

FlyHash, a bio-inspired hashing scheme, significantly outperforms standard SimHash in retrieval quality per active bit for LLM agent memory. However, this accuracy comes at a cost: FlyHash is slower and more memory-intensive to implement naively, and it is still dominated by graph-based methods like HNSW at typical production scales.

What Problem Does This Paper Address?

LLM agents need "long-term memory" to stay coherent over long interactions. The standard way to do this is by turning text into dense vector embeddings and searching them using Approximate Nearest Neighbor (ANN) methods. As the number of memories grows, storing these high-dimensional vectors becomes expensive in terms of both memory and compute.

Binary hashing is a potential solution, compressing vectors into short bitstrings. A specific algorithm called FlyHash—inspired by how fruit flies process smells—has shown promise in general benchmarks. This paper asks if FlyHash actually works for LLM memory and, more importantly, if its theoretical quality advantage translates into real-world performance gains for engineers.

Methods

The authors compare two primary hashing paradigms:

  1. SimHash (Standard): Uses a dense random projection. Each bit in the output code is independent and has a ~50% chance of being active.
  2. FlyHash (Bio-inspired): Uses a sparse random projection into a much larger "pool" of dimensions (Kenyon cells), followed by a winner-take-all (WTA) competition where only the top $k$ most active cells "fire" (become 1s).

A major contribution of this paper is the matched-active-bit protocol. The authors identified a common pitfall in previous literature where FlyHash was compared unfairly to SimHash by conflating the total pool size ($m$) with the number of active bits ($k$). By ensuring both methods use the same number of active bits, they isolate the true quality of the hashing function.

Datasets

The study evaluates performance across four datasets spanning text and image modalities:

  • GloVe: Word vectors (the primary dataset for statistical validation).
  • MiniLM: Sentence embeddings (representative of modern LLM agent memory).
  • scikit-learn digits & MNIST: Image benchmarks to ensure robustness across modalities.
Table 1: Datasets used for the main comparison (Section 4.1).

Additionally, the authors introduced a synthetic "named persona" benchmark with 6,000 memories and 150 queries. Unlike standard benchmarks that use embedding similarity as a proxy for relevance, this dataset uses ground-truth labels (e.g., "What is Jordan's favorite color?") to test if hashing preserves actual semantic utility.

Key Insights and Ideas

  • The "Quality vs. Resource" Gap: A hash function can be "better" (higher precision per bit) while being "worse" for a computer to handle. Because FlyHash codes are sparse but live in a large pool (e.g., 2,000 dimensions), a naive implementation is 10–70x slower than SimHash.
  • Sparse-Set Recovery: The authors show that by treating FlyHash codes as sets of indices rather than dense bit arrays, they can recover most of the speed loss, though SimHash remains 2–5x faster.
  • Low-Bit Dominance: FlyHash’s advantage is most pronounced when the bit budget is extremely tight. As you add more bits, the gap between FlyHash and SimHash narrows.
  • HNSW is still the Baseline: For most practitioners, HNSW (Hierarchical Navigable Small World) remains the superior choice. Hashing only becomes the "right tool" when you are operating under extreme, explicit storage constraints where even HNSW's overhead is too high.

Key Results

FlyHash consistently beat SimHash in Mean Average Precision (mAP) across all datasets and bit budgets.

Table 2: Main results: mAP (mean ± std over 10 seeds) for FlyHash vs. SimHash across four datasets and five bit budgets.
  • Quality: On the GloVe dataset at $k=16$ bits, FlyHash achieved an mAP of 0.196 compared to SimHash’s 0.047—a 4.2x improvement.
  • Robustness: The advantage held up under the new "named persona" benchmark, proving the quality gain isn't just an artifact of embedding circularity.
  • Latency: In an end-to-end agent demo, the embedding step (MiniLM) took ~14ms, while the FlyHash search took ~6ms, showing that hashing is a viable, if not yet optimal, component of the pipeline.

Limitations and Future Work

The authors are refreshingly honest about FlyHash's current limitations:

  • Memory Overhead: Even with sparse indexing, FlyHash requires more memory per record than bit-packed SimHash because storing an integer index is "thicker" than storing a single bit.
  • Scale: The HNSW comparison was conducted at a relatively small scale (5,000 records). The relative benefits of hashing might shift at billion-scale deployments.
  • Algorithmic Variants: The paper focused on the "base" FlyHash. Future work could integrate BioHash (learned projections) or DenseFly (densified outputs) to further close the resource gap.

Summary updated

Abstract

Large language model (LLM) agents increasingly rely on external memory stores to retain information across conversations, typically via dense vector embeddings searched with approximate nearest-neighbor methods. The fruit fly's olfactory circuit computes a locality-sensitive hash of sensory input using a strikingly different mechanism - sparse random projection followed by winner-take-all competition - and prior work (Dasgupta et al., 2017) showed this scheme, dubbed FlyHash, preserves neighbor structure better per bit than conventional random-hyperplane hashing (SimHash) on several benchmarks. We apply FlyHash, to our knowledge for the first time, to LLM agent memory retrieval, and ask three questions a practitioner actually needs answered: does the quality advantage hold under a correctly matched-bit protocol (it does, robustly, across 10 seeds and four datasets spanning two modalities, with one specific, previously undocumented comparison pitfall identified and corrected along the way); does that advantage translate into real memory and latency savings, including against the dense-vector indexing (HNSW) practitioners default to today (no: at equal bits FlyHash's codes are larger and slower to compare than SimHash's, and HNSW dominates both hash methods at ordinary scale; a sparse-set comparison we introduce recovers most but not all of a naive latency gap, leaving hashing's practical case narrower and more specific than the quality result alone implies); and does the advantage survive genuine, non-circular agent-memory relevance labels rather than the nearest-neighbor-by-embedding proxy this literature otherwise relies on (it does). We report all three answers precisely, including the two that narrow rather than flatter the headline result, and release our implementation, a working agent-memory demo, and a full account of the methodological pitfalls we found and corrected.
BibTeX
@misc{bheemadolu2026flyhash,
  author = {Mohan Bheemadolu and Chrisogonas O. Odhiambo},
  title = {{FlyHash for LLM Agent Memory: An Empirical Validation and a New Application}},
  year = {2026},
  eprint = {2611.05791},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.05791},
}
Figure