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

Local AI model for Flutter — on-device text embeddings & vector search, fully offline, no API keys or cloud. The engine behind semantic search & RAG.

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 helps others find it.

Features #

  • 100% offline and 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 to embeddings to similarity to 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
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 to ONNX inference to ranking).

More from ksaikiran.dev #

Other Flutter packages for text, search, and input:

Package What it does
text_comparison_score_codespark String similarity — Levenshtein, Damerau-Levenshtein, Jaro-Winkler.
semantic_search_codespark Ready-made offline semantic search built on this engine.
animated_dropdown_search_codespark Dropdown widget with built-in search and highlighting.
text_highlight_codespark Highlight rich text — queries, regex, per-term colors, tappable spans.

Browse the full list on pub.dev/publishers/ksaikiran.dev.

License #

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

8
likes
160
points
336
downloads

Documentation

API reference

Publisher

verified publisherksaikiran.dev

Weekly Downloads

Local AI model for Flutter — on-device text embeddings & vector search, fully offline, no API keys or cloud. The engine behind semantic search & RAG.

Homepage
Repository (GitHub)
View/report issues

Topics

#embeddings #vector-search #offline-ai #local-ai #onnx

License

MIT (license)

Dependencies

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

More

Packages that depend on ai_core_codespark