mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-26 09:16:22 +02:00
examples + fmt
This commit is contained in:
parent
356f75cca7
commit
dd972f6ffe
16 changed files with 1064 additions and 25 deletions
31
examples/nbc-headlines/demo.py
Normal file
31
examples/nbc-headlines/demo.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import sqlite3
|
||||
import sqlite_vec
|
||||
from sentence_transformers import SentenceTransformer
|
||||
|
||||
db = sqlite3.connect("articles.db")
|
||||
db.enable_load_extension(True)
|
||||
sqlite_vec.load(db)
|
||||
db.enable_load_extension(False)
|
||||
|
||||
model = SentenceTransformer("all-MiniLM-L6-v2")
|
||||
|
||||
|
||||
query = "sports"
|
||||
query_embedding = model.encode(query)
|
||||
|
||||
results = db.execute(
|
||||
"""
|
||||
select
|
||||
article_id,
|
||||
headline,
|
||||
distance
|
||||
from vec_articles
|
||||
left join articles on articles.id = vec_articles.article_id
|
||||
where headline_embedding match ?
|
||||
and k = 8;
|
||||
""",
|
||||
[query_embedding]
|
||||
).fetchall()
|
||||
|
||||
for (article_id, headline, distance) in results:
|
||||
print(article_id, headline, distance)
|
||||
Loading…
Add table
Add a link
Reference in a new issue