-
Notifications
You must be signed in to change notification settings - Fork 0
perf(android): replace flutter_gemma with llamadart — 150 MB → 42 MB APK #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6b35f5a
perf(android): reduce APK size with ABI splitting, R8, and lib exclus…
priyavratuniyal 9762e7a
refactor(models): add HNSW vector index and app-owned RetrievalResult
priyavratuniyal 7dcf2db
feat(services): add model downloader with progress and resume support
priyavratuniyal e91e186
refactor(ai): replace flutter_gemma services with llamadart
priyavratuniyal d2326d4
refactor(app): wire llamadart services into shell, add lite/full entr…
priyavratuniyal a39fd83
feat(android): add lite/full build flavors and llamadart backend config
priyavratuniyal da98430
Merge remote-tracking branch 'origin/main' into feature/apk-size-redu…
priyavratuniyal 6e329d0
fix(ai): harden model switching, downloads, and migration
priyavratuniyal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import 'main.dart'; | ||
|
|
||
| /// Entry point for the full flavor — includes all AI features. | ||
| Future<void> main() async => appMain(aiEnabled: true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import 'main.dart'; | ||
|
|
||
| /// Entry point for the lite flavor — no AI, no model downloads. | ||
| Future<void> main() async => appMain(aiEnabled: false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /// Configuration for a downloadable GGUF model (curated or custom). | ||
| class LlmModelConfig { | ||
| final String id; | ||
| final String name; | ||
| final String downloadUrl; | ||
| final int estimatedSizeMB; | ||
| final String description; | ||
| final bool isCustom; | ||
|
|
||
| const LlmModelConfig({ | ||
| required this.id, | ||
| required this.name, | ||
| required this.downloadUrl, | ||
| required this.estimatedSizeMB, | ||
| required this.description, | ||
| this.isCustom = false, | ||
| }); | ||
|
|
||
| /// Derive the on-disk filename from the download URL. | ||
| String get filename { | ||
| final uri = Uri.parse(downloadUrl); | ||
| return uri.pathSegments.isNotEmpty ? uri.pathSegments.last : '$id.gguf'; | ||
| } | ||
|
|
||
| /// Human-readable size string. | ||
| String get formattedSize { | ||
| if (estimatedSizeMB == 0) return 'Unknown'; | ||
| if (estimatedSizeMB >= 1000) { | ||
| return '${(estimatedSizeMB / 1000).toStringAsFixed(1)} GB'; | ||
| } | ||
| return '~$estimatedSizeMB MB'; | ||
| } | ||
| } | ||
|
|
||
| /// Registry of curated chat models + factory for custom GGUF URLs. | ||
| abstract final class LlmModelRegistry { | ||
| static const defaultModelId = 'qwen3-0.6b'; | ||
|
|
||
| static const List<LlmModelConfig> curated = [ | ||
| LlmModelConfig( | ||
| id: 'smollm2-360m', | ||
| name: 'SmolLM2 360M', | ||
| downloadUrl: | ||
| 'https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf', | ||
| estimatedSizeMB: 230, | ||
| description: 'Smallest, fastest load, lowest RAM', | ||
| ), | ||
| LlmModelConfig( | ||
| id: 'qwen3-0.6b', | ||
| name: 'Qwen3 0.6B', | ||
| downloadUrl: | ||
| 'https://huggingface.co/bartowski/Qwen3-0.6B-GGUF/resolve/main/Qwen3-0.6B-Q4_K_M.gguf', | ||
| estimatedSizeMB: 430, | ||
| description: 'Balanced quality and size', | ||
| ), | ||
| LlmModelConfig( | ||
| id: 'llama3.2-1b', | ||
| name: 'Llama 3.2 1B', | ||
| downloadUrl: | ||
| 'https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_K_M.gguf', | ||
| estimatedSizeMB: 770, | ||
| description: 'Strong instruction following', | ||
| ), | ||
| LlmModelConfig( | ||
| id: 'gemma3-1b', | ||
| name: 'Gemma 3 1B', | ||
| downloadUrl: | ||
| 'https://huggingface.co/bartowski/gemma-3-1b-it-GGUF/resolve/main/gemma-3-1b-it-Q4_K_M.gguf', | ||
| estimatedSizeMB: 780, | ||
| description: 'Most capable curated model', | ||
| ), | ||
| ]; | ||
|
|
||
| /// Embedding model — fixed, not user-selectable. | ||
| static const embeddingModel = LlmModelConfig( | ||
| id: 'bge-small-en', | ||
| name: 'bge-small-en-v1.5', | ||
| downloadUrl: | ||
| 'https://huggingface.co/CompendiumLabs/bge-small-en-v1.5-gguf/resolve/main/bge-small-en-v1.5-q8_0.gguf', | ||
| estimatedSizeMB: 67, | ||
| description: 'Semantic search model', | ||
| ); | ||
|
|
||
| /// Create a config for a user-provided GGUF URL. | ||
| static LlmModelConfig custom({ | ||
| required String name, | ||
| required String downloadUrl, | ||
| }) { | ||
| return LlmModelConfig( | ||
| id: 'custom', | ||
| name: name, | ||
| downloadUrl: downloadUrl, | ||
| estimatedSizeMB: 0, | ||
| description: 'Custom GGUF model', | ||
| isCustom: true, | ||
| ); | ||
| } | ||
|
|
||
| /// Look up a curated model by id. Returns null for unknown ids. | ||
| static LlmModelConfig? findById(String id) { | ||
| for (final m in curated) { | ||
| if (m.id == id) return m; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /// The default curated model. | ||
| static LlmModelConfig get defaultModel => | ||
| findById(defaultModelId) ?? curated.first; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /// App-owned retrieval result for the RAG pipeline. | ||
| /// | ||
| /// Replaces flutter_gemma's RetrievalResult so the pipeline is | ||
| /// decoupled from the inference engine. | ||
| class RetrievalResult { | ||
| final String id; | ||
| final String content; | ||
|
|
||
| /// JSON-encoded metadata (biomarkerKey, reportId, flag, testDate, labName). | ||
| final String? metadata; | ||
|
|
||
| /// Cosine similarity score in [0, 1]. | ||
| final double score; | ||
|
|
||
| const RetrievalResult({ | ||
| required this.id, | ||
| required this.content, | ||
| this.metadata, | ||
| this.score = 0.0, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.