mlboydaisuke commited on
Commit
b03901c
·
verified ·
1 Parent(s): ccf7f0d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +46 -0
README.md CHANGED
@@ -12,6 +12,52 @@ tags:
12
  library_name: coreml
13
  ---
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # EmbeddingGemma-300M for Apple CoreML (ANE-optimized)
16
 
17
  CoreML conversion of `google/embeddinggemma-300m` produced with the
 
12
  library_name: coreml
13
  ---
14
 
15
+ ## Use it from Swift
16
+
17
+ <!-- swift-usage-begin -->
18
+ ### Add the package
19
+
20
+ `Package.swift`:
21
+
22
+ ```swift
23
+ .package(url: "https://github.com/john-rocky/CoreML-LLM", branch: "main"),
24
+
25
+ // In your target:
26
+ .product(name: "CoreMLLLM", package: "CoreML-LLM"),
27
+ ```
28
+
29
+ Platforms: iOS 18+ / macOS 15+.
30
+
31
+ ### Download + encode
32
+
33
+ ```swift
34
+ import CoreMLLLM
35
+
36
+ let modelsDir = try FileManager.default.url(
37
+ for: .applicationSupportDirectory, in: .userDomainMask,
38
+ appropriateFor: nil, create: true)
39
+
40
+ let eg = try await EmbeddingGemma.downloadAndLoad(modelsDir: modelsDir)
41
+
42
+ // 768-dim L2-normalised embedding
43
+ let v = try eg.encode(text: "How do I list files in Swift?")
44
+ // Matryoshka: cheap-to-truncate dims (768 / 512 / 256 / 128)
45
+ let v256 = try eg.encode(text: "How do I list files in Swift?",
46
+ dim: 256)
47
+
48
+ // Task-prefixed (RAG document vs. query)
49
+ let q = try eg.encode(text: "list files",
50
+ task: .retrievalQuery)
51
+ let d = try eg.encode(text: "Use FileManager.contentsOfDirectory(...)",
52
+ task: .retrievalDocument)
53
+ ```
54
+
55
+ See [`Gemma3EmbeddingGemma.swift`](https://github.com/john-rocky/CoreML-LLM/blob/main/Sources/CoreMLLLM/Gemma3EmbeddingGemma.swift)
56
+ for task prefixes and dim list.
57
+ <!-- swift-usage-end -->
58
+
59
+
60
+
61
  # EmbeddingGemma-300M for Apple CoreML (ANE-optimized)
62
 
63
  CoreML conversion of `google/embeddinggemma-300m` produced with the