Skip to content

Commit

Permalink
Added docs for getting items within a certain distance with Kysely - c…
Browse files Browse the repository at this point in the history
…loses #24
  • Loading branch information
ankane committed Jul 17, 2024
1 parent 89aaa35 commit e745334
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ const items = await db.selectFrom('items')

Also supports `maxInnerProduct`, `cosineDistance`, `l1Distance`, `hammingDistance`, and `jaccardDistance`

Get items within a certain distance

```javascript
const items = await db.selectFrom('items')
.selectAll()
.where(l2Distance('embedding', [1, 2, 3]), '<', 5)
.execute();
```

Add an approximate index

```javascript
Expand Down
7 changes: 7 additions & 0 deletions tests/kysely.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ test('kysely example', async () => {
.execute();
assert.deepEqual(items.map(v => v.id), [2, 3, 1, 4]);

// within distance
items = await db.selectFrom('kysely_items')
.selectAll()
.where(l2Distance('embedding', [1, 1, 1]), '<', 0.5)
.execute();
assert.deepEqual(items.map(v => v.id), [1]);

await db.schema.createIndex('kysely_items_embedding_idx')
.on('kysely_items')
.using('hnsw')
Expand Down

0 comments on commit e745334

Please sign in to comment.