-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve handling vector data and tooltip
- Loading branch information
Showing
11 changed files
with
132 additions
and
13 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
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
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
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,7 @@ | ||
libsql_vector_idx(X) | ||
|
||
Use the **libsql_vector_idx** expression in the CREATE INDEX statement to create an ANN index. | ||
|
||
``` | ||
CREATE INDEX movies_idx ON movies (libsql_vector_idx(embedding)); | ||
``` |
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,7 @@ | ||
vector(X) | ||
|
||
Function to convert a vector from string format to binary. | ||
|
||
``` | ||
INSERT INTO movies (title, year, embedding) VALUES('Napoleon', 2023, vector('[1,2,3]')); | ||
``` |
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,10 @@ | ||
vector_distance_cos(X, Y) | ||
|
||
Function to calculate cosine distance between two vectors. | ||
It computes the distance as 1 minus the cosine similarity, | ||
meaning a smaller distance indicates closer vectors. | ||
|
||
``` | ||
SELECT * FROM movie | ||
ORDER BY vector_distance_cos(embedding, '[3,1,2]') | ||
``` |
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,10 @@ | ||
vector_extract(X) | ||
|
||
Function to extract string from binary vector | ||
|
||
``` | ||
SELECT title, | ||
vector_extract(embedding), | ||
vector_distance_cos(embedding, vector('[5,6,7]')) | ||
FROM movies; | ||
``` |
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,9 @@ | ||
vector_top_k(idx_name, q_vector, k) | ||
|
||
Use **vector_top_k** with the **idx_name** index to efficiently find the top k most similar vectors to **q_vector** | ||
|
||
``` | ||
SELECT title, year | ||
FROM vector_top_k('movies_idx', vector('[4,5,6]'), 3) | ||
JOIN movies ON movies.rowid = id | ||
``` |
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