-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from tursodatabase/upgrade-to-0.4.4
upgrade libsql-js: 0.4.1 -> 0.4.4
- Loading branch information
Showing
6 changed files
with
100 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createClient } from "@libsql/client"; | ||
import reader from "readline-sync"; | ||
|
||
async function example() { | ||
const config = { | ||
url: process.env.URL ?? "file:local.db", | ||
syncUrl: process.env.SYNC_URL, | ||
authToken: process.env.AUTH_TOKEN, | ||
}; | ||
const db = createClient(config); | ||
await db.sync(); | ||
await db.execute( | ||
"CREATE TABLE IF NOT EXISTS movies (title TEXT, embedding FLOAT32(4))", | ||
); | ||
await db.execute( | ||
"CREATE INDEX IF NOT EXISTS movies_idx ON movies (libsql_vector_idx(embedding))", | ||
); | ||
await db.sync(); | ||
|
||
const title = reader.question("Add movie (title): "); | ||
const embedding = reader.question( | ||
"Add movie (embedding, e.g. [1,2,3,4]): ", | ||
); | ||
|
||
await db.execute({ | ||
sql: "INSERT INTO movies (title, embedding) VALUES (?, vector32(?))", | ||
args: [title, embedding], | ||
}); | ||
|
||
await db.sync(); | ||
|
||
const all = await db.execute( | ||
"SELECT title, vector_extract(embedding) as embedding FROM movies", | ||
); | ||
console.info("all movies:"); | ||
for (const row of all.rows) { | ||
console.log(" - " + row.title + ": " + row.embedding); | ||
} | ||
|
||
const query = reader.question("KNN query (e.g. [1,2,3,4]): "); | ||
const nn = await db.execute({ | ||
sql: "SELECT title, vector_extract(embedding) as embedding FROM vector_top_k('movies_idx', vector32(?), 2) as knn JOIN movies ON knn.id = movies.rowid", | ||
args: [query], | ||
}); | ||
console.info("nearest neighbors:"); | ||
for (const row of nn.rows) { | ||
console.log(" - " + row.title + ": " + row.embedding); | ||
} | ||
} | ||
|
||
example(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@libsql/core", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"keywords": [ | ||
"libsql", | ||
"database", | ||
|