-
-
Notifications
You must be signed in to change notification settings - Fork 238
Additional support for vector indexes. #2721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fd98328
Move vector distance functions into their own package and implement F…
nicktobey 2871918
Add IsVector method to sql.Index
nicktobey 3a9c4ab
Allow creating and validating vector indexes on columns with JSON type.
nicktobey 7009dea
Implement SHOW CREATE for tables with vector indexes.
nicktobey 5ec3634
Add integration tests for vector indexes.
nicktobey 0463328
Propage vector properties into in-memory vector indexes.
nicktobey 56b6778
Add vector functions to builtin functions.
nicktobey 2b86254
Allow converting strings to vectors, so they can be passed into VEC_D…
nicktobey c7387c3
Allow adding and altering vector indexes in GMS.
nicktobey dbacc9b
[ga-format-pr] Run ./format_repo.sh to fix formatting
nicktobey 6e94253
Remove unused Column field from vectorPartitionIter
nicktobey 3b2cf89
Add Literal field to the `OrderAndLimit` struct used for tracking exp…
nicktobey c10da38
Amend vector index queries
nicktobey 4dea0bb
Amend replace_order_by_distance.go
nicktobey be72c6e
Only optimize ORDER BY to use vector indexes if there's also a limit.
nicktobey 2c88f05
Update vector index tests.
nicktobey b0899a9
Avoid using Vector indexes for lookups.
nicktobey 07b686d
Update sql/sqlfmt.go
nicktobey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,58 @@ | ||
| // Copyright 2024 Dolthub, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package queries | ||
|
|
||
| import ( | ||
| "github.com/dolthub/go-mysql-server/sql" | ||
| "github.com/dolthub/go-mysql-server/sql/types" | ||
| ) | ||
|
|
||
| var VectorFunctionQueries = []ScriptTest{ | ||
| { | ||
| Name: "basic usage of VEC_DISTANCE without index", | ||
| SetUpScript: []string{ | ||
| "create table vectors (id int primary key, v json);", | ||
| `insert into vectors values (1, '[3.0,4.0]'), (2, '[0.0,0.0]'), (3, '[1.0,-1.0]'), (4, '[-2.0,0.0]');`, | ||
| }, | ||
| Assertions: []ScriptTestAssertion{ | ||
| { | ||
| Query: "select VEC_DISTANCE('[10.0]', '[20.0]');", | ||
| Expected: []sql.Row{{100.0}}, | ||
| }, | ||
| { | ||
| Query: "select VEC_DISTANCE_L2_SQUARED('[1.0, 2.0]', '[5.0, 5.0]');", | ||
| Expected: []sql.Row{{25.0}}, | ||
| }, | ||
| { | ||
| Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v)", | ||
| Expected: []sql.Row{ | ||
| {2, types.MustJSON(`[0.0, 0.0]`)}, | ||
| {3, types.MustJSON(`[1.0, -1.0]`)}, | ||
| {4, types.MustJSON(`[-2.0, 0.0]`)}, | ||
| {1, types.MustJSON(`[3.0, 4.0]`)}, | ||
| }, | ||
| }, | ||
| { | ||
| Query: "select * from vectors order by VEC_DISTANCE_L2_SQUARED('[-2.0,0.0]', v)", | ||
| Expected: []sql.Row{ | ||
| {4, types.MustJSON(`[-2.0, 0.0]`)}, | ||
| {2, types.MustJSON(`[0.0, 0.0]`)}, | ||
| {3, types.MustJSON(`[1.0, -1.0]`)}, | ||
| {1, types.MustJSON(`[3.0, 4.0]`)}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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,81 @@ | ||
| // Copyright 2024 Dolthub, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package queries | ||
|
|
||
| import ( | ||
| "github.com/dolthub/go-mysql-server/sql" | ||
| "github.com/dolthub/go-mysql-server/sql/types" | ||
| ) | ||
|
|
||
| var VectorIndexQueries = []ScriptTest{ | ||
| { | ||
| Name: "basic vector index", | ||
| SetUpScript: []string{ | ||
| "create table vectors (id int primary key, v json);", | ||
| `insert into vectors values (1, '[4.0,3.0]'), (2, '[0.0,0.0]'), (3, '[-1.0,1.0]'), (4, '[0.0,-2.0]');`, | ||
| `create vector index v_idx on vectors(v);`, | ||
| }, | ||
| Assertions: []ScriptTestAssertion{ | ||
| { | ||
| Query: "show create table vectors", | ||
| Expected: []sql.Row{ | ||
| {"vectors", "CREATE TABLE `vectors` (\n `id` int NOT NULL,\n `v` json,\n PRIMARY KEY (`id`),\n VECTOR KEY `v_idx` (`v`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}, | ||
| }, | ||
| }, | ||
| { | ||
| Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v) limit 4", | ||
| Expected: []sql.Row{ | ||
| {2, types.MustJSON(`[0.0, 0.0]`)}, | ||
| {3, types.MustJSON(`[-1.0, 1.0]`)}, | ||
| {4, types.MustJSON(`[0.0, -2.0]`)}, | ||
| {1, types.MustJSON(`[4.0, 3.0]`)}, | ||
| }, | ||
| ExpectedIndexes: []string{"v_idx"}, | ||
| }, | ||
| { | ||
| // Only queries with a limit can use a vector index. | ||
| Query: "select * from vectors order by VEC_DISTANCE('[0.0,0.0]', v)", | ||
| Expected: []sql.Row{ | ||
| {2, types.MustJSON(`[0.0, 0.0]`)}, | ||
| {3, types.MustJSON(`[-1.0, 1.0]`)}, | ||
| {4, types.MustJSON(`[0.0, -2.0]`)}, | ||
| {1, types.MustJSON(`[4.0, 3.0]`)}, | ||
| }, | ||
| ExpectedIndexes: nil, | ||
| }, | ||
| { | ||
| Query: "select * from vectors order by VEC_DISTANCE_L2_SQUARED('[0.0,-2.0]', v) limit 4", | ||
| Expected: []sql.Row{ | ||
| {4, types.MustJSON(`[0.0, -2.0]`)}, | ||
| {2, types.MustJSON(`[0.0, 0.0]`)}, | ||
| {3, types.MustJSON(`[-1.0, 1.0]`)}, | ||
| {1, types.MustJSON(`[4.0, 3.0]`)}, | ||
| }, | ||
| ExpectedIndexes: []string{"v_idx"}, | ||
| }, | ||
| { | ||
| // Ensure vector index is not used for range lookups. | ||
| Query: "select * from vectors order by v limit 4", | ||
| Expected: []sql.Row{ | ||
| {3, types.MustJSON(`[-1.0, 1.0]`)}, | ||
| {4, types.MustJSON(`[0.0, -2.0]`)}, | ||
| {2, types.MustJSON(`[0.0, 0.0]`)}, | ||
| {1, types.MustJSON(`[4.0, 3.0]`)}, | ||
| }, | ||
| ExpectedIndexes: []string{}, | ||
| }, | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.