Skip to content

FlyHash for LLM agent memory: empirical validation and a new applicationFlyHash for LLM Agent Memory: An Empirical Validation and a New Application

Hugging Face Daily Papers· arXiv:2611.05791· Mohan Bheemadolu, Chrisogonas O. Odhiambo·Indexed by this site · 14 days ago· Originally publishedTools

Quick read

Evaluation and benchmarks

Based on the paper PDF (AI-generated); refer to the original

The authors apply FlyHash to LLM agent memory retrieval, reporting that it has better mAP than SimHash at matched active bits, but is not advantageous on resources and does not match HNSW.

Questions
LLM agent memory commonly uses dense vectors plus approximate nearest neighbor retrieval, with storage and computation growing with scale. FlyHash was previously shown to outperform SimHash per bit on several benchmarks, but it has never been used for agent memory retrieval, and three questions remain unanswered: the comparison protocol, resource overhead, and real relevance labels.
Methods
The authors compare FlyHash and SimHash under a matched-active-bit protocol: fixing the FlyHash pool size m=2000 and the number of winners k, with SimHash taking a k-bit output. They measure mAP@R on 4 datasets with 10 seeds, supplemented by paired statistical tests, hyperparameter sweeps, memory and latency measurements, an HNSW system comparison, and an agent memory benchmark with constructed relevance labels.
Experiments and results
The authors report that FlyHash outperforms SimHash in all 20 comparisons across 4 datasets and 5 bit budgets (Table 2), with the largest relative advantage at low bits (4.2× at GloVe k=16); however, under dense representation it uses about 250 bytes/item and about 13 ms per query, slower than SimHash; HNSW at the 5,000-item scale is better than both hashes in both quality and latency (Table 8).
Limitations and future work
The limitations listed by the authors include: sparse comparison only partially narrows the resource gap; the HNSW comparison is only a single scale and single configuration; SIFT1M, DenseFly, BioHash and quantization methods were not evaluated; the MiniLM corpus has only 100 sentences; end-to-end latency has only single-point data; the annotated benchmark uses template-synthesized text and TF-IDF+SVD embeddings (Section 6).
Experimental setupFlyHash · GloVe (glove-wiki-gigaword-100)、MiniLM (all-MiniLM-L6-v2) sentence embeddings et al. · mAP@R、bytes/record et al.
Evaluated models
FlyHash
Benchmarks
GloVe (glove-wiki-gigaword-100)MiniLM (all-MiniLM-L6-v2) sentence embeddingsscikit-learn digitsMNIST (via OpenML)labeled agent-memory benchmark (6,000 memories, 150 queries)
Metrics
mAP@Rbytes/recordms/query
AI summaryThe authors state that this is the first use of FlyHash, inspired by the Drosophila olfactory circuit, for LLM agent memory retrieval, and that under a matched-bit protocol and real relevance labels, its nearest-neighbor structure preservation is better than SimHash, and this holds stably across 10 random seeds and 4 datasets spanning two modalities. However, at equal bits, FlyHash encodings are larger and comparisons are slower, and at ordinary scale HNSW outperforms both hashing methods, so the practical memory and latency benefits do not hold. The authors released the implementation and an agent memory demo.

The authors state that this is the first use of FlyHash, inspired by the Drosophila olfactory circuit, for LLM agent memory retrieval, and that under a matched-bit protocol and real relevance labels, its nearest-neighbor structure preservation is better than SimHash, and this holds stably across 10 random seeds and 4 datasets spanning two modalities. However, at equal bits, FlyHash encodings are larger and comparisons are slower, and at ordinary scale HNSW outperforms both hashing methods, so the practical memory and latency benefits do not hold. The authors released the implementation and an agent memory demo.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors apply FlyHash to LLM agent memory retrieval, addressing three questions: answer quality, resource overhead, and true relevance.

    Core question: Can FlyHash, a hash scheme inspired by the Drosophila olfactory system, hold up in LLM agent memory retrieval—is its quality truly better than SimHash, does it bring actual resource savings, and does the advantage still exist under real relevance labels.

    • Setting and motivation: LLM agents increasingly store facts, preferences, etc. in external memory; the mainstream approach embeds each memory as a dense vector and retrieves with an approximate nearest neighbor index such as FAISS, with storage and computation growing with embedding scale and dimensionality, so more compact hash representations are needed (Section 1).
    • Shortcomings of existing methods: Dasgupta et al. (2017) proposed FlyHash and claimed it outperforms SimHash in terms of matching output bits on SIFT, GloVe, and MNIST, but the authors state that to their knowledge no one has used FlyHash for LLM agent memory retrieval, and that the literature generally uses "embedding nearest neighbors" as a relevance proxy, lacking multi-seed, multi-dataset, multi-modal statistical validation (Sections 1–2).
    • Core observation: The authors find that "the same number of bits" has three non-interchangeable meanings (active bits, physical storage, query resources); conflating FlyHash's total width m with the active bit count k secretly lowers FlyHash's effective bit count, a previously unflagged comparison trap (Section 3.2, Appendix A).
    • What the paper proposes: The authors claim to be the first to apply FlyHash to LLM agent memory retrieval, providing a comparison protocol matching active bits, statistical validation with 10 seeds×4 datasets, a resource and HNSW system comparison, a benchmark with constructed relevance labels, and an end-to-end agent memory demonstration (Sections 3–4).
  2. What related research exists?

    Related work is divided into four groups: the original FlyHash algorithm and its improvements, graph-index ANN, LLM memory architectures, and quantization and other hashing/sparse retrieval.

    The original FlyHash algorithm and improvements

    • Dasgupta, Stevens & Navlakha (2017): proposed FlyHash—sparse random projection to about 2,000 "Kenyon cells" followed by taking the top ~5% activations—and reported that it outperforms SimHash on SIFT, GloVe and MNIST at matched output bit counts; this paper directly reuses its algorithm and the GloVe and MNIST datasets (Section 2).
    • DenseFly (Sharma & Navlakha, 2018): densifies FlyHash's sparse output to improve similarity search accuracy; this paper does not implement it and lists it as future work (Section 2).
    • BioHash (Ryali et al., 2020): replaces random projection with learnable local-rule projections, reports retrieval accuracy better than the random version, and established the mAP metric this paper uses; the authors state that their contribution is not a better hash function but the application and validation of the training-free random version (Section 2).
    • FlyNN (Ram & Sinha, AAAI 2022): applies the fruit-fly olfactory circuit to federated nearest-neighbor classification; there is also a general FlyHash implementation on PyPI (Huang), which the authors cite to explain that the implementation itself is not a new contribution (Section 2).

    Graph-index approximate nearest neighbor

    • HNSW (Malkov & Yashunin, 2016/2020): builds a navigable graph over full-precision vectors for greedy search, and is the default method in most production vector retrieval systems; the authors note that HNSW and hashing target different design points (sublinear queries vs. compactness per record), and the main results only compare FlyHash against SimHash at matched bits, with a separate HNSW system comparison in Section 4.6 (Section 2).

    LLM memory architectures and RAG

    • Mem0 (Chhikara et al., 2025), Zeng et al. (2024), Du (2026): production-oriented long-term memory frameworks, structured memory representations, and a survey of agent memory; that literature notes that flat similarity retrieval in long-horizon tasks suffers from redundancy and relational blind spots, and the authors state that this paper evaluates hashing only within the flat similarity retrieval paradigm and does not propose a structured memory architecture (Section 2).

    Quantization, other hashing, and sparse retrieval

    • Product Quantization (Jégou et al., 2010) and optimized variants, RaBitQ (Gao & Long, 2024): the quantization line; the authors cite literature stating it is stronger than both hashes at most operating points, and this paper does not compare against it (Section 2).
    • Cross-Polytope LSH (Laarhoven, 2020): has a better asymptotic query exponent, but the authors cite Cai (2016) and Laarhoven (2020) as saying that at the medium scale of this paper SimHash remains competitive because of its lower per-hash overhead, so SimHash was chosen as the baseline (Section 2).
    • BM25, SPLADE (Formal et al., 2024): term-based sparse retrieval, a different concept from FlyHash's sparse binary codes and a complementary line, outside this paper's scope (Section 2).

    Baselines and benchmarks: the quality baseline is SimHash, the system baseline is FAISS IndexHNSWFlat; the datasets are GloVe, MiniLM sentence embeddings, scikit-learn digits, and MNIST, plus a self-built annotated agent memory benchmark of 6,000 memories and 150 queries (Tables 1, 8–10).

    Author positioning: none of the above work applies FlyHash to LLM agent memory retrieval, nor provides the validation depth of this paper—multiple seeds, multiple datasets, multiple modalities, plus hyperparameter ablations; this paper fills the intersection gap of new application and empirical rigor (Section 2).

  3. How does the paper address this problem?

    Under the matched-active-bit protocol, compare the mAP@R of FlyHash and SimHash, then measure resource overhead, the HNSW comparison, and the true-label benchmark.

    Overall approach: apply the original FlyHash algorithm directly to the agent memory retrieval setting, use a matched-active-bit protocol to isolate hash function quality, then separately answer the resource question and the real relevance question.

    Hash schemes and formalization

    • SimHash: dense random matrix W (elements i.i.d. standard normal), output hsim(x) = sign(Wx) ∈ {0,1}k, each of the k bits independently thresholded, each bit being 1 with probability about 1/2 (Section 3.1).
    • FlyHash: sparse random projection matrix P (each row connects only to ⌈s·d⌉ input dimensions, s=0.10, weights uniformly {−1,+1} on connections), then k-winners-take-all: hfly(x) = WTAk(Px) ∈ {0,1}m, exactly k bits are 1; m is the pool size (default 2,000), k is the bit budget (Section 3.1).

    Evaluation protocol

    • Metric: mAP@R, with the relevant set defined as the top R nearest neighbors by exact Euclidean distance on the original embeddings, AP computed by ranking on hash code Hamming distance and then averaged over queries; the authors state it rewards ranking true nearest neighbors higher more than recall@k (Section 3.2).
    • Matched-active-bit protocol: for each bit budget k, FlyHash fixes m=2,000 and winner ratio k/m, while SimHash outputs exactly k bits, so both methods have the same number of active bits; the authors point out that the naive approach (treating m as the "bit count" scanned and fixing the winner ratio at 5%) makes FlyHash's effective active bits far fewer than SimHash's, which is the core trap this paper centers on (Section 3.2).
    • Three "bit count" distinctions: equal active bits (used for quality comparison), equal physical storage, equal query resources; the latter two are handled in Sections 4.3–4.4, 4.6 (Section 3.2).

    Data and statistics

    • Datasets: GloVe (5,000 items, 100 dimensions, main dataset), MiniLM sentence embeddings (100 items, 384 dimensions), scikit-learn digits (1,797 items, 64 dimensions), MNIST (5,000/70,000 items, 784 dimensions); GloVe and MiniLM are L2-normalized, pixel values scaled to [0,1] (Table 1).
    • Statistical protocol: main results with 10 seeds, hyperparameter sweep with 3 seeds, varying only the projection matrix initialization and fixing the query set; report mean±standard deviation, and use "mean difference > 2 times pooled standard deviation" as a robustness heuristic; for the GloVe main results, additionally perform paired analysis—t interval and 95% CI from 10,000 bootstrap resamples, Cohen's dz, Wilcoxon signed-rank and 10,000 sign-flip permutation test (Section 3.4).

    System integration and annotated benchmark

    • Agent memory system: remember(text)/recall(query, k) text interface wrapping a sentence embedding model and FlyHash storage, connected to a tool-calling loop with two tools, save memory / recall memory; the authors describe a three-turn interaction example where the agent answers via recall memory by retrieving a fact stored several turns earlier (Section 3.5).
    • Annotated benchmark: 150 synthetic named personas, each with 10 facts and 3–4 paraphrase templates per fact, 6,000 memories in total; queries name a persona, and the relevant set is fixed by construction as the 3–4 paraphrases of that persona's that fact, with labels not derived from embedding distance; embeddings use TF-IDF plus truncated SVD (256 dimensions) (Section 4.7).
  4. What experiments did the paper conduct?

    4 datasets × 5 bit budgets mAP comparison, paired statistics, 36-configuration hyperparameter sweep, memory and latency measurements, HNSW comparison, and the annotated benchmark.

    Experimental setup

    • Methods under test: FlyHash (default s=0.10, m=2,000) and SimHash, compared at matched active bits k ∈ {16, 32, 64, 128, 256}; the system baseline is FAISS IndexHNSWFlat (M=32, efConstruction=200, efSearch ∈ {16, 64, 128}) (Sections 3.1, 4.6).
    • Datasets: GloVe (5,000 items, mAP@100), MiniLM (100 items, mAP@20), digits (1,797 items, mAP@50), MNIST (5,000 items, mAP@100); the annotated agent memory benchmark has 6,000 memories and 150 queries (Tables 1, 10).
    • Metric and criterion: mAP@R (the relevant set is the exact Euclidean top-R nearest neighbors of the original embeddings; the annotated benchmark uses constructed labels); the robustness criterion is a mean difference > 2 times the pooled standard deviation; for GloVe, paired t/bootstrap CI, Cohen's dz, Wilcoxon and permutation tests are also run (Sections 3.2, 3.4).
    • Repetitions: main results 10 seeds; hyperparameter sweep 3 seeds; latency measurement 50 queries; end-to-end latency 30 repetitions (Sections 3.4, 4.3, 4.5).
    • Resource measurement: brute-force comparison on 5,000 GloVe items, with the exact float32 baseline at 400 bytes/item and 0.78 ms/query (Table 5).

    Main results

    Excerpt from Table 2 (mean ± standard deviation over 10 seeds):

    Swipe horizontally to read the table

    DatasetkFlyHash mAPSimHash mAPRobust
    GloVe, mAP@100160.196 ± 0.0070.047 ± 0.006Yes
    GloVe, mAP@1002560.705 ± 0.0060.469 ± 0.007Yes
    MiniLM, mAP@20160.310 ± 0.0130.214 ± 0.026Yes
    MiniLM, mAP@202560.753 ± 0.0130.587 ± 0.016Yes
    digits, mAP@50160.456 ± 0.0150.119 ± 0.031Yes
    MNIST, mAP@1002560.563 ± 0.0040.450 ± 0.010Yes
    • Advantage in all combinations: the authors report that in all 20 (dataset × bit budget) combinations FlyHash outperforms SimHash and all are judged Robust, with no exceptions (Section 4.1).
    • Paired statistics: on GloVe, the Wilcoxon and permutation p-values for each k are all about 0.00195 (the smallest reportable value at n=10), and Cohen's dz is 14.8–40.8; the authors call this the main evidence (Table 3).
    • Larger advantage at low bits: the relative advantage (mAPfly/mAPsim) shrinks as k increases, from 4.2× at k=16 on GloVe to 1.5× at k=256; Figure 1 shows that the ratio curves for all four datasets decrease monotonically and always stay above the parity line (y=1), with GloVe and MNIST having the largest initial advantage and the MiniLM curve being the flattest (Section 4.1, Figure 1).

    Resource overhead: quality advantage is not resource advantage

    • FlyHash is worse under dense representation: FlyHash's code width is m=2,000 bits, about 250 bytes/item in dense storage and almost independent of k, with brute-force queries at about 13 ms/query, 10–70× slower than SimHash at the same k; SimHash at k=16 is 2 bytes/item and 0.19 ms/query (Table 5).
    • Sparse set comparison partially recovers: using the fact that Hamming distance equals 2k−2|A∩B| and ranking by the intersection of active indices, speed improves 10–22× over dense comparison and scales correctly with k; but SimHash is still 2–5× faster, and explicit index storage is about 16× that of SimHash's bit-packed codes, which the authors call a partial improvement rather than a solved problem (Table 6).

    HNSW system comparison

    • HNSW is comprehensively better: on 5,000 GloVe items, HNSW at efSearch=64 gives mAP@100 of 0.9862, 0.060 ms/query, and 671.5 bytes/item; on the same data, FlyHash (sparse comparison) at k=256 gives mAP 0.697, 10.13 ms/query, and 512 bytes/item, while SimHash at k=256 gives 0.476 and 0.70 ms/query (Tables 8–9).
    • Authors' interpretation: at this scale HNSW is better than both hashes on quality and latency simultaneously, with memory only about 1.6× that of exact storage; the applicable scenario for hashing is narrowed to extreme storage budgets, and the authors say practitioners without special memory constraints should choose HNSW (Section 4.6).

    Annotated agent memory benchmark and end-to-end demonstration

    • Advantage persists under true labels: with 6,000 memories, 150 queries and 10 seeds, FlyHash mAP goes from 0.195 ± 0.014 at k=16 to 0.392 ± 0.009 at k=256, better than SimHash at every budget (0.345 ± 0.011 at k=256) and all Robust; the absolute values are lower than in Table 2, which the authors attribute to the task itself being harder, and the two sets of numbers should not be compared directly (Table 10).
    • End-to-end latency: for a single representative query over the 6,000-item corpus, repeated 30 times, total latency is 20.5 ms, of which MiniLM embedding is 14.1 ms (68.8%) and FlyHash hashing plus sparse ranking is 6.4 ms (31.2%); the authors say the embedding stage is the main overhead and that this is only single-point data, not a benchmark (Table 7).

    Other ablations and analyses

    • Hyperparameter sweep: s ∈ {0.05, 0.10, 0.20} × m ∈ {500, 1000, 2000, 4000}, 36 configurations in total (GloVe, 3 seeds), all exceeding the SimHash baseline; s=0.20 is slightly better at large k, and returns diminish or turn negative once m exceeds about 8× k (Table 4, Figure 2).
    • Weight modes: on GloVe, the mAP difference between signed weights {−1,+1} and binary {0,1} grows from 0.0042 at k=16 to 0.0577 at k=256, and both modes outperform SimHash (Table 11).
    • Excluded hypotheses: L2 normalization, weight definition, and the recall@k metric are not the cause of the reproduction discrepancy; the real cause is the confounding of k and m (Appendix A).
    • Retracted hypothesis: the authors had proposed that FlyHash is advantageous only on correlated, non-negative feature data; after correcting the protocol this pattern disappeared, and the authors explicitly retract this hypothesis (Appendix A).
  5. What are some points that can be further explored?

    The authors list eight limitations and future directions, covering the resource gap, the scope of the HNSW comparison, methods not evaluated, and synthetic data.

    Limitations and future directions noted by the authors

    • The resource gap is not closed: sparse set comparison recovers most of the speed disadvantage, but the memory disadvantage remains; sublinear indexing (banded/multi-probe LSH or inverted indices verified to be sublinear) has not been implemented, and more compact index encoding is a clear next step (Section 6).
    • The HNSW comparison is a single-point snapshot: only one dataset (GloVe 5,000 items) and one HNSW configuration, with no sweep over corpus scale; the combined approach of using FlyHash as a pre-filter before HNSW reranking is unexplored (Section 6).
    • SIFT1M is not included: the authors call this a deliberate scope decision, believing four datasets are enough to show the results are not dataset-specific (Section 6).
    • DenseFly and BioHash are not implemented: both are reported to outperform the random-projection version of FlyHash evaluated here, and combining them with agent memory applications is future work (Section 6).
    • No comparison with quantization methods: the authors cite literature stating that Product Quantization and RaBitQ are generally better than hashing in accuracy per bit, and leave the comparison to future work (Section 6).
    • The MiniLM corpus has only 100 sentences: a small corpus was chosen to avoid duplicate-embedding artifacts, and a larger and more diverse real-text corpus would strengthen this result (Section 6).
    • End-to-end latency has only a single point: 20.5 ms/query is the result from one machine, one query, and 30 repetitions, with no seed averaging and no scale or hardware sweep; multi-subsystem benchmarks are future work (Section 6).
    • The annotated benchmark uses template-synthesized text and TF-IDF+SVD embeddings: it is not natural language, and real deployments are more likely to restrict retrieval scope by session or user ID; rerunning with human-written memory logs and real sentence embeddings would strengthen this result (Section 6).

    Scope of experimental coverage

    • Methods under test: two hashes, FlyHash and SimHash, with one configuration of FAISS IndexHNSWFlat as the system baseline; no other models were run, and embeddings use all-MiniLM-L6-v2 and TF-IDF+SVD (Sections 3.3, 4.6–4.7).
    • Datasets: GloVe (5,000 items), MiniLM (100 items), digits (1,797 items), MNIST (5,000/70,000 items), and the self-built annotated benchmark (6,000 memories, 150 queries) (Tables 1, 10).
    • Statistical scale: main results 10 seeds, hyperparameter sweep 3 seeds, paired tests based on n=10 paired seeds (Sections 3.4, 4.2).
    • Resource measurement: brute-force comparison on 5,000 GloVe items with 50 queries; end-to-end latency is a single machine, single query, 30 repetitions (Tables 5, 7).
    • Not reported in the paper: HNSW performance at other corpus scales, comparison with quantization methods, and results of the annotated benchmark under real sentence embeddings (Section 6).
  6. Summarize the main content of the paper

    FlyHash for agent memory retrieval: robustly better than SimHash on quality, not advantageous on resources, and HNSW is comprehensively better at conventional scale.

    An empirical validation paper applying FlyHash, a locality-sensitive hash inspired by the Drosophila olfactory system, to LLM agent memory retrieval, organized around three questions: quality, resources, and real relevance.

    • Problem: agent memory mainstream uses dense vectors plus ANN indexes, with storage and computation growing with scale; FlyHash had not previously been used in this setting, and the literature generally uses embedding nearest neighbors as a relevance proxy, lacking statistical validation (Section 1).
    • Method: matched-active-bit protocol—FlyHash fixes m=2,000 and winner count k, SimHash outputs k bits, isolating hash quality; the authors find that scanning m as k is a previously unflagged comparison trap, and only after correcting it do the original paper's conclusions reproduce (Sections 3.1–3.2, Appendix A).
    • Quality results: across 20 comparisons (4 datasets×5 bit budgets), FlyHash outperforms SimHash in all (10 seeds, Table 2); on GloVe the paired test gives p ≈ 0.00195, Cohen's dz 14.8–40.8 (Table 3); the relative advantage is largest at low bits, 4.2× at GloVe k=16 (Section 4.1).
    • Resource results: under dense representation FlyHash uses about 250 bytes/item and about 13 ms/query, 10–70× slower than SimHash; the sparse-set comparison is 10–22× faster but still 2–5× slower than SimHash, with about 16× its storage (Tables 5–6).
    • System comparison: on GloVe 5,000 items, HNSW (efSearch=64) achieves mAP@100 of 0.9862 at 0.060 ms/query, better than both hashes in both quality and latency (Tables 8–9).
    • Real labels: on the self-built constructed-label benchmark with 6,000 memories and 150 queries, FlyHash still outperforms SimHash at every budget (0.392 vs 0.345 at k=256, Table 10).
    • Authors' conclusion: the quality advantage is real and statistically validated, but does not automatically translate into memory or latency advantages; the applicable setting for hashing is narrowed to extreme storage budgets, and practitioners without special constraints should choose HNSW (Sections 5, 7).
Read originalhuggingface.co