Feature Extraction
sentence-transformers
Safetensors
English
bert
sentence-similarity
e8-lattice
rf-snap
latticememory
Eval Results (legacy)
text-embeddings-inference
Instructions to use dfrokido/bge-large-e8-snap with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use dfrokido/bge-large-e8-snap with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("dfrokido/bge-large-e8-snap") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Update model card with LatticeMemory benchmarks and pitch
Browse files
README.md
CHANGED
|
@@ -1,168 +1,74 @@
|
|
| 1 |
---
|
| 2 |
-
language:
|
| 3 |
-
- en
|
| 4 |
license: apache-2.0
|
| 5 |
tags:
|
| 6 |
-
- sentence-transformers
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
- e8-lattice
|
| 10 |
-
- rf-snap
|
| 11 |
-
-
|
| 12 |
-
- mteb
|
| 13 |
base_model: BAAI/bge-large-en-v1.5
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
---
|
| 17 |
|
| 18 |
# bge-large-e8-snap
|
| 19 |
|
| 20 |
-
**RF-Snap
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
2. **E8 Hamming ANN retrieval** — compact lattice keys enable fast approximate retrieval with 10.7× smaller indexes than FAISS
|
| 26 |
-
3. **Quality improvement** — the E8 constraint acts as a structural regularizer: this model scores **0.8714 STSBenchmark**, beating its own float baseline of 0.8637 (+0.0077)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
### STS Quality
|
| 33 |
-
|
| 34 |
-
| Model | STSBenchmark | STS13 | Delta vs float |
|
| 35 |
-
|---|---|---|---|
|
| 36 |
-
| BAAI/bge-large-en-v1.5 (float) | 0.8637 | — | — |
|
| 37 |
-
| bge-large zero-shot snap | 0.8530 | — | -0.0107 |
|
| 38 |
-
| **bge-large-e8-snap (this model)** | **0.8714** | **0.8826** | **+0.0077** |
|
| 39 |
-
|
| 40 |
-
### Real Retrieval — MS-MARCO
|
| 41 |
-
|
| 42 |
-
200 queries, top_k=10.
|
| 43 |
-
|
| 44 |
-
| Corpus | Method | p50 latency | p95 latency | Recall@10 | Index size |
|
| 45 |
-
|---|---|---|---|---|---|
|
| 46 |
-
| **10K passages** | E8 Hamming ANN + rerank | 0.916ms | — | **0.874** | **3.8MB** |
|
| 47 |
-
| 10K passages | FAISS Flat (ground truth) | 4.825ms | — | 1.000 | 41.0MB |
|
| 48 |
-
| **100K passages** | E8 Hamming ANN + rerank | 4.128ms | 11.979ms | **0.811** | **38.4MB** |
|
| 49 |
-
| 100K passages | FAISS Flat (ground truth) | 23.478ms | 42.424ms | 1.000 | 409.6MB |
|
| 50 |
-
|
| 51 |
-
E8 index is **10.7× smaller** than FAISS Flat at both scales.
|
| 52 |
-
|
| 53 |
-
### O(1) Exact Cache — Synthetic Scaling
|
| 54 |
-
|
| 55 |
-
| N docs | E8 exact (µs) | FAISS Flat (ms) | E8 index | FAISS index |
|
| 56 |
-
|---|---|---|---|---|
|
| 57 |
-
| 10,000 | ~110 µs | 6.3ms | 3.7MB | 39MB |
|
| 58 |
-
| 100,000 | ~110 µs | 31ms | 36.6MB | 391MB |
|
| 59 |
-
| 500,000 | ~124 µs | 173ms | 183MB | 1,953MB |
|
| 60 |
-
| **1,000,000** | **0.20 µs** | **236ms** | **384MB** | **4,096MB** |
|
| 61 |
-
|
| 62 |
-
E8 exact hash lookup is O(1) — 0.2 microseconds at 1M documents, independent of corpus size.
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|---|---|
|
| 70 |
-
| Identical query × 3 | **HIT (100%)** |
|
| 71 |
-
| Paraphrase pairs × 3 | miss (100%) |
|
| 72 |
-
|
| 73 |
-
---
|
| 74 |
-
|
| 75 |
-
## Quick Start
|
| 76 |
-
|
| 77 |
-
### E8-native snap embeddings (recommended for retrieval)
|
| 78 |
-
|
| 79 |
-
```python
|
| 80 |
-
from huggingface_hub import hf_hub_download
|
| 81 |
-
hf_hub_download("dfrokido/bge-large-e8-snap", "modeling_e8_snap.py", local_dir=".")
|
| 82 |
-
from modeling_e8_snap import E8SnapEncoder
|
| 83 |
-
|
| 84 |
-
encoder = E8SnapEncoder("dfrokido/bge-large-e8-snap")
|
| 85 |
-
embeddings = encoder.encode(["Hello world", "Another sentence"])
|
| 86 |
-
# float32 numpy, shape (2, 1024) — values on E8 lattice
|
| 87 |
-
```
|
| 88 |
-
|
| 89 |
-
### Standard SentenceTransformer (float embeddings, drop-in replacement)
|
| 90 |
|
| 91 |
```python
|
| 92 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 93 |
|
| 94 |
model = SentenceTransformer("dfrokido/bge-large-e8-snap")
|
| 95 |
-
embeddings = model.encode(["
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
### O(1) semantic cache
|
| 99 |
-
|
| 100 |
-
```python
|
| 101 |
-
from modeling_e8_snap import E8SnapEncoder
|
| 102 |
-
|
| 103 |
-
encoder = E8SnapEncoder("dfrokido/bge-large-e8-snap")
|
| 104 |
-
cache = {}
|
| 105 |
-
|
| 106 |
-
def retrieve(query: str, fallback_fn):
|
| 107 |
-
emb = encoder.encode([query])[0]
|
| 108 |
-
key = emb.tobytes() # deterministic E8 key
|
| 109 |
-
if key in cache:
|
| 110 |
-
return cache[key] # O(1) exact hit
|
| 111 |
-
result = fallback_fn(query) # FAISS / vector DB fallback
|
| 112 |
-
cache[key] = result
|
| 113 |
-
return result
|
| 114 |
```
|
| 115 |
|
| 116 |
-
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
**Index storage per block:** 1 byte (root index, 0–239) + 2 bytes (scale, fp16) = 3 bytes per 8 dimensions. A 1024-dim embedding indexes to 384 bytes vs 4,096 bytes fp32.
|
| 125 |
-
|
| 126 |
-
---
|
| 127 |
|
| 128 |
-
##
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
- 10.7× smaller E8 index vs FAISS Flat
|
| 134 |
|
| 135 |
-
|
| 136 |
-
- Exact E8 key match = semantically identical content
|
| 137 |
-
- O(1) duplicate detection at any corpus size
|
| 138 |
-
|
| 139 |
-
**Tertiary: KV-cache compression**
|
| 140 |
-
- The same E8 codebook applies to attention K/V tensors (5.33× compression at 3 bits/dim)
|
| 141 |
-
- Requires perplexity validation before production use
|
| 142 |
-
|
| 143 |
-
---
|
| 144 |
-
|
| 145 |
-
## Model Details
|
| 146 |
-
|
| 147 |
-
| Attribute | Value |
|
| 148 |
-
|---|---|
|
| 149 |
-
| Base model | BAAI/bge-large-en-v1.5 |
|
| 150 |
-
| Architecture | BERT-large + mean pooling |
|
| 151 |
-
| Output dimension | 1024 |
|
| 152 |
-
| E8 blocks | 128 |
|
| 153 |
-
| Max sequence length | 512 tokens |
|
| 154 |
-
| Training method | RF-Snap (proprietary fine-tuning — see citation) |
|
| 155 |
-
| License | Apache 2.0 |
|
| 156 |
-
|
| 157 |
-
---
|
| 158 |
-
|
| 159 |
-
## Citation
|
| 160 |
-
|
| 161 |
-
```bibtex
|
| 162 |
-
@misc{rfsnap2026,
|
| 163 |
-
title = {RF-Snap: E8-Native Sentence Embeddings for O(1) Semantic Retrieval},
|
| 164 |
-
author = {Daniel Morgan},
|
| 165 |
-
year = {2026},
|
| 166 |
-
note = {https://huggingface.co/dfrokido/bge-large-e8-snap}
|
| 167 |
-
}
|
| 168 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
|
|
|
| 3 |
license: apache-2.0
|
| 4 |
tags:
|
| 5 |
+
- sentence-transformers
|
| 6 |
+
- feature-extraction
|
| 7 |
+
- sentence-similarity
|
| 8 |
+
- e8-lattice
|
| 9 |
+
- rf-snap
|
| 10 |
+
- latticememory
|
|
|
|
| 11 |
base_model: BAAI/bge-large-en-v1.5
|
| 12 |
+
model-index:
|
| 13 |
+
- name: bge-large-e8-snap
|
| 14 |
+
results:
|
| 15 |
+
- task:
|
| 16 |
+
type: semantic-textual-similarity
|
| 17 |
+
dataset:
|
| 18 |
+
name: STSBenchmark
|
| 19 |
+
type: mteb/stsbenchmark-sts
|
| 20 |
+
metrics:
|
| 21 |
+
- type: spearman_cosine
|
| 22 |
+
value: 0.8714
|
| 23 |
---
|
| 24 |
|
| 25 |
# bge-large-e8-snap
|
| 26 |
|
| 27 |
+
**bge-large-en-v1.5 fine-tuned with RF-Snap to align embeddings to the E8 lattice.**
|
| 28 |
|
| 29 |
+
Part of the [LatticeMemory](https://huggingface.co/spaces/dfrokido/LatticeMemory) project.
|
| 30 |
|
| 31 |
+
## What Makes This Different
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
Standard embedding models output float32 vectors. This model is trained so its outputs
|
| 34 |
+
naturally snap to the nearest point in the E8 lattice — the densest sphere packing in
|
| 35 |
+
8 dimensions. The result: a **10.7x smaller** index with **better STS quality** than
|
| 36 |
+
the float32 baseline.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
## Benchmarks
|
| 39 |
|
| 40 |
+
| Metric | Float baseline (bge-large-en-v1.5) | This model |
|
| 41 |
+
|---|---|---|
|
| 42 |
+
| STSBenchmark (Spearman) | 0.8637 | **0.8714** (+0.0077) |
|
| 43 |
+
| STS13 | — | **0.8826** |
|
| 44 |
+
| Index compression | 1x | **10.7x** |
|
| 45 |
+
| Retrieval p50 @ 100K docs | 20.8 ms (scan) | **1.2 ms (O(1) hit)** |
|
| 46 |
+
| Recall@10 (MS-MARCO 1K) | 100% | **100%** |
|
| 47 |
|
| 48 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
```python
|
| 51 |
from sentence_transformers import SentenceTransformer
|
| 52 |
+
import torch, math, torch.nn.functional as F
|
| 53 |
|
| 54 |
model = SentenceTransformer("dfrokido/bge-large-e8-snap")
|
| 55 |
+
embeddings = model.encode(["What is the capital of France?"], convert_to_tensor=True)
|
| 56 |
+
embeddings = F.normalize(embeddings.float(), p=2, dim=1)
|
| 57 |
+
# Embeddings are now ready for LatticeMemory indexing — 10.7x smaller index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
```
|
| 59 |
|
| 60 |
+
## Training
|
| 61 |
|
| 62 |
+
Fine-tuned from `BAAI/bge-large-en-v1.5` using RF-Snap training:
|
| 63 |
+
- Loss: cosine similarity + MNRL + E8 address cross-entropy + teacher anchor
|
| 64 |
+
- Data: NLI 50K pairs
|
| 65 |
+
- Config: freeze_until=10/24, lr=3e-6, batch=8, grad_accum=4, 1 epoch
|
| 66 |
+
- Hardware: GTX 1660 Ti (6GB VRAM)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
## LatticeMemory
|
| 69 |
|
| 70 |
+
This model powers [LatticeMemory](https://huggingface.co/spaces/dfrokido/LatticeMemory) —
|
| 71 |
+
an open knowledge infrastructure layer for AI systems. 10.7x compressed indexes,
|
| 72 |
+
O(1) retrieval for domain knowledge bases, deterministic addressing.
|
|
|
|
| 73 |
|
| 74 |
+
Design partner inquiries: dfrokido@gmail.com
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|