ai_core_codespark 0.1.1 copy "ai_core_codespark: ^0.1.1" to clipboard
ai_core_codespark: ^0.1.1 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.

example/main.dart

// A ~30-line preview of what `semantic_search_codespark` becomes once it sits
// on top of this core. This is the DX the whole ecosystem is selling.
import 'package:ai_core_codespark/ai_core_codespark.dart';

Future<void> main() async {
  // 1. One engine, downloads + verifies the model on first run.
  final engine = CodesparkEngine(model: ModelCatalog.miniLmL6V2);
  await engine.initialize(
    onProgress: (received, total) {
      final pct = total > 0 ? (received / total * 100).toStringAsFixed(0) : '?';
      // ignore: avoid_print
      print('Downloading model… $pct%');
    },
  );

  // 2. Embed a corpus once and stash it in the vector store.
  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]));
  }

  // 3. Search by meaning, not spelling.
  final query = await engine.embed('car');
  for (final hit in store.search(query, k: 2, threshold: 0.3)) {
    // ignore: avoid_print
    print('${hit.record.id}  (${hit.score.toStringAsFixed(3)})');
  }
  // Expected: automobile (~0.6), vehicle (~0.6) — banana/smoothie fall below.

  await engine.dispose();
}
8
likes
160
points
336
downloads

Documentation

API reference

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

MIT (license)

Dependencies

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

More

Packages that depend on ai_core_codespark