mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 00:36:56 +02:00
example updates
This commit is contained in:
parent
12c96fc6fe
commit
85fac4c5ef
10 changed files with 112 additions and 76 deletions
|
|
@ -10,19 +10,23 @@ db.enable_load_extension(false)
|
|||
sqlite_version, vec_version = db.execute("select sqlite_version(), vec_version()").first
|
||||
puts "sqlite_version=#{sqlite_version}, vec_version=#{vec_version}"
|
||||
|
||||
db.execute("CREATE VIRTUAL TABLE vec_items USING vec0(embedding float[8])")
|
||||
db.execute("CREATE VIRTUAL TABLE vec_items USING vec0(embedding float[4])")
|
||||
|
||||
items = [
|
||||
[1, [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]],
|
||||
[2, [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]]
|
||||
[1, [0.1, 0.1, 0.1, 0.1]],
|
||||
[2, [0.2, 0.2, 0.2, 0.2]],
|
||||
[3, [0.3, 0.3, 0.3, 0.3]],
|
||||
[4, [0.4, 0.4, 0.4, 0.4]],
|
||||
[5, [0.5, 0.5, 0.5, 0.5]],
|
||||
]
|
||||
|
||||
db.transaction do
|
||||
items.each do |item|
|
||||
db.execute("INSERT INTO vec_items(rowid, embedding) VALUES (?, ?)", [item[0], item[1].pack("f*")])
|
||||
end
|
||||
end
|
||||
|
||||
query = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
|
||||
query = [0.3, 0.3, 0.3, 0.3]
|
||||
rows = db.execute(<<-SQL, [query.pack("f*")])
|
||||
SELECT
|
||||
rowid,
|
||||
|
|
@ -30,7 +34,7 @@ rows = db.execute(<<-SQL, [query.pack("f*")])
|
|||
FROM vec_items
|
||||
WHERE embedding MATCH ?
|
||||
ORDER BY distance
|
||||
LIMIT 5
|
||||
LIMIT 3
|
||||
SQL
|
||||
|
||||
puts rows
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue