Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 31, 2023
1 parent ae9bf0d commit f069c34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ Insert vectors
```nim
import std/json
let embedding1 = @[1, 1, 1];
let embedding2 = @[1, 1, 2];
let embedding3 = @[2, 2, 2];
let embedding1 = @[1, 1, 1]
let embedding2 = @[1, 1, 2]
let embedding3 = @[2, 2, 2]
db.exec(sql"INSERT INTO items (embedding) VALUES (?), (?), (?)", %* embedding1, %* embedding2, %* embedding3)
```

Get the nearest neighbors

```nim
let embedding = @[1, 1, 1];
let embedding = @[1, 1, 1]
let rows = db.getAllRows(sql"SELECT * FROM items ORDER BY embedding <-> ? LIMIT 5", %* embedding)
for row in rows:
echo row
Expand Down
8 changes: 4 additions & 4 deletions example.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ db.exec(sql"DROP TABLE IF EXISTS items")

db.exec(sql"CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))")

let embedding1 = @[1, 1, 1];
let embedding2 = @[1, 1, 2];
let embedding3 = @[2, 2, 2];
let embedding1 = @[1, 1, 1]
let embedding2 = @[1, 1, 2]
let embedding3 = @[2, 2, 2]
db.exec(sql"INSERT INTO items (embedding) VALUES (?), (?), (?)", %* embedding1, %* embedding2, %* embedding3)

let embedding = @[1, 1, 1];
let embedding = @[1, 1, 1]
let rows = db.getAllRows(sql"SELECT * FROM items ORDER BY embedding <-> ? LIMIT 5", %* embedding)
for row in rows:
echo row[0], ": ", parseJson(row[1])
Expand Down

0 comments on commit f069c34

Please sign in to comment.