Skip to content

Commit 64d09ee

Browse files
authored
Update README.md
1 parent 1dac2ae commit 64d09ee

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,39 @@ Or embed it directly into your application.
5656

5757
You can download the WebAssembly (WASM) version of SQLite with the SQLite Vector extension enabled from: https://www.npmjs.com/package/@sqliteai/sqlite-wasm
5858

59+
## Example Usage
60+
61+
```sql
62+
-- Create a regular SQLite table
63+
CREATE TABLE images (
64+
id INTEGER PRIMARY KEY,
65+
embedding BLOB, -- store Float32/UInt8/etc.
66+
label TEXT
67+
);
68+
69+
-- Insert a BLOB vector (Float32, 384 dimensions) using bindings
70+
INSERT INTO images (embedding, label) VALUES (?, 'cat');
71+
72+
-- Insert a JSON vector (Float32, 384 dimensions)
73+
INSERT INTO images (embedding, label) VALUES (vector_as_f32('[0.3, 1.0, 0.9, 3.2, 1.4,...]'), 'dog');
74+
75+
-- Initialize the vector. By default, the distance function is L2.
76+
-- To use a different metric, specify one of the following options:
77+
-- distance=L1, distance=COSINE, distance=DOT, or distance=SQUARED_L2.
78+
SELECT vector_init('images', 'embedding', 'type=FLOAT32,dimension=384');
79+
80+
-- Quantize vector
81+
SELECT vector_quantize('images', 'embedding');
82+
83+
-- Optional preload quantized version in memory (for a 4x/5x speedup)
84+
SELECT vector_quantize_preload('images', 'embedding');
85+
86+
-- Run a nearest neighbor query on the quantized version (returns top 20 closest vectors)
87+
SELECT e.id, v.distance FROM images AS e
88+
JOIN vector_quantize_scan('images', 'embedding', ?, 20) AS v
89+
ON e.id = v.rowid;
90+
```
91+
5992
### Swift Package
6093

6194
You can [add this repository as a package dependency to your Swift project](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app#Add-a-package-dependency). After adding the package, you'll need to set up SQLite with extension loading by following steps 4 and 5 of [this guide](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/platforms/ios.md#4-set-up-sqlite-with-extension-loading).
@@ -112,39 +145,6 @@ pip install sqliteai-vector
112145

113146
For usage details and examples, see the [Python package documentation](./packages/python/README.md).
114147

115-
## Example Usage
116-
117-
```sql
118-
-- Create a regular SQLite table
119-
CREATE TABLE images (
120-
id INTEGER PRIMARY KEY,
121-
embedding BLOB, -- store Float32/UInt8/etc.
122-
label TEXT
123-
);
124-
125-
-- Insert a BLOB vector (Float32, 384 dimensions) using bindings
126-
INSERT INTO images (embedding, label) VALUES (?, 'cat');
127-
128-
-- Insert a JSON vector (Float32, 384 dimensions)
129-
INSERT INTO images (embedding, label) VALUES (vector_as_f32('[0.3, 1.0, 0.9, 3.2, 1.4,...]'), 'dog');
130-
131-
-- Initialize the vector. By default, the distance function is L2.
132-
-- To use a different metric, specify one of the following options:
133-
-- distance=L1, distance=COSINE, distance=DOT, or distance=SQUARED_L2.
134-
SELECT vector_init('images', 'embedding', 'type=FLOAT32,dimension=384');
135-
136-
-- Quantize vector
137-
SELECT vector_quantize('images', 'embedding');
138-
139-
-- Optional preload quantized version in memory (for a 4x/5x speedup)
140-
SELECT vector_quantize_preload('images', 'embedding');
141-
142-
-- Run a nearest neighbor query on the quantized version (returns top 20 closest vectors)
143-
SELECT e.id, v.distance FROM images AS e
144-
JOIN vector_quantize_scan('images', 'embedding', ?, 20) AS v
145-
ON e.id = v.rowid;
146-
```
147-
148148
## Documentation
149149

150150
Extensive API documentation can be found in the [API page](https://github.com/sqliteai/sqlite-vector/blob/main/API.md).

0 commit comments

Comments
 (0)