From ae9bf0dc22f0208bddadb351a2cbbabb5e376dc9 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 31 Oct 2023 00:31:09 -0700 Subject: [PATCH] Improved example --- README.md | 12 ++++++------ example.nim | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1532853..c2af493 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,17 @@ Insert vectors ```nim import std/json -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 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 rows = db.getAllRows(sql"SELECT * FROM items ORDER BY embedding <-> ? LIMIT 5", embedding) +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 25aece1..de6469c 100644 --- a/example.nim +++ b/example.nim @@ -8,13 +8,13 @@ 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]; -db.exec(sql"INSERT INTO items (embedding) VALUES (?), (?), (?)", embedding1, embedding2, embedding3) +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 rows = db.getAllRows(sql"SELECT * FROM items ORDER BY embedding <-> ? LIMIT 5", embedding) +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])