TL;DR: Stateful embedding model that replaces sliding-window attention with RWKV recurrence, allowing for incremental encoding and streaming semantic search.
Conventional embedding models are stateless: adding new content requires re-encoding from scratch because token representations depend on the entire sequence.
HARE replaces 14 local sliding-window attention layers in ModernBERT-base with bidirectional RWKV linear recurrence while retaining 8 global attention layers.
Each recurrent layer maintains a fixed-size state matrix that summarizes all prior tokens with O(1) per-token cost, making the encoder stateful thus it can save and resume from any position.
Essentially, the biggest advantage is being able to perform semantic search on large files way before they're 100% available - and across multiple streams simultaneously (for example parallel distributed files, concurrent transcripts, documents arriving from different sources on the same topic)
Token-level HARE (73.9) surpasses both GTE-ModernBERT-base (71.5) and bge-m3 (71.7) on LoCo.
Usage
python
1import torch
2import torch.nn.functional as F
3from transformers import AutoModel, AutoTokenizer
45model = AutoModel.from_pretrained("SixOpen/HARE", trust_remote_code=True)6tokenizer = AutoTokenizer.from_pretrained("SixOpen/HARE")7model = model.cuda().eval()89texts =["Apple released a new iPhone model today","The latest iPhone was announced by Apple"]10enc = tokenizer(texts, padding=True, truncation=True, max_length=512, return_tensors='pt')11enc ={k: v.to('cuda')for k, v in enc.items()}12with torch.no_grad():13 hidden = model(**enc).last_hidden_state
14mask = enc['attention_mask'].unsqueeze(-1).float()15embs =(hidden * mask).sum(1)/ mask.sum(1).clamp(min=1e-9)16embs = F.normalize(embs, p=2, dim=-1)1718similarity =(embs[0] @ embs[1]).item()
Multi-vector retrieval (long documents)
For documents longer than 512 tokens, split into 256-token chunks with 64-token overlap and score with MaxSim.
HARE can also carry recurrent state across chunks, conditioning each chunk on all prior context without re-encoding. See the streaming demos for stateful usage.
As mentioned prior unlike standard encoders, HARE can save and resume from any position. New text is encoded with full prior context without re-encoding anything before it.
python
1from streaming import SpanEncoder
23enc = SpanEncoder(model, tokenizer,"cuda", chunk_size=256)45# Mock lecture transcript arriving in 3 streaming pieces6pieces =[7"Today we will cover the fundamentals of quantum computing. Classical computers "8"use bits that are either 0 or 1. Quantum computers use qubits which can exist "9"in superposition, meaning they can be both 0 and 1 simultaneously. ",10"The key advantage comes from entanglement. When two qubits are entangled, "11"measuring one instantly determines the state of the other regardless of distance. "12"This allows quantum computers to process certain problems exponentially faster. ",13"The most important quantum algorithm is Shor's algorithm which can factor large "14"numbers in polynomial time. This has major implications for cryptography since "15"RSA encryption relies on the difficulty of factoring large primes. ",16]1718# Encode incrementally, only the new piece is processed each time19enc.encode_span(pieces[0], key="p0")# encode first piece20enc.extend_right(pieces[1],"p0","p1")# extend with state carry21enc.extend_right(pieces[2],"p1","p2")# extend again2223# Search the incrementally built index24q_emb = enc.encode_query("why is Shor's algorithm important for cryptography")25chunk_embs = torch.cat(enc.span_data["p2"]["chunk_embs"], dim=0)26scores =(q_emb @ chunk_embs.T).squeeze(0)27best = scores.argmax().item()28print(f"Best chunk: {best}, score: {scores[best]:.4f}")29# → Best chunk: 2, score: 0.7814
Token-level late interaction (offline, full-document)
For best quality on long documents, encode the full document in one pass and score at the token level, where query_tokens and doc_tokens are l2-normalized token embeddings:
score = sum(max(q_tok @ d_tok for d_tok in doc_tokens) for q_tok in query_tokens)
Architecture
HARE starts from ModernBERT-base (22 layers, 768-dim, 12 heads) and performs architectural surgery:
Layers 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20 (14 local sliding-window attention layers) are replaced with BiRWKV-7 bidirectional recurrence
Layers 0, 3, 6, 9, 12, 15, 18, 21 (8 global attention layers) are retained unchanged
Recurrence-specific parameters (decay, gate, mixing coefficients) are randomly initialized and learned during training
Each BiRWKV-7 layer runs a forward (left-to-right) and backward (right-to-left) scan, averaged. The forward scan's state matrix (64x64 per head, 12 heads per layer) can be saved and resumed for incremental encoding.
Layer replacement mapping (which layers were replaced, weight transfer record)
tokenizer.json
Tokenizer
tokenizer_config.json
Tokenizer config
surgery.py
Standalone surgery CLI tool (inspect layers, perform surgery from scratch)
birwkv7.py
BiRWKV-7 recurrence layer /w Triton Kernel (required for loading)
modeling_hare.py
Model wrapper
configuration_hare.py
Config class
streaming.py
SpanEncoder for stateful incremental encoding
Intended uses
Semantic search and retrieval over short or long documents
Incremental indexing where text arrives sequentially and must be searchable before completion: live transcription, real-time meeting/dispatch/etc indexing, distributed (ie torrent) content search, incremental document editing
Multi-vector retrieval with chunk-level or token-level scoring
Limitations
This is a research-grade model - although some numbers indicate long ctx sota on specific categories, it could benefit from seeing more diverse data during training as shown by the scores on legal case reports and stackoverflow above.
Asymmetric streaming context - streaming mode uses forward (left-to-right) state carry, which accumulates full left context incrementally; the backward scan only sees within each piece, so right context is local
Citation
bibtex
1@article{osman2026hare,
2 title={Stateful Embeddings via Hybrid Attention-Recurrence},
3 author={Osman A. Ender},
4 year={2026}
5}