DylanCouzon commited on
Commit
6bb167d
·
verified ·
1 Parent(s): ab01353

Upload constella-nano research preview

Browse files
Files changed (7) hide show
  1. README.md +256 -0
  2. config.json +30 -0
  3. model.onnx +3 -0
  4. special_tokens_map.json +7 -0
  5. tokenizer.json +0 -0
  6. tokenizer_config.json +59 -0
  7. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language: en
4
+ library_name: fastembed
5
+ tags:
6
+ - fastembed
7
+ - qdrant
8
+ - onnx
9
+ - retrieval
10
+ - asymmetric-dual-encoder
11
+ - research-preview
12
+ base_model: BAAI/bge-small-en-v1.5
13
+ pipeline_tag: feature-extraction
14
+ ---
15
+
16
+ # constella-nano
17
+
18
+ The query side of an **asymmetric dual encoder**: documents are indexed once with a large frozen
19
+ encoder; queries are encoded at serving time with a smaller encoder.
20
+
21
+ Nano starts from `bge-small-en-v1.5` and uses a three-layer feature tap plus a linear head. It was
22
+ trained to land in the 1024-dimensional document space of `stella_en_400M_v5`. The matching
23
+ document encoder is published as
24
+ [`stella-en-400M-v5-doc-onnx`](https://huggingface.co/DylanCouzon/stella-en-400M-v5-doc-onnx);
25
+ the two towers are only meaningful together.
26
+
27
+ > **Research preview.** The registered reserved-four evaluation and broad descriptive BEIR-18
28
+ > validation are pending. Read [Results](#results) and [Limits](#limits) first. The native model
29
+ > entry currently lives only on the custom FastEmbed branch `m14-constella-preview`; it is **not
30
+ > in upstream FastEmbed**. The upstream PR belongs to later M20 work.
31
+
32
+ ## Usage
33
+
34
+ Install the preview branch and Qdrant's Python client:
35
+
36
+ ```console
37
+ pip install "fastembed @ git+https://github.com/Dylancouzon/fastembed@m14-constella-preview" qdrant-client
38
+ ```
39
+
40
+ The snippets in this section run in order, sharing state. They use FastEmbed's native model
41
+ registrations and never call `add_custom_model`. The optional model-path variables are only for
42
+ offline verification; omit them for normal Hub-backed use.
43
+
44
+ <!-- m14-card-usage-start -->
45
+
46
+ ```python
47
+ import os
48
+
49
+ import numpy as np
50
+ from fastembed import TextEmbedding
51
+
52
+ NANO_NAME = "DylanCouzon/constella-nano"
53
+ ZERO_NAME = "DylanCouzon/constella-zero"
54
+ DOC_NAME = "DylanCouzon/stella-en-400M-v5-doc-onnx"
55
+
56
+ nano_path = os.environ.get("CONSTELLA_NANO_PATH")
57
+ zero_path = os.environ.get("CONSTELLA_ZERO_PATH")
58
+ doc_path = os.environ.get("CONSTELLA_DOC_PATH")
59
+ nano_kwargs = {"specific_model_path": nano_path} if nano_path else {}
60
+ zero_kwargs = {"specific_model_path": zero_path} if zero_path else {}
61
+ doc_kwargs = {"specific_model_path": doc_path} if doc_path else {}
62
+ ```
63
+
64
+ ### The document side
65
+
66
+ Run the published Stella document tower in the indexing job, once per document:
67
+
68
+ ```python
69
+ doc_model = TextEmbedding(DOC_NAME, **doc_kwargs)
70
+ docs = [
71
+ "mRNA vaccines deliver messenger RNA encoding a viral antigen.",
72
+ "The Treaty of Westphalia ended the Thirty Years' War in 1648.",
73
+ ]
74
+ D = np.stack(list(doc_model.embed(docs))).astype(np.float32, copy=False)
75
+ assert D.shape == (2, 1024)
76
+ assert np.isfinite(D).all()
77
+ ```
78
+
79
+ The document model is the large, frozen side of the system. Do not use its unprompted path as a
80
+ Stella query encoder.
81
+
82
+ ### With Qdrant
83
+
84
+ This defaults to Qdrant's local, in-memory mode, so the example is runnable without a server but
85
+ the collection disappears with the process. Set `QDRANT_URL` to use an already-running Qdrant
86
+ deployment instead; choose a fresh collection name there.
87
+
88
+ ```python
89
+ from qdrant_client import QdrantClient, models
90
+
91
+ qdrant_url = os.environ.get("QDRANT_URL")
92
+ client = QdrantClient(url=qdrant_url) if qdrant_url else QdrantClient(":memory:")
93
+ COLLECTION_NAME = "constella_nano_demo"
94
+
95
+ client.create_collection(
96
+ COLLECTION_NAME,
97
+ vectors_config=models.VectorParams(size=1024, distance=models.Distance.COSINE),
98
+ )
99
+ client.upsert(
100
+ COLLECTION_NAME,
101
+ points=[
102
+ models.PointStruct(id=i, vector=D[i].tolist(), payload={"text": text})
103
+ for i, text in enumerate(docs)
104
+ ],
105
+ )
106
+
107
+ # Serving time: Nano encodes each query; the document tower does not run here.
108
+ query_model = TextEmbedding(NANO_NAME, **nano_kwargs)
109
+ query = "how do mRNA vaccines work?"
110
+ q_native = np.asarray(next(iter(query_model.embed([query]))))
111
+ # FastEmbed's integer attention mask promotes Nano's masked mean to float64.
112
+ # Cast explicitly to keep each 1024-d query at the intended 4,096-byte fp32 size.
113
+ q = q_native.astype(np.float32, copy=False)
114
+ assert q.shape == (1024,) and np.isfinite(q).all()
115
+
116
+ hits = client.query_points(COLLECTION_NAME, query=q.tolist(), limit=2).points
117
+ print([(hit.payload["text"], hit.score) for hit in hits])
118
+ ```
119
+
120
+ The collection is 1024-dimensional cosine. Both towers emit L2-normalized vectors, so cosine and
121
+ dot-product ranking agree for these vectors; cosine keeps the collection contract explicit.
122
+
123
+ ### Swapping the query encoder
124
+
125
+ The same Qdrant collection can be queried with
126
+ [`constella-zero`](https://huggingface.co/DylanCouzon/constella-zero) without re-encoding its
127
+ documents:
128
+
129
+ ```python
130
+ zero_model = TextEmbedding(ZERO_NAME, **zero_kwargs)
131
+ q_zero = np.asarray(next(iter(zero_model.embed([query])))).astype(np.float32, copy=False)
132
+ assert q_zero.shape == (1024,) and np.isfinite(q_zero).all()
133
+ zero_hits = client.query_points(COLLECTION_NAME, query=q_zero.tolist(), limit=2).points
134
+ print([(hit.payload["text"], hit.score) for hit in zero_hits])
135
+ ```
136
+
137
+ <!-- m14-card-usage-end -->
138
+
139
+ Nano and Zero both emit normalized 1024-dimensional query vectors in the same Stella document
140
+ space. One document index therefore serves either query encoder, and the choice can be made per
141
+ deployment or per query. This compatibility is geometric, **not a retrieval-quality equivalence
142
+ claim**: the encoders have distinct measured retrieval behavior, and no parity, equivalence or
143
+ tie is implied. The query-cost side of the trade-off is measured under the same four-thread CPU
144
+ protocol: Zero's warm p50 median was **0.1119 ms** and Nano's was **7.2511 ms**. These are
145
+ **synthetic latencies, not workload estimates**. Only Zero claims near-zero query compute; Nano's
146
+ query cost is roughly bge-small's, whose warm p50 median was 6.8400 ms under that protocol.
147
+
148
+ ## How it works
149
+
150
+ Nano starts from
151
+ [`BAAI/bge-small-en-v1.5`](https://huggingface.co/BAAI/bge-small-en-v1.5). Its three-layer feature
152
+ tap and linear head were trained to match frozen query and document targets in the space of
153
+ [`NovaSearch/stella_en_400M_v5`](https://huggingface.co/NovaSearch/stella_en_400M_v5). Nano needs
154
+ no query prefix.
155
+
156
+ Inputs are right-truncated to 512 tokens. The tokenizer leaves padding unset so FastEmbed uses
157
+ dynamic batch-longest padding. The ONNX graph emits fp32 token embeddings; FastEmbed's native
158
+ `PooledNormalizedEmbedding` family applies attention-masked mean pooling and L2 normalization.
159
+ That family assignment is required for correct native output.
160
+
161
+ FastEmbed's integer attention mask currently promotes Nano's native masked-mean result to
162
+ float64 even though the graph output is fp32. The usage example casts the final normalized query
163
+ vector back to fp32 before sending it to Qdrant.
164
+
165
+ ## Files
166
+
167
+ The release bundle contains the ONNX graph plus its FastEmbed configuration and tokenizer files.
168
+ The native FastEmbed registration downloads those assets by model name. The graph returns token
169
+ embeddings; pooling and normalization are supplied by FastEmbed, not serialized into the graph.
170
+
171
+ The custom branch registers Nano with `PooledNormalizedEmbedding`, and registers the published
172
+ Stella document tower and constella-zero with their appropriate native families. It is a preview
173
+ vehicle, not an upstream FastEmbed release.
174
+
175
+ ## Results
176
+
177
+ The headline is the **clean-four** partition, which excludes ArguAna and FiQA because Stella
178
+ discloses training/evaluation contact with those two datasets. Against bge-small, Nano improved
179
+ clean-four nDCG@10 by **+0.017648**, with one-sided lower 2.5% bound **+0.003674** and sign-flip
180
+ **p=0.006410**.
181
+
182
+ Nano's exact-search nDCG@10 results are:
183
+
184
+ | dataset | Nano | Nano − bge-small | Nano − LEAF asym |
185
+ |---|---:|---:|---:|
186
+ | SciFact | 0.721097 | +0.008391 | +0.022084 |
187
+ | NFCorpus | 0.363080 | +0.020129 | +0.002301 |
188
+ | FiQA† | 0.477765 | +0.074253 | +0.061296 |
189
+ | ArguAna† | 0.623296 | +0.019848 | +0.040043 |
190
+ | SCIDOCS | 0.217710 | +0.012498 | +0.014345 |
191
+ | TREC-COVID | 0.787116 | +0.029573 | -0.042982 |
192
+
193
+ † Stella-disclosed training/evaluation contact; excluded from clean-four.
194
+
195
+ Against LEAF asym, Nano established an all-six improvement of **+0.016181** (one-sided lower 2.5%
196
+ bound **+0.006504**, sign-flip **p=0.000540**). The clean-four result against LEAF is
197
+ **UNESTABLISHED**: the contrast was **-0.001063**, lower bound **-0.014456**, **p=0.559474**. This
198
+ is not parity, equivalence or a tie. The **-0.042982** TREC-COVID difference versus LEAF is the
199
+ principal per-dataset limitation.
200
+
201
+ ## Limits
202
+
203
+ - **Pending registered evidence.** The reserved four remain unestablished and unspent at preview
204
+ time; no result is claimed for them. Broad BEIR-18 validation is also pending, so the six-set
205
+ table must not be read as broad domain coverage.
206
+ - **Teacher contact.** Stella discloses training/evaluation contact with ArguAna and FiQA. They
207
+ are excluded from the headline clean-four partition; all-six results are secondary.
208
+ - **LEAF comparison.** Clean-four performance against LEAF is UNESTABLISHED. No parity,
209
+ equivalence or tie follows, and TREC-COVID is the main observed per-dataset weakness.
210
+ - **Length and language.** Nano is English-only and truncates beyond 512 tokens.
211
+ - **The document side is not cheap.** The Stella document tower still runs once per document;
212
+ Nano changes query-side cost, not indexing cost.
213
+
214
+ ## Costs
215
+
216
+ The measurements below are **synthetic query latencies, not workload estimates**. They used the
217
+ same four-thread, batch-one CPU protocol, with medians across three fresh processes.
218
+
219
+ | model | hydration | first query | warm 20-word p50 | peak RSS | model assets |
220
+ |---|---:|---:|---:|---:|---:|
221
+ | constella-zero | 0.2618 s | 0.3529 ms | 0.1119 ms | 275.4 MiB | 90.1 MiB |
222
+ | bge-small | 0.6726 s | 8.2401 ms | 6.8400 ms | 291.0 MiB | 127.6 MiB |
223
+ | constella-nano | 0.6907 s | 7.6685 ms | 7.2511 ms | 280.9 MiB | 132.3 MiB |
224
+
225
+ A native 1024-dimensional Nano query occupies 8,192 bytes as float64; the explicit fp32 cast in
226
+ the example reduces it to 4,096 bytes. If query vectors are stored, the corresponding raw-vector
227
+ sizes are 8.192 GB per million for native float64 and 4.096 GB per million for cast fp32, before
228
+ index overhead. Any 4.096 GB figure assumes the fp32 cast.
229
+
230
+ ## Training
231
+
232
+ The frozen checkpoint saw exactly **199,999,721 examples**, a reconciled shortfall of **279**
233
+ from the nominal 200,000,000-example plan. Nine one-row document tail batches each lost 31 rows;
234
+ the original failed supervisor receipt remains part of the audit trail.
235
+
236
+ Training mixed real queries from ESCI, HotpotQA, Mr. TyDi, NQ Open, SQuAD and TriviaQA; a PAQ
237
+ sample; harvested titles, headings and claim sentences from Wikipedia, arXiv and the licensed
238
+ pool; seven generated query forms; and the eligible document pool. MS MARCO was excluded from
239
+ training and used only as a validation surface. The CC BY-SA sources and PAQ retain their source
240
+ attribution.
241
+
242
+ Every training source was fingerprint-screened against the protected index containing the six
243
+ evaluation datasets and COV components. The final assembly records 709 query removals and 79,630
244
+ document removals, plus zero cross-role collisions. This is fingerprint-level decontamination;
245
+ it does not erase the Stella-contact disclosure above.
246
+
247
+ ## Provenance
248
+
249
+ ```text
250
+ student BAAI/bge-small-en-v1.5 @ 5c38ec7c405ec4b44b94cc5a9bb96e735b38267a
251
+ teacher NovaSearch/stella_en_400M_v5 @ ffeb2b7ee715c226d4ffe5e4619f7dbb48624c20
252
+ ```
253
+
254
+ The preview weights are released under MIT. The pinned bge-small backbone and Stella
255
+ teacher/document tower are also MIT and are attributed above. Dataset-source obligations and the
256
+ decontamination record remain documented in the project evidence.
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "float32",
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "id2label": {
12
+ "0": "LABEL_0"
13
+ },
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 1536,
16
+ "label2id": {
17
+ "LABEL_0": 0
18
+ },
19
+ "layer_norm_eps": 1e-12,
20
+ "max_position_embeddings": 512,
21
+ "model_type": "bert",
22
+ "num_attention_heads": 12,
23
+ "num_hidden_layers": 12,
24
+ "pad_token_id": 0,
25
+ "position_embedding_type": "absolute",
26
+ "transformers_version": "4.57.6",
27
+ "type_vocab_size": 2,
28
+ "use_cache": true,
29
+ "vocab_size": 30522
30
+ }
model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ba0acf57b71dc31bc5512c5445078a797fa51cf3e85587d6b8a506bfc55dbc2
3
+ size 137802369
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "unk_token": "[UNK]",
3
+ "sep_token": "[SEP]",
4
+ "pad_token": "[PAD]",
5
+ "cls_token": "[CLS]",
6
+ "mask_token": "[MASK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]",
58
+ "max_length": 512
59
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff