Skip to content

Commit e745334

Browse files
committed
Added docs for getting items within a certain distance with Kysely - closes #24
1 parent 89aaa35 commit e745334

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ const items = await db.selectFrom('items')
247247

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

250+
Get items within a certain distance
251+
252+
```javascript
253+
const items = await db.selectFrom('items')
254+
.selectAll()
255+
.where(l2Distance('embedding', [1, 2, 3]), '<', 5)
256+
.execute();
257+
```
258+
250259
Add an approximate index
251260

252261
```javascript

tests/kysely.test.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ test('kysely example', async () => {
108108
.execute();
109109
assert.deepEqual(items.map(v => v.id), [2, 3, 1, 4]);
110110

111+
// within distance
112+
items = await db.selectFrom('kysely_items')
113+
.selectAll()
114+
.where(l2Distance('embedding', [1, 1, 1]), '<', 0.5)
115+
.execute();
116+
assert.deepEqual(items.map(v => v.id), [1]);
117+
111118
await db.schema.createIndex('kysely_items_embedding_idx')
112119
.on('kysely_items')
113120
.using('hnsw')

0 commit comments

Comments
 (0)