mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 00:36:56 +02:00
examples + fmt
This commit is contained in:
parent
356f75cca7
commit
dd972f6ffe
16 changed files with 1064 additions and 25 deletions
34
examples/nbc-headlines/demo.mjs
Normal file
34
examples/nbc-headlines/demo.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import Database from "better-sqlite3";
|
||||
import * as sqliteVec from "sqlite-vec";
|
||||
import { pipeline } from "@xenova/transformers";
|
||||
|
||||
const db = new Database("articles.db");
|
||||
sqliteVec.load(db);
|
||||
|
||||
const extractor = await pipeline(
|
||||
"feature-extraction",
|
||||
"Xenova/all-MiniLM-L6-v2"
|
||||
);
|
||||
|
||||
const query = "sports";
|
||||
const queryEmbedding = await extractor([query], {
|
||||
pooling: "mean",
|
||||
normalize: true,
|
||||
});
|
||||
|
||||
const rows = db
|
||||
.prepare(
|
||||
`
|
||||
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;
|
||||
`
|
||||
)
|
||||
.all(queryEmbedding.data);
|
||||
|
||||
console.log(rows);
|
||||
Loading…
Add table
Add a link
Reference in a new issue