quazim commited on
Commit
2616e2f
·
verified ·
1 Parent(s): 18628df

Model card (TheStage Apple SDK)

Browse files
Files changed (1) hide show
  1. README.md +224 -0
README.md ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - google/embeddinggemma-2
4
+ base_model_relation: quantized
5
+ license: apache-2.0
6
+ pipeline_tag: feature-extraction
7
+ library_name: coreml
8
+ tags:
9
+ - embeddings
10
+ - multimodal
11
+ - sentence-similarity
12
+ - retrieval
13
+ - matryoshka
14
+ - apple-silicon
15
+ - on-device
16
+ - coreml
17
+ - ios
18
+ - macos
19
+ - thestage-apple-sdk
20
+ ---
21
+
22
+ # EmbeddingGemma 2 (Apple Silicon)
23
+
24
+ ![On-Device Apple SDK](assets/on-device-apple-sdk-banner.png)
25
+
26
+
27
+ [TheStage Apple SDK](https://github.com/TheStageAI/AppleSDK)
28
+
29
+ **Original model:** [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2) (Google)
30
+
31
+ On-device **multimodal embeddings** compressed and packaged by **TheStage AI** for Apple Silicon (CoreML / Neural Engine). Text, images, audio, video, and mixed inputs (an image with its caption) map into **one 768-d, L2-normalized space**, so a typed query can find a paragraph, a photo, a sound or a clip. Matryoshka-trained: the first 512, 256 or 128 values are themselves embeddings.
32
+
33
+ | | |
34
+ | --- | --- |
35
+ | Runtime | TheStage Apple SDK (`EmbeddingPipeline`) |
36
+ | Embedding dim | **768** (L2-normalized); Matryoshka **512 / 256 / 128** |
37
+ | Inputs | text, image, audio, video, mixed |
38
+ | Default device | **NPU** (Neural Engine) |
39
+ | SDK | **1.7.0+** |
40
+ | HF engines | `TheStageAI/embeddinggemma-2` (tag `v1.7`) |
41
+
42
+
43
+ ## Overview
44
+
45
+ ---
46
+
47
+ This repo hosts **CoreML engine bundles** for the TheStage Apple SDK. Point `engines_path` at the repo id; the SDK downloads, caches, and loads the engines automatically. Task prompts, token limits and Matryoshka sizes all come from the bundle. Open only the inputs you use (`modalities:`) to shorten the first load.
48
+
49
+ ## System Requirements
50
+
51
+ ---
52
+
53
+ | **Property** | **Value** |
54
+ | --- | --- |
55
+ | **Hardware** | Apple Silicon Mac, or physical iPhone / iPad |
56
+ | **macOS** | 15.0+ |
57
+ | **iOS** | 18.0+ |
58
+ | **Xcode** | 16.0+ |
59
+ | **Swift** | 6.0+ |
60
+ | **Flutter** (optional) | 3.24+ |
61
+
62
+ > Simulator is **not** supported — run on real Apple Silicon hardware.
63
+
64
+
65
+ ## TheStage AI Access Token
66
+
67
+ ---
68
+
69
+ Create a token at [app.thestage.ai](https://app.thestage.ai) and pass it to the SDK:
70
+
71
+ ```swift
72
+ try await TheStageAI.shared.initialize(api_token: "th_…")
73
+ ```
74
+
75
+ ```dart
76
+ await TheStageFlutterSDK.initialize(api_token: 'th_…');
77
+ ```
78
+
79
+ Token is checked online in `initialize` (once per app process when reachable). Inference runs fully on-device. Offline initialize fails — reconnect and call `initialize` again.
80
+
81
+
82
+ ## TheStage Apple SDK
83
+
84
+ ---
85
+
86
+ Docs: [TheStage Apple SDK · Embeddings](https://docs.thestage.ai) · Repo: [TheStage Apple SDK](https://github.com/TheStageAI/AppleSDK)
87
+
88
+
89
+ ### Installation (SwiftPM)
90
+
91
+ In Xcode: **File → Add Package Dependencies…**, paste `https://github.com/TheStageAI/AppleSDK.git`, and add the `TheStageSDK` product. Or in `Package.swift`:
92
+
93
+ ```swift
94
+ .package(
95
+ url: "https://github.com/TheStageAI/AppleSDK.git",
96
+ exact: Version(1, 7, 0)
97
+ )
98
+ ```
99
+
100
+ ### Installation (Flutter / iOS)
101
+
102
+ ```yaml
103
+ # pubspec.yaml
104
+ dependencies:
105
+ thestage_apple_sdk:
106
+ git:
107
+ url: https://github.com/TheStageAI/AppleSDK.git
108
+ path: plugin/thestage_apple_sdk
109
+ ref: 1.7.0
110
+ ```
111
+
112
+
113
+ ### Swift
114
+
115
+ ```swift
116
+ import TheStageSDK
117
+
118
+ try await TheStageAI.shared.initialize(api_token: "th_…")
119
+
120
+ let embedder = try await EmbeddingPipeline(
121
+ engines_path: "TheStageAI/embeddinggemma-2",
122
+ modalities: [.TEXT, .IMAGE] // nil = every input kind
123
+ )
124
+
125
+ // Search: queries and documents use different task prompts
126
+ let query: EmbeddingResult = try await embedder.infer(text: "how to reset the router", task: .QUERY)
127
+ let doc: EmbeddingResult = try await embedder.infer(text: doc_text, task: .DOCUMENT)
128
+ let score: Float = try EmbeddingPipeline.similarity(query, doc)
129
+
130
+ // Other inputs — same space
131
+ let photo: EmbeddingResult = try await embedder.infer(image: cg_image)
132
+ let product: EmbeddingResult = try await embedder.infer(inputs: [.image(cg_image), .text("red sneakers")])
133
+ // with modalities [.AUDIO] / [.VIDEO]:
134
+ // try await embedder.infer(audio: samples, sample_rate: 44_100)
135
+ // try await embedder.infer(video: file_url, max_frames: 8)
136
+
137
+ // Smaller vectors
138
+ let small: EmbeddingResult = try await embedder.infer(text: "how to reset the router", task: .QUERY, dimension: 256)
139
+ ```
140
+
141
+ ### Flutter (iOS)
142
+
143
+ ```dart
144
+ await TheStageFlutterSDK.start_model(
145
+ model_name: 'embed',
146
+ engines_path: 'TheStageAI/embeddinggemma-2',
147
+ );
148
+
149
+ final rows = await TheStageFlutterSDK.infer(
150
+ model_name: 'embed',
151
+ input_json: {'text': 'how to reset the router', 'task': 'query'},
152
+ );
153
+ final embedding = (rows[0]['embedding'] as List).cast<double>();
154
+
155
+ // Images, audio, video: pass a file path
156
+ final photo = await TheStageFlutterSDK.infer(
157
+ model_name: 'embed',
158
+ input_json: {'image_path': '/path/to/photo.jpg', 'dimension': 256},
159
+ );
160
+ ```
161
+
162
+ ### Inputs / outputs
163
+
164
+ | Direction | Swift | Flutter key | Notes |
165
+ | --- | --- | --- | --- |
166
+ | in | `infer(text:)` | `text` | Up to 2048 tokens; longer text is cut (`truncated`) |
167
+ | in | `infer(image:)` | `image_path` | Any size; 256–280 tokens per image |
168
+ | in | `infer(audio:sample_rate:)` | `audio_path` | Mono, any rate (resampled); 25 tokens/s, first 30 s (`truncated` past that) |
169
+ | in | `infer(video:max_frames:)` | `video_path`, `max_frames` | 1 frame/s, up to 14 frames (default), up to 140 tokens per frame |
170
+ | in | `infer(inputs:)` | several keys | One embedding for mixed parts (Flutter order: text, image, audio, video) |
171
+ | in | `task:` | `task` | `query`, `document`, `STS`, `Classification`, `Clustering`, `CodeRetrieval`, `QuestionAnswering`, `FactChecking` |
172
+ | in | `dimension:` | `dimension` | 768 (default), 512, 256, 128 |
173
+ | out | `embedding` | `embedding` | Unit-length vector |
174
+ | out | `dimension`, `embedding_space_id` | same | Compare only results with equal `embedding_space_id` |
175
+ | out | `token_count`, `truncated` | same | Input length read; whether anything was cut |
176
+
177
+ ### Matryoshka sizes
178
+
179
+ Reference quality of the base model (Google model card, bf16):
180
+
181
+ | Size | MTEB eng v2 | MTEB Code | MIEB lite | MAEB | MMEB v2 |
182
+ | --- | --- | --- | --- | --- | --- |
183
+ | 768 | 68.46 | 78.68 | 65.67 | 49.87 | 59.01 |
184
+ | 512 | 68.41 | 77.24 | 65.34 | 49.76 | 58.38 |
185
+ | 256 | 67.78 | 76.18 | 64.16 | 49.13 | 56.24 |
186
+ | 128 | 65.68 | 71.41 | 59.97 | 47.28 | 45.65 |
187
+
188
+ 256 is near-lossless for text; 128 costs noticeably more on images, audio and video. For large indexes, store 768-d vectors, shortlist on the first 256 values renormalized, and re-rank the shortlist on 768.
189
+
190
+ ### On-device latency
191
+
192
+ Release build, Neural Engine, warmed, median of 5 (guidance, not an SLA):
193
+
194
+ | Input | Tokens | Apple M-series Mac | iPhone 13 |
195
+ | --- | --- | --- | --- |
196
+ | Text query | 16 | **8.1 ms** | **12.6 ms** |
197
+ | Text document | 368 | **47.6 ms** | **69.7 ms** |
198
+ | Image 768x768 | 260 | **439.5 ms** | **538.0 ms** |
199
+ | Audio 3 s | 79 | **137.7 ms** | **227.7 ms** |
200
+ | Audio 30 s | 754 | **236.6 ms** | **382.7 ms** |
201
+ | Video, 4 frames | 494 | **607.1 ms** | **757.8 ms** |
202
+ | Image + caption | 271 | **439.8 ms** | **538.4 ms** |
203
+
204
+ The first load on a device prepares every engine (about two minutes on a Mac, under four on an iPhone 13, with all four inputs); later loads take seconds (7.9 s on an iPhone 13). Memory stays under 200 MB once loaded on an iPhone 13. Always measure release builds on device.
205
+
206
+ ## Acknowledgments
207
+
208
+ ---
209
+
210
+ This work builds on **EmbeddingGemma 2** by Google: [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2).
211
+
212
+ The base model [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2) is released under Apache-2.0. This Apple Silicon package is produced by TheStage AI; it is not an official Google release.
213
+
214
+ ## Links
215
+
216
+ ---
217
+
218
+
219
+ * __Original model__: [google/embeddinggemma-2](https://huggingface.co/google/embeddinggemma-2)
220
+ * __Platform__: [app.thestage.ai](https://app.thestage.ai)
221
+ * __TheStage Apple SDK__: [github.com/TheStageAI/AppleSDK](https://github.com/TheStageAI/AppleSDK)
222
+ * __Docs__: [docs.thestage.ai](https://docs.thestage.ai)
223
+ * __Subscribe for updates__: [TheStageAI X](https://x.com/TheStageAI)
224
+ * __Contact email__: contact@thestage.ai