Skip to content

Commit efa1bb8

Browse files
committed
Improved example
1 parent 9bee536 commit efa1bb8

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ Get the nearest neighbors
5858
local embedding = pgvector.new({1, 1, 1})
5959
local res = pg:query("SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5", embedding)
6060
for i, row in ipairs(res) do
61-
for k, v in pairs(row) do
62-
print(k, v)
63-
end
61+
print(row["id"])
6462
end
6563
```
6664

test/example.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ local embedding3 = pgvector.new({1, 1, 2})
1818
assert(pg:query("INSERT INTO items (embedding) VALUES ($1), ($2), ($3)", embedding1, embedding2, embedding3))
1919

2020
-- optional: automatically convert vector type to table
21-
-- pgvector.setup_vector(pg)
21+
pgvector.setup_vector(pg)
2222

2323
local embedding = pgvector.new({1, 1, 1})
2424
local res = assert(pg:query("SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5", embedding))
2525
for i, row in ipairs(res) do
26-
for k, v in pairs(row) do
27-
print(k, v)
28-
end
26+
print(row["id"])
27+
print(row["embedding"])
2928
end
3029

3130
assert(pg:query("CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)"))

0 commit comments

Comments
 (0)