Skip to content

Commit 0f9e12f

Browse files
committed
update docs
1 parent 75a638d commit 0f9e12f

1 file changed

Lines changed: 66 additions & 78 deletions

File tree

docs/ml/model-manager.md

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
# ModelManager
1+
## ModelManager
22

3-
---
4-
5-
## Overview
6-
7-
Handles lifecycle of ML models on device: downloading, importing, validating, listing, and deleting. Supports single-file models and zip-based multi-file models with dependency validation.
3+
Handles lifecycle of ML models on device: download, import, validation, listing, deletion, and model instantiation.
84

95
---
106

117
## ROOT_DIR
128

13-
Base directory for all stored models.
14-
15-
* `"models"` inside `context.filesDir`
9+
`filesDir/models/`
1610

1711
---
1812

@@ -28,26 +22,10 @@ suspend fun downloadModelInternal(
2822

2923
Downloads a model into internal storage.
3024

31-
### Behavior
32-
33-
* Resolves target path via `getModelFile`
34-
* Detects zip models via `resourceFiles`
35-
36-
### Zip flow
37-
38-
* Downloads to temporary `.zip`
39-
* Extracts into target directory
40-
* Validates required files exist
41-
* Deletes extracted files on validation failure
42-
43-
### Single-file flow
44-
45-
* Direct download into target file
46-
47-
### Notes
48-
49-
* Progress reported 0–100 on main thread
50-
* Uses temp file then atomic rename
25+
* Streams file from network to local storage
26+
* Reports progress (0–100) if available
27+
* Uses temporary file then atomic rename
28+
* Returns final model file
5129

5230
---
5331

@@ -57,7 +35,7 @@ Downloads a model into internal storage.
5735
fun downloadModelExternal(context: Context, url: String)
5836
```
5937

60-
Opens external browser for model URL.
38+
Opens external browser for model download URL.
6139

6240
---
6341

@@ -67,20 +45,10 @@ Opens external browser for model URL.
6745
suspend fun importModel(context: Context, modelInfo: ModelInfo, uri: Uri)
6846
```
6947

70-
Imports model from external URI.
48+
Imports a model from a URI into internal storage.
7149

72-
### Behavior
73-
74-
* Zip models:
75-
76-
* Copy URI → temp zip
77-
* Extract into model directory
78-
* Validate required files
79-
* Delete temp file
80-
81-
* Single-file models:
82-
83-
* Direct copy to target location
50+
* Copies URI content into model directory
51+
* Replaces existing model if present
8452

8553
---
8654

@@ -90,10 +58,7 @@ Imports model from external URI.
9058
fun modelExists(context: Context, model: ModelName): Boolean
9159
```
9260

93-
Checks if model exists locally.
94-
95-
* File model: checks file existence
96-
* Directory model: checks all required resources exist
61+
Checks whether a model is fully available locally.
9762

9863
---
9964

@@ -103,10 +68,7 @@ Checks if model exists locally.
10368
fun deleteModel(context: Context, modelInfo: ModelInfo): Boolean
10469
```
10570

106-
Deletes model from storage.
107-
108-
* Files: direct delete
109-
* Directories: recursive delete
71+
Deletes a model from internal storage.
11072

11173
---
11274

@@ -116,10 +78,7 @@ Deletes model from storage.
11678
fun listModels(context: Context, type: ModelType? = null): List<ModelName>
11779
```
11880

119-
Returns installed models.
120-
121-
* Filters registry by existence
122-
* Optional filtering by model type
81+
Returns installed models, optionally filtered by type.
12382

12483
---
12584

@@ -137,41 +96,70 @@ filesDir/models/<modelInfo.path>
13796

13897
---
13998

140-
## unzipFiles
99+
## downloadFileInternal
141100

142-
Extracts zip archive into target directory.
101+
Core network download utility.
143102

144-
* Skips directories
145-
* Writes files directly
146-
* Returns extracted file list
103+
* Streams HTTP response to local file
104+
* Writes to temp file first
105+
* Reports progress if content length is known
106+
* Replaces final file atomically
147107

148108
---
149109

150-
## downloadFileInternal
110+
## Model Providers
151111

152-
Core HTTP download implementation.
112+
### Text Embedders
153113

154-
### Behavior
114+
```kotlin
115+
fun getTextEmbedder(context: Context, modelName: ModelName): TextEmbeddingProvider
116+
```
117+
118+
Returns initialized text embedding model.
119+
120+
Supported models:
121+
122+
* `ALL_MINILM_L6_V2`
123+
* `CLIP_VIT_B_32_TEXT`
124+
125+
Throws `ModelNotDownloaded` if missing.
126+
127+
---
128+
129+
### Image Embedders
130+
131+
```kotlin
132+
fun getImageEmbedder(context: Context, modelName: ModelName): ImageEmbeddingProvider
133+
```
134+
135+
Supported models:
136+
137+
* `DINOV2_SMALL`
138+
* `CLIP_VIT_B_32_IMAGE`
139+
* `INCEPTION_RESNET_V1`
140+
141+
Throws `ModelNotDownloaded` if missing.
142+
143+
---
144+
145+
### Object Detectors
146+
147+
```kotlin
148+
fun getObjectDetector(context: Context, modelName: ModelName): DetectorProvider
149+
```
155150

156-
* Streams file via `HttpURLConnection`
157-
* Writes to `.tmp` file
158-
* Tracks progress if content length is available
159-
* Reports progress only on increase
160-
* Executes callbacks on main thread
151+
Supported models:
161152

162-
### Safety
153+
* `ULTRA_LIGHT_FACE_DETECTOR`
163154

164-
* Uses temp file during download
165-
* Deletes temp file on failure
166-
* Replaces final file atomically via rename
155+
Throws `ModelNotDownloaded` if missing.
167156

168157
---
169158

170159
## Design Notes
171160

172-
* Supports both single-file and multi-file model packages
173-
* Validates zip contents against expected dependencies
174-
* Uses atomic file replacement to prevent partial model states
175-
* Designed for offline-first model management
176-
* Separates download, import, and storage concerns
177-
* Optimized for Android sandboxed file system constraints
161+
* Internal storage only (`filesDir/models`)
162+
* Atomic file replacement for safety
163+
* Progress-aware streaming downloads
164+
* Model validation enforced before instantiation
165+
* Strict model-type matching for provider factories

0 commit comments

Comments
 (0)