English | δΈζ
Lightning-fast, in-process vector database for Dart & Flutter β powered by Zvec.
Zvec Dart SDK brings Alibaba's open-source Zvec vector engine to mobile via dart:ffi β no servers, no IPC, just a single dynamic library running in your app's process. Build on-device semantic search, RAG, recommendation, and similarity workloads with milliseconds-level latency.
π« Features
- π Native speed β Direct FFI calls into a battle-tested C++ engine; no method-channel hops, no isolate marshalling.
- π± Mobile-first β Ships prebuilt binaries for Android (
arm64-v8a) and iOS (arm64). - βοΈ Zero-friction install β Native libs are auto-fetched from GitHub Releases at build time. Your
pub.devpackage stays slim. - π§ Rich vector ops β HNSW / IVF / Flat / Inverted indexes, hybrid filters, top-k & group-by queries.
- π Durable storage β Write-ahead log, atomic flush, persistent across app restarts.
- π― Idiomatic Dart β Strongly-typed schema, exception-based error handling, synchronous API.
π¦ Installation
flutter pub add zvec
Or in pubspec.yaml:
dependencies:
zvec: ^0.5.1
Platform support
Platform Architectures Distribution Android arm64-v8a Gradle task downloadZvecNativeLibsiOS arm64 (device) CocoaPods prepare_command(curl + unzip)
β‘ Quick Start
import 'dart:typed_data';
import 'package:zvec/zvec.dart';
void main() {
// 1. Boot the engine
Zvec.initialize();
print('Zvec ${Zvec.version}');
// 2. Define a schema: 4-dim FP32 vector + a string field
final schema = CollectionSchema(name: 'demo', fields: [
VectorSchema('embedding', 4, indexParams: HnswIndexParams()),
FieldSchema(name: 'title', dataType: DataType.string),
]);
// 3. Create & open the collection
final collection = Collection.createAndOpen('/tmp/zvec_demo', schema);
// 4. Insert documents
final docs = [
Doc(id: 'doc_1')
..setField('title', 'hello')
..setVector('embedding', Float32List.fromList([0.1, 0.2, 0.3, 0.4])),
Doc(id: 'doc_2')
..setField('title', 'world')
..setVector('embedding', Float32List.fromList([0.2, 0.3, 0.4, 0.1])),
];
collection.insert(docs);
for (final d in docs) d.destroy();
// 5. Build the index
collection.optimize();
// 6. Vector search β top-k by cosine similarity
final query = VectorQuery(
fieldName: 'embedding',
vector: Float32List.fromList([0.4, 0.3, 0.3, 0.1]),
topk: 5,
outputFields: ['title'],
);
for (final r in collection.query(query)) {
print('${r.pk} score=${r.score} title=${r.getString('title')}');
}
query.destroy();
// 7. Clean up
collection.close();
Zvec.shutdown();
}
A full Flutter demo lives in example/lib/main.dart.
𧬠How Native Libraries Are Distributed
Native libraries are NOT bundled in the pub.dev tarball β they're fetched on first build:
| Platform | Mechanism | Trigger |
|---|---|---|
| Android | Gradle task downloadZvecNativeLibs (android/build.gradle) |
flutter build apk / flutter run |
| iOS | prepare_command in ios/zvec.podspec (curl + unzip) |
pod install |
This keeps the Dart package small and lets us version native binaries independently.
π€ Contributing
Issues and pull requests are welcome! Want to hack on the plugin or rebuild the native libraries? See BUILDING.md for the developer setup. For changes that touch the underlying engine, please file them in the upstream zvec repo instead.
π License
Released under the Apache License 2.0 β same as upstream Zvec.
Libraries
- zvec
- Dart SDK for Zvec β a lightweight, lightning-fast, in-process vector database by Alibaba.