Skip to content

Commit 4a60ec0

Browse files
committed
feat(docs): update README with Android package integration
1 parent 0395ed2 commit 4a60ec0

File tree

1 file changed

+65
-7
lines changed

1 file changed

+65
-7
lines changed

README.md

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ Download the appropriate pre-built binary for your platform from the official [R
4040
- Android
4141
- iOS
4242

43+
### Loading the Extension
44+
45+
```sql
46+
-- In SQLite CLI
47+
.load ./vector
48+
49+
-- In SQL
50+
SELECT load_extension('./vector');
51+
```
52+
53+
Or embed it directly into your application.
54+
4355
### WASM Version
4456

4557
You can download the WebAssembly (WASM) version of SQLite with the SQLite Vector extension enabled from: https://www.npmjs.com/package/@sqliteai/sqlite-wasm
@@ -67,17 +79,63 @@ log("vector_version(): \(String(cString: sqlite3_column_text(stmt, 0)))")
6779
sqlite3_close(db)
6880
```
6981

70-
### Loading the Extension
82+
### Android Package
7183

72-
```sql
73-
-- In SQLite CLI
74-
.load ./vector
84+
You can [add this project as a dependency to your Android project](https://central.sonatype.com/artifact/ai.sqlite/vector).
85+
```gradle
86+
repositories {
87+
google()
88+
mavenCentral()
89+
maven { url 'https://jitpack.io' }
90+
}
7591
76-
-- In SQL
77-
SELECT load_extension('./vector');
92+
dependencies {
93+
94+
...
95+
96+
implementation 'com.github.requery:sqlite-android:3.49.0'
97+
implementation 'ai.sqlite:vector:0.9.32' // or 'com.github.sqliteai:sqlite-vector:0.9.32'
98+
}
7899
```
79100

80-
Or embed it directly into your application.
101+
After adding the package, you'll need to [enable extractNativeLibs](https://github.com/sqliteai/sqlite-extensions-guide/blob/18acfc56d6af8791928f3ac8df7dc0e6a9741dd4/examples/android/src/main/AndroidManifest.xml#L6).
102+
103+
Here's an example of how to use the package:
104+
```java
105+
import android.database.Cursor;
106+
import io.requery.android.database.sqlite.SQLiteCustomExtension;
107+
import io.requery.android.database.sqlite.SQLiteDatabase;
108+
import io.requery.android.database.sqlite.SQLiteDatabaseConfiguration;
109+
import java.util.Collections;
110+
111+
...
112+
113+
private void vectorExtension() {
114+
try {
115+
SQLiteCustomExtension vectorExtension = new SQLiteCustomExtension(getApplicationInfo().nativeLibraryDir + "/vector", null);
116+
SQLiteDatabaseConfiguration config = new SQLiteDatabaseConfiguration(
117+
getCacheDir().getPath() + "/vector_test.db",
118+
SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.OPEN_READWRITE,
119+
Collections.emptyList(),
120+
Collections.emptyList(),
121+
Collections.singletonList(vectorExtension)
122+
);
123+
124+
SQLiteDatabase db = SQLiteDatabase.openDatabase(config, null, null);
125+
126+
Cursor cursor = db.rawQuery("SELECT vector_version()", null);
127+
if (cursor.moveToFirst()) {
128+
String version = cursor.getString(0);
129+
resultTextView.setText("vector_version(): " + version);
130+
}
131+
cursor.close();
132+
db.close();
133+
134+
} catch (Exception e) {
135+
resultTextView.setText("❌ Error: " + e.getMessage());
136+
}
137+
}
138+
```
81139

82140
### Python Package
83141

0 commit comments

Comments
 (0)