Skip to content

Commit 57d0d87

Browse files
committed
Added Flutter multi-platform package
1 parent c42510a commit 57d0d87

File tree

14 files changed

+359
-0
lines changed

14 files changed

+359
-0
lines changed

.github/workflows/main.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,55 @@ jobs:
392392
echo " Platform packages: 7"
393393
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
394394
395+
- name: assemble flutter package
396+
if: steps.tag.outputs.version != ''
397+
run: |
398+
VERSION=${{ steps.tag.outputs.version }}
399+
FLUTTER_DIR=packages/flutter
400+
401+
# Android
402+
mkdir -p $FLUTTER_DIR/native_libraries/android
403+
cp artifacts/vector-android-arm64-v8a/vector.so $FLUTTER_DIR/native_libraries/android/vector_android_arm64.so
404+
cp artifacts/vector-android-armeabi-v7a/vector.so $FLUTTER_DIR/native_libraries/android/vector_android_arm.so
405+
cp artifacts/vector-android-x86_64/vector.so $FLUTTER_DIR/native_libraries/android/vector_android_x64.so
406+
407+
# iOS device
408+
mkdir -p $FLUTTER_DIR/native_libraries/ios
409+
cp artifacts/vector-ios/vector.dylib $FLUTTER_DIR/native_libraries/ios/vector_ios_arm64.dylib
410+
411+
# iOS simulator (keep universal/fat binary as-is)
412+
mkdir -p $FLUTTER_DIR/native_libraries/ios-sim
413+
cp artifacts/vector-ios-sim/vector.dylib $FLUTTER_DIR/native_libraries/ios-sim/vector_ios-sim.dylib
414+
415+
# macOS (separate arch-specific dylibs)
416+
mkdir -p $FLUTTER_DIR/native_libraries/mac
417+
cp artifacts/vector-macos-arm64/vector.dylib $FLUTTER_DIR/native_libraries/mac/vector_mac_arm64.dylib
418+
cp artifacts/vector-macos-x86_64/vector.dylib $FLUTTER_DIR/native_libraries/mac/vector_mac_x64.dylib
419+
420+
# Linux
421+
mkdir -p $FLUTTER_DIR/native_libraries/linux
422+
cp artifacts/vector-linux-x86_64/vector.so $FLUTTER_DIR/native_libraries/linux/vector_linux_x64.so
423+
cp artifacts/vector-linux-arm64/vector.so $FLUTTER_DIR/native_libraries/linux/vector_linux_arm64.so
424+
425+
# Windows
426+
mkdir -p $FLUTTER_DIR/native_libraries/windows
427+
cp artifacts/vector-windows-x86_64/vector.dll $FLUTTER_DIR/native_libraries/windows/vector_windows_x64.dll
428+
429+
# Update version
430+
sed -i "s/^version: .*/version: $VERSION/" $FLUTTER_DIR/pubspec.yaml
431+
432+
# Publish (commented out until pub.dev OIDC is configured)
433+
# cd $FLUTTER_DIR
434+
# dart pub publish --dry-run
435+
# dart pub publish --force
436+
395437
- uses: softprops/action-gh-release@v2.2.1
396438
if: steps.tag.outputs.version != ''
397439
with:
398440
body: |
399441
# Packages
400442
443+
[**Flutter/Dart**](https://pub.dev/packages/sqlite_vector): `dart pub add sqlite_vector`
401444
[**Node**](https://www.npmjs.com/package/@sqliteai/sqlite-vector): `npm install @sqliteai/sqlite-vector`
402445
[**WASM**](https://www.npmjs.com/package/@sqliteai/sqlite-wasm): `npm install @sqliteai/sqlite-wasm`
403446
[**Android**](https://central.sonatype.com/artifact/ai.sqlite/vector): `ai.sqlite:vector:${{ steps.tag.outputs.version }}`

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ packages/node/test-platform-packages/
4545
.DS_Store
4646
Thumbs.db
4747
CLAUDE.md
48+
49+
# Dart/Flutter
50+
.dart_tool/
51+
pubspec.lock

examples/flutter/lib/main.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2025 SQLite Cloud, Inc.
2+
// Licensed under the Elastic License 2.0 (see LICENSE.md).
3+
4+
import 'package:sqlite3/sqlite3.dart';
5+
import 'package:sqlite_vector/sqlite_vector.dart';
6+
7+
void main() {
8+
// Load the sqlite-vector extension (call once at startup).
9+
sqlite3.loadSqliteVectorExtension();
10+
11+
// Open an in-memory database.
12+
final db = sqlite3.openInMemory();
13+
14+
// Verify the extension is loaded.
15+
final version = db.select('SELECT vector_version()');
16+
print('sqlite-vector version: ${version.first.values.first}');
17+
18+
// Create a regular table with a BLOB column for vectors.
19+
db.execute('''
20+
CREATE TABLE items (
21+
id INTEGER PRIMARY KEY,
22+
embedding BLOB
23+
)
24+
''');
25+
26+
// Insert sample Float32 vectors (4 dimensions).
27+
final stmt =
28+
db.prepare('INSERT INTO items (embedding) VALUES (vector_as_f32(?))');
29+
stmt.execute(['[1.0, 2.0, 3.0, 4.0]']);
30+
stmt.execute(['[5.0, 6.0, 7.0, 8.0]']);
31+
stmt.execute(['[1.1, 2.1, 3.1, 4.1]']);
32+
stmt.dispose();
33+
34+
// Initialize the vector index.
35+
db.execute(
36+
"SELECT vector_init('items', 'embedding', 'type=FLOAT32,dimension=4')",
37+
);
38+
39+
// Find the 2 nearest neighbors using vector_full_scan.
40+
final results = db.select('''
41+
SELECT e.id, v.distance
42+
FROM items AS e
43+
JOIN vector_full_scan('items', 'embedding', vector_as_f32('[1.0, 2.0, 3.0, 4.0]'), 2) AS v
44+
ON e.id = v.rowid
45+
''');
46+
47+
print('Nearest neighbors:');
48+
for (final row in results) {
49+
print(' id=${row['id']}, distance=${row['distance']}');
50+
}
51+
52+
db.dispose();
53+
}

examples/flutter/pubspec.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: sqlite_vector_example
2+
description: Example app demonstrating sqlite_vector usage.
3+
publish_to: none
4+
5+
environment:
6+
sdk: ^3.10.0
7+
8+
dependencies:
9+
sqlite3: ^3.0.0
10+
sqlite_vector:
11+
path: ../../packages/flutter

packages/flutter/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
native_libraries/

packages/flutter/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 0.9.70
2+
3+
- Initial release.
4+
- Bundles pre-built sqlite-vector binaries for Android, iOS, macOS, Linux, and Windows.
5+
- Provides `loadSqliteVectorExtension()` for use with `sqlite3` and `drift`.

packages/flutter/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE.md

packages/flutter/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# sqlite_vector
2+
3+
SQLite Vector extension for Flutter/Dart. Provides vector search with SIMD-optimized distance functions (L2, cosine, dot product) for Float32, Float16, Int8, and 1Bit vectors.
4+
5+
## Installation
6+
7+
```
8+
dart pub add sqlite_vector
9+
```
10+
11+
Requires Dart 3.10+ / Flutter 3.38+.
12+
13+
## Usage
14+
15+
### With `sqlite3`
16+
17+
```dart
18+
import 'package:sqlite3/sqlite3.dart';
19+
import 'package:sqlite_vector/sqlite_vector.dart';
20+
21+
void main() {
22+
// Load once at startup.
23+
sqlite3.loadSqliteVectorExtension();
24+
25+
final db = sqlite3.openInMemory();
26+
27+
// Create a regular table with a BLOB column for vectors.
28+
db.execute('CREATE TABLE items (id INTEGER PRIMARY KEY, embedding BLOB)');
29+
30+
// Insert vectors.
31+
final stmt = db.prepare('INSERT INTO items (embedding) VALUES (vector_as_f32(?))');
32+
stmt.execute(['[1.0, 2.0, 3.0, 4.0]']);
33+
stmt.dispose();
34+
35+
// Initialize the vector index.
36+
db.execute("SELECT vector_init('items', 'embedding', 'type=FLOAT32,dimension=4')");
37+
38+
// Find the 2 nearest neighbors.
39+
final results = db.select('''
40+
SELECT e.id, v.distance FROM items AS e
41+
JOIN vector_full_scan('items', 'embedding', vector_as_f32('[1.0, 2.0, 3.0, 4.0]'), 2) AS v
42+
ON e.id = v.rowid
43+
''');
44+
45+
db.dispose();
46+
}
47+
```
48+
49+
### With `drift`
50+
51+
```dart
52+
import 'package:sqlite3/sqlite3.dart';
53+
import 'package:sqlite_vector/sqlite_vector.dart';
54+
import 'package:drift/native.dart';
55+
56+
Sqlite3 loadExtensions() {
57+
sqlite3.loadSqliteVectorExtension();
58+
return sqlite3;
59+
}
60+
61+
// Use when creating the database:
62+
NativeDatabase.createInBackground(
63+
File(path),
64+
sqlite3: loadExtensions,
65+
);
66+
```
67+
68+
## Supported platforms
69+
70+
| Platform | Architectures |
71+
|----------|---------------|
72+
| Android | arm64, arm, x64 |
73+
| iOS | arm64 (device + simulator) |
74+
| macOS | arm64, x64 |
75+
| Linux | arm64, x64 |
76+
| Windows | x64 |
77+
78+
## API
79+
80+
See the full [sqlite-vector API documentation](https://github.com/sqliteai/sqlite-vector/blob/main/API.md).
81+
82+
## License
83+
84+
See [LICENSE](LICENSE).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

packages/flutter/example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../examples/flutter

0 commit comments

Comments
 (0)