From f069c340c4961b392455f5e1f08a8a7b2cd8c8ba Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 31 Oct 2023 00:36:42 -0700 Subject: [PATCH] Improved code --- README.md | 8 ++++---- example.nim | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c2af493..f94e09c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example.nim b/example.nim index de6469c..2911afb 100644 --- a/example.nim +++ b/example.nim @@ -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])