Skip to content

Commit f8b1170

Browse files
committed
Update iOS libs
1 parent 0ac98cd commit f8b1170

File tree

6 files changed

+71
-41
lines changed

6 files changed

+71
-41
lines changed

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ EXTERNAL SOURCES:
20272027
SPEC CHECKSUMS:
20282028
FBLazyVector: 2e5b5553df729e080483373db6f045201ff4e6db
20292029
hermes-engine: 273e30e7fb618279934b0b95ffab60ecedb7acf5
2030-
op-sqlite: 4651f571998e9739cd4fe16f033bd8a159279da6
2030+
op-sqlite: 710ca7b0c7eeef98e62fad9cd22c984f06749563
20312031
OpServer: 9b3ebdeeb095950e760e3c39853cd06849421b35
20322032
RCTDeprecation: c6b36da89aa26090c8684d29c2868dcca2cd4554
20332033
RCTRequired: 1413a0844770d00fa1f1bb2da4680adfa8698065

example/src/tests/queries.ts

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
describe,
1515
it,
1616
} from '@op-engineering/op-test';
17+
import pkg from '../../package.json'
1718

1819
describe('Queries tests', () => {
1920
let db: DB;
@@ -776,45 +777,49 @@ describe('Queries tests', () => {
776777
expect(res.rows).toDeepEqual([{user_version: 0}]);
777778
});
778779

779-
it('sqlite-vec extension: vector similarity search', async () => {
780-
// Create a virtual table for storing vectors
781-
await db.execute(`
782-
CREATE VIRTUAL TABLE vec_items USING vec0(
783-
embedding FLOAT[8]
784-
)
785-
`);
786-
787-
// Insert some sample vectors
788-
await db.execute(`
789-
INSERT INTO vec_items(rowid, embedding)
790-
VALUES
791-
(1, '[-0.200, 0.250, 0.341, -0.211, 0.645, 0.935, -0.316, -0.924]'),
792-
(2, '[0.443, -0.501, 0.355, -0.771, 0.707, -0.708, -0.185, 0.362]'),
793-
(3, '[0.716, -0.927, 0.134, 0.052, -0.669, 0.793, -0.634, -0.162]'),
794-
(4, '[-0.710, 0.330, 0.656, 0.041, -0.990, 0.726, 0.385, -0.958]')
795-
`);
796-
797-
// Perform KNN query to find the 2 nearest neighbors
798-
const queryVector = '[0.890, 0.544, 0.825, 0.961, 0.358, 0.0196, 0.521, 0.175]';
799-
const result = await db.execute(`
800-
SELECT rowid, distance
801-
FROM vec_items
802-
WHERE embedding MATCH ?
803-
ORDER BY distance
804-
LIMIT 2
805-
`, [queryVector]);
806-
807-
// Verify results
808-
expect(result.rows.length).toEqual(2);
809-
expect(result.rows[0]!.rowid).toEqual(2);
810-
expect(result.rows[1]!.rowid).toEqual(1);
811-
812-
// Verify distances are positive numbers
813-
const distance0 = result.rows[0]!.distance as number;
814-
const distance1 = result.rows[1]!.distance as number;
815-
expect(typeof distance0).toEqual('number');
816-
expect(distance0 > 0).toBeTruthy();
817-
expect(distance1 > 0).toBeTruthy();
818-
});
780+
781+
const sqliteVecEnabled = pkg?.['op-sqlite']?.sqliteVec === true;
782+
if (sqliteVecEnabled) {
783+
it('sqlite-vec extension: vector similarity search', async () => {
784+
// Create a virtual table for storing vectors
785+
await db.execute(`
786+
CREATE VIRTUAL TABLE vec_items USING vec0(
787+
embedding FLOAT[8]
788+
)
789+
`);
790+
791+
// Insert some sample vectors
792+
await db.execute(`
793+
INSERT INTO vec_items(rowid, embedding)
794+
VALUES
795+
(1, '[-0.200, 0.250, 0.341, -0.211, 0.645, 0.935, -0.316, -0.924]'),
796+
(2, '[0.443, -0.501, 0.355, -0.771, 0.707, -0.708, -0.185, 0.362]'),
797+
(3, '[0.716, -0.927, 0.134, 0.052, -0.669, 0.793, -0.634, -0.162]'),
798+
(4, '[-0.710, 0.330, 0.656, 0.041, -0.990, 0.726, 0.385, -0.958]')
799+
`);
800+
801+
// Perform KNN query to find the 2 nearest neighbors
802+
const queryVector = '[0.890, 0.544, 0.825, 0.961, 0.358, 0.0196, 0.521, 0.175]';
803+
const result = await db.execute(`
804+
SELECT rowid, distance
805+
FROM vec_items
806+
WHERE embedding MATCH ?
807+
ORDER BY distance
808+
LIMIT 2
809+
`, [queryVector]);
810+
811+
// Verify results
812+
expect(result.rows.length).toEqual(2);
813+
expect(result.rows[0]!.rowid).toEqual(2);
814+
expect(result.rows[1]!.rowid).toEqual(1);
815+
816+
// Verify distances are positive numbers
817+
const distance0 = result.rows[0]!.distance as number;
818+
const distance1 = result.rows[1]!.distance as number;
819+
expect(typeof distance0).toEqual('number');
820+
expect(distance0 > 0).toBeTruthy();
821+
expect(distance1 > 0).toBeTruthy();
822+
});
823+
}
819824

820825
});
512 Bytes
Binary file not shown.
31.1 KB
Binary file not shown.

scripts/turnOnLibsql.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const packageJson = JSON.parse(fs.readFileSync('./example/package.json'));
66
// Modify the op-sqlite.sqlcipher key to true
77
packageJson['op-sqlite']['libsql'] = true;
88
packageJson['op-sqlite']['sqlcipher'] = false;
9+
packageJSON['op-sqlite']['sqliteVec'] = false;
910

1011
// Save the updated package.json file
1112
fs.writeFileSync(

scripts/update-sqlitevec.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Change to the iOS directory
6+
cd "$(dirname "$0")/../ios"
7+
8+
echo "📦 Updating sqlitevec.xcframework binaries..."
9+
10+
# Device (ios-arm64)
11+
echo "🔨 Processing device binary (ios-arm64)..."
12+
cp vec0-ios-aarch64.dylib sqlitevec
13+
install_name_tool -id @rpath/sqlitevec.framework/sqlitevec sqlitevec
14+
codesign -f -s - --identifier com.op.sqlitevec sqlitevec
15+
mv sqlitevec sqlitevec.xcframework/ios-arm64/sqlitevec.framework/
16+
17+
# Simulator (ios-arm64_x86_64-simulator) - create fat binary
18+
echo "🔨 Processing simulator binaries (arm64 + x86_64)..."
19+
lipo -create vec0-iossimulator-aarch64.dylib vec0-iossimulator-x86_64.dylib -output sqlitevec
20+
install_name_tool -id @rpath/sqlitevec.framework/sqlitevec sqlitevec
21+
codesign -f -s - --identifier com.op.sqlitevec sqlitevec
22+
mv sqlitevec sqlitevec.xcframework/ios-arm64_x86_64-simulator/sqlitevec.framework/
23+
24+
echo "✅ sqlitevec.xcframework updated successfully!"

0 commit comments

Comments
 (0)