Skip to content

Commit

Permalink
doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Jun 25, 2024
1 parent 3a8ab9b commit dada170
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
6 changes: 3 additions & 3 deletions reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ functions:
vec_version:
params: []
section: meta
desc: x
example: x
desc: Returns a version string of the current `sqlite-vec` version.
example: select vec_version();
vec_debug:
params: []
section: meta
Expand Down Expand Up @@ -118,4 +118,4 @@ entrypoints:
compile_options:
- SQLITE_VEC_ENABLE_AVX
- SQLITE_VEC_ENABLE_NEON

Empty file removed site/using/deno.md
Empty file.
45 changes: 38 additions & 7 deletions site/using/js.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Using `sqlite-vec` in Node.js, Deno, and Bun

[![npm](https://img.shields.io/npm/v/sqlite-vec.svg?color=green&logo=nodedotjs&logoColor=white)](https://www.npmjs.com/package/sqlite-vec)

To use `sqlite-vec` in Node.js, Deno or Bun, install the
[`sqlite-vec` NPM package](https://npmjs.com/package/sqlite-vec) using your
favorite package manager:
Expand Down Expand Up @@ -40,26 +42,55 @@ console.log(`vec_version=${vec_version}`);
The `load()` function is compatable with
[`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3),
[`node-sqlite3`](https://github.com/TryGhost/node-sqlite3),
[`js:@db/sqlite`](https://jsr.io/@db/sqlite) (Deno), and
[`jsr:@db/sqlite`](https://jsr.io/@db/sqlite) (Deno), and
[`bun:sqlite`](https://bun.sh/docs/api/sqlite).

## Working with vectors in JavaScript

if your vectors are represented as an array of numbers, use
[Float32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array),
use the
if your vectors are represented as an array of numbers, wrap it in a
[`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array),
and use
[`.buffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/buffer)
accessor to insert the underlying ArrayBuffer.
accessor to bind as a parameter to `sqlite-vec` SQL functions.

```js
const embedding = new Float32Array([0.1, 0.2, 0.3]);
// TODO
const embedding = new Float32Array([0.1, 0.2, 0.3, 0.4]);
const stmt = db.prepare("INSERT INTO vss_demo VALUES (?)");
stmt.run(embedding.buffer);

```

## Node.js

Here's a quick recipe of using `sqlite-vec` with [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3) in Node.js.

```js

```

See [`simple-node/demo.mjs`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-node/demo.mjs)
for a more complete Node.js demo.

## Deno

Here's a quick recipe of using `sqlite-vec` with [`jsr:@db/sqlite`](https://jsr.io/@db/sqlite) in Deno. It will only work on Deno version `1.44` or greater, because of a bug in previous Deno version.

Keep in mind, the `better-sqlite3` example above also works in Deno, you just need to prefix the `better-sqlite3` import with `npm:`, like `import * from "npm:better-sqlite3"`.

```ts

```

See [`simple-deno/demo.ts`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-deno/demo.ts)
for a more complete Deno demo.

## Bun

Here's a quick recipe of using `sqlite-vec` with [`bun:sqlite`](https://bun.sh/docs/api/sqlite) in Bun. The `better-sqlite3` example above also works with Bun.

```ts

```

See [`simple-bun/demo.ts`](https://github.com/asg017/sqlite-vec/blob/main/examples/simple-bun/demo.ts)
for a more complete Bun demo.
14 changes: 12 additions & 2 deletions site/using/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ If your vectors are from `numpy` arrays, the Python SQLite package allows you to

```python
import numpy as np
import sqlite3
import sqlite_vec

db = sqlite3.connect(":memory:")
db.enable_load_extension(True)
sqlite_vec.load(db)
db.enable_load_extension(False)

db.execute("CREATE VIRTUAL TABLE vec_demo(sample_embedding float[4])")

embedding = np.array([0.1, 0.2, 0.3, 0.4])
result = db.execute('select vec_length(?)', [embedding.astype(np.float32)]).fetchone()[0]
print(result) # 4
db.execute(
"INSERT INTO vec_demo(sample_embedding) VALUES (?)", [embedding.astype(np.float32)]
)
```

## Recipes
Expand Down

0 comments on commit dada170

Please sign in to comment.