ai_core_codespark 0.1.0 copy "ai_core_codespark: ^0.1.0" to clipboard
ai_core_codespark: ^0.1.0 copied to clipboard

On-device text embeddings for Flutter: auto-downloads a verified MiniLM ONNX model, WordPiece tokenizer, cosine similarity and a vector store. Offline, no API keys.

ai_core_codespark #

pub package pub points license: MIT

On-device text embeddings for Flutter — offline, no API keys, no cloud.

ai_core_codespark is the local AI engine the *_codespark family is built on. It turns text into vectors entirely on the device using a quantized MiniLM ONNX model, with a WordPiece tokenizer, cosine similarity, and a vector store included. Point it at a list of strings and rank them by meaning — no OpenAI, Gemini, Ollama, or server required.

💙 If this saves you a backend, please ⭐ star the repo and 👍 like it on pub.dev — it genuinely helps others find it.

Features #

  • 🔒 100% offline & private — text never leaves the device.
  • 🔑 No API keys, no cloud, no subscriptions.
  • 📦 Zero-setup model management — the model auto-downloads on first run, is SHA-256 verified, and cached. No manual curl, no asset wrangling.
  • 🧠 Full pipeline included — tokenizer → embeddings → similarity → store. You don't bring your own vectors; it generates them.
  • Verified tokenizer — matches the HuggingFace reference byte-for-byte (accents, CJK, Cyrillic, punctuation), so embeddings are correct.
  • 🧵 Off the UI thread — inference runs on a background isolate.
  • 🪶 Small app binary — the ~23 MB model is downloaded, not bundled.

How it compares #

Package On-device No API key Model handling Tokenizer + embeddings included
ai_core_codespark auto-download + SHA-256 verify + cache ✅ (parity-verified)
mobile_rag_engine manual curl into assets
pocket_brain bundled (adds weight to every app)
veda / realm vector DBs none ❌ bring your own vectors
zir_semantic_search ❌ cloud server API

Why download instead of bundle? A real transformer is ~23 MB — bundling it (like some packages do) bloats every app build, even screens that never search. We download once on first launch and cache it, so your binary stays lean and the model is shared across updates. The URL and checksum are overridable, so enterprises can self-host or ship the file for fully air-gapped installs.

Install #

dependencies:
  ai_core_codespark: ^0.1.0

Quick start #

import 'package:ai_core_codespark/ai_core_codespark.dart';

final engine = CodesparkEngine(model: ModelCatalog.miniLmL6V2);

// Downloads (~23 MB) + verifies the model on first run only, then caches it.
await engine.initialize(
  onProgress: (received, total) => print('Model: $received / $total'),
);

final vector = await engine.embed('hello world'); // Float32List, length 384

Rank a list by meaning #

const items = ['automobile', 'banana', 'vehicle', 'fruit smoothie'];

final store = VectorStore();
final vectors = await engine.embedBatch(items);
for (var i = 0; i < items.length; i++) {
  store.add(VectorRecord(id: items[i], vector: vectors[i]));
}

final query = await engine.embed('car');
for (final hit in store.search(query, k: 2, threshold: 0.3)) {
  print('${hit.record.id}  (${hit.score.toStringAsFixed(3)})');
}
// automobile (0.61), vehicle (0.60) — banana & smoothie fall below the threshold.

Need ready-made search UI on top of this? See semantic_search_codespark.

What's inside #

Piece What it does
CodesparkEngine One facade: download → load → embed (on an isolate).
ModelManager / ModelConfig Download, SHA-256 verify, cache, evict; pinned model catalog.
BertTokenizer Pure-Dart WordPiece tokenization, parity-verified.
Embedder / EmbedderIsolate ONNX inference, pooling (mean/cls/max), L2 normalize.
Similarity cosine, dot, topK, mmr (diversity-aware ranking).
VectorStore In-memory brute-force search + JSON persistence.

Platform support #

Android iOS macOS Windows Linux Web
⚠️ experimental

On the web there are no FFI background isolates — construct the engine with useIsolate: false to run inference inline.

Quality #

  • Tokenizer parity verified byte-for-byte against the HuggingFace reference.
  • int8 model output ≈ fp32 reference at cosine 0.99.
  • End-to-end tested on a real device (model download → ONNX inference → ranking).

License #

MIT © Sai Kiran Katayath — part of the codespark on-device AI ecosystem · ksaikiran.dev

If you ship something with it, a ⭐ on GitHub and a 👍 on pub.dev are hugely appreciated.

8
likes
0
points
336
downloads

Publisher

verified publisherksaikiran.dev

Weekly Downloads

On-device text embeddings for Flutter: auto-downloads a verified MiniLM ONNX model, WordPiece tokenizer, cosine similarity and a vector store. Offline, no API keys.

Homepage
Repository (GitHub)
View/report issues

Topics

#embeddings #semantic-search #onnx #nlp #on-device

License

unknown (license)

Dependencies

crypto, flutter, http, onnxruntime, path, path_provider, unorm_dart

More

Packages that depend on ai_core_codespark