This repository was archived by the owner on Oct 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 470
vector extension optional params + features #5955
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3e16709
(wip) skip_if_exists optional parameter for CREATE_VECTOR_INDEX
carminite 116fbab
Implemented skip_if_exists optional param for CREATE_VECTOR_INDEX
carminite 6ff9087
ci: auto code format
carminite 31708d0
Catch by reference, throw by value
carminite c755952
remove test_list in root dir
carminite b262c50
Implement skip_if_not_exists for DROP_VECTOR_INDEX
carminite 8b05d3b
ci: auto code format
carminite 9ffda8f
Remove redundant cast to string
carminite 750d3e7
Removed try catch and slightly modified hsnw_index_utils
carminite 1ba2062
ci: auto code format
carminite 567cd37
Removed redundant indexExist check, implemented DropAllVectorIndexes(…
carminite fffb318
ci: auto code format
carminite c90c925
removed DropAllVectorIndexes, changed skipIf(Not)Exists to ConflictAc…
carminite 93eec34
Merge branch 'master' into origin/vector-index-optional-params
carminite 456ea05
ci: auto code format
carminite 395ac62
Implemented changes suggested by @acquamarin
carminite 23f903b
ci: auto code format
carminite 410f0d5
Made comments for placeholder nullptr, removed inline for indexExists
carminite 109f99a
ci: auto code format
carminite aa33657
forgot to remove inline in hnsw_index_utils.cpp
carminite 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| #include "catalog/catalog_entry/function_catalog_entry.h" | ||||||
| #include "catalog/catalog_entry/node_table_catalog_entry.h" | ||||||
| #include "catalog/hnsw_index_catalog_entry.h" | ||||||
| #include "common/exception/binder.h" | ||||||
| #include "function/built_in_function_utils.h" | ||||||
| #include "function/hnsw_index_functions.h" | ||||||
| #include "function/table/bind_data.h" | ||||||
|
|
@@ -44,17 +45,22 @@ static std::unique_ptr<TableFuncBindData> createInMemHNSWBindFunc(main::ClientCo | |||||
| const auto tableName = input->getLiteralVal<std::string>(0); | ||||||
| const auto indexName = input->getLiteralVal<std::string>(1); | ||||||
| const auto columnName = input->getLiteralVal<std::string>(2); | ||||||
| auto tableEntry = HNSWIndexUtils::bindNodeTable(*context, tableName, indexName, | ||||||
| HNSWIndexUtils::IndexOperation::CREATE); | ||||||
| const auto tableID = tableEntry->getTableID(); | ||||||
| HNSWIndexUtils::validateColumnType(*tableEntry, columnName); | ||||||
| auto config = HNSWIndexConfig{input->optionalParams}; | ||||||
| const auto nodeTableEntry = HNSWIndexUtils::bindNodeTable(*context, tableName); | ||||||
| if (HNSWIndexUtils::validateIndexExistence(*context, nodeTableEntry, indexName, | ||||||
| HNSWIndexUtils::IndexOperation::CREATE, config.conflictAction)) { | ||||||
| return std::make_unique<CreateHNSWIndexBindData>(context, indexName, nullptr, 0, 0, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We inline comments as follows:
Suggested change
|
||||||
| std::move(config), | ||||||
| true); // Placeholders for nodeTableEntry, propertyID, numNodes - WILL NOT BE ACCESSED | ||||||
| } | ||||||
| const auto tableID = nodeTableEntry->getTableID(); | ||||||
| HNSWIndexUtils::validateColumnType(*nodeTableEntry, columnName); | ||||||
| const auto& table = | ||||||
| storage::StorageManager::Get(*context)->getTable(tableID)->cast<storage::NodeTable>(); | ||||||
| auto propertyID = tableEntry->getPropertyID(columnName); | ||||||
| auto config = HNSWIndexConfig{input->optionalParams}; | ||||||
| auto propertyID = nodeTableEntry->getPropertyID(columnName); | ||||||
| auto transaction = transaction::Transaction::Get(*context); | ||||||
| auto numNodes = table.getStats(transaction).getTableCard(); | ||||||
| return std::make_unique<CreateHNSWIndexBindData>(context, indexName, tableEntry, propertyID, | ||||||
| return std::make_unique<CreateHNSWIndexBindData>(context, indexName, nodeTableEntry, propertyID, | ||||||
| numNodes, std::move(config)); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -327,6 +333,9 @@ static std::string rewriteCreateHNSWQuery(main::ClientContext& context, | |||||
| const TableFuncBindData& bindData) { | ||||||
| context.setUseInternalCatalogEntry(true /* useInternalCatalogEntry */); | ||||||
| const auto hnswBindData = bindData.constPtrCast<CreateHNSWIndexBindData>(); | ||||||
| if (hnswBindData->skipAfterBind) { | ||||||
| return ""; | ||||||
| } | ||||||
| std::string query = "BEGIN TRANSACTION;"; | ||||||
| auto indexName = hnswBindData->indexName; | ||||||
| auto tableName = hnswBindData->tableEntry->getName(); | ||||||
|
|
||||||
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #include "catalog/catalog.h" | ||
| #include "catalog/catalog_entry/node_table_catalog_entry.h" | ||
| #include "common/exception/binder.h" | ||
| #include "function/hnsw_index_functions.h" | ||
| #include "function/table/bind_data.h" | ||
| #include "index/hnsw_index_utils.h" | ||
|
|
@@ -16,22 +17,29 @@ namespace vector_extension { | |
| struct DropHNSWIndexBindData final : TableFuncBindData { | ||
| catalog::NodeTableCatalogEntry* tableEntry; | ||
| std::string indexName; | ||
| bool skipAfterBind; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to something along the line of |
||
|
|
||
| DropHNSWIndexBindData(catalog::NodeTableCatalogEntry* tableEntry, std::string indexName) | ||
| : TableFuncBindData{0}, tableEntry{tableEntry}, indexName{std::move(indexName)} {} | ||
| DropHNSWIndexBindData(catalog::NodeTableCatalogEntry* tableEntry, std::string indexName, | ||
| bool skipAfterBind = false) | ||
| : TableFuncBindData{0}, tableEntry{tableEntry}, indexName{std::move(indexName)}, | ||
| skipAfterBind{skipAfterBind} {} | ||
|
|
||
| std::unique_ptr<TableFuncBindData> copy() const override { | ||
| return std::make_unique<DropHNSWIndexBindData>(tableEntry, indexName); | ||
| return std::make_unique<DropHNSWIndexBindData>(tableEntry, indexName, skipAfterBind); | ||
| } | ||
| }; | ||
|
|
||
| static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context, | ||
| const TableFuncBindInput* input) { | ||
| const auto tableName = input->getLiteralVal<std::string>(0); | ||
| const auto indexName = input->getLiteralVal<std::string>(1); | ||
| const auto tableEntry = HNSWIndexUtils::bindNodeTable(*context, tableName, indexName, | ||
| HNSWIndexUtils::IndexOperation::DROP); | ||
| return std::make_unique<DropHNSWIndexBindData>(tableEntry, indexName); | ||
| auto config = DropHNSWConfig{input->optionalParams}; | ||
| const auto nodeTableEntry = HNSWIndexUtils::bindNodeTable(*context, tableName); | ||
| if (!HNSWIndexUtils::validateIndexExistence(*context, nodeTableEntry, indexName, | ||
| HNSWIndexUtils::IndexOperation::DROP, config.conflictAction)) { | ||
| return std::make_unique<DropHNSWIndexBindData>(nullptr, indexName, true); | ||
| } | ||
| return std::make_unique<DropHNSWIndexBindData>(nodeTableEntry, indexName); | ||
| } | ||
|
|
||
| static common::offset_t internalTableFunc(const TableFuncInput& input, TableFuncOutput&) { | ||
|
|
@@ -49,6 +57,9 @@ static std::string dropHNSWIndexTables(main::ClientContext& context, | |
| const TableFuncBindData& bindData) { | ||
| const auto dropHNSWIndexBindData = bindData.constPtrCast<DropHNSWIndexBindData>(); | ||
| context.setUseInternalCatalogEntry(true /* useInternalCatalogEntry */); | ||
| if (dropHNSWIndexBindData->skipAfterBind) { | ||
| return ""; | ||
| } | ||
| std::string query = ""; | ||
| const auto requireNewTransaction = !context.getTransactionContext()->hasActiveTransaction(); | ||
| if (requireNewTransaction) { | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -17,16 +17,18 @@ struct CreateHNSWIndexBindData final : function::TableFuncBindData { | |
| catalog::TableCatalogEntry* tableEntry; | ||
| common::property_id_t propertyID; | ||
| HNSWIndexConfig config; | ||
| bool skipAfterBind; | ||
|
acquamarin marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rename this to |
||
|
|
||
| CreateHNSWIndexBindData(main::ClientContext* context, std::string indexName, | ||
| catalog::TableCatalogEntry* tableEntry, common::property_id_t propertyID, | ||
| common::offset_t numNodes, HNSWIndexConfig config) | ||
| common::offset_t numNodes, HNSWIndexConfig config, bool skipAfterBind = false) | ||
| : TableFuncBindData{numNodes}, context{context}, indexName{std::move(indexName)}, | ||
| tableEntry{tableEntry}, propertyID{propertyID}, config{std::move(config)} {} | ||
| tableEntry{tableEntry}, propertyID{propertyID}, config{std::move(config)}, | ||
| skipAfterBind{skipAfterBind} {} | ||
|
|
||
| std::unique_ptr<TableFuncBindData> copy() const override { | ||
| return std::make_unique<CreateHNSWIndexBindData>(context, indexName, tableEntry, propertyID, | ||
| numRows, config.copy()); | ||
| numRows, config.copy(), skipAfterBind); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| -DATASET CSV empty | ||
|
|
||
| -- | ||
|
|
||
| -CASE CreateSkipIfExists | ||
| -LOAD_DYNAMIC_EXTENSION vector | ||
| -STATEMENT CREATE NODE TABLE embeddings (id int64, vec FLOAT[8], PRIMARY KEY (id)); | ||
| ---- ok | ||
| -STATEMENT CALL CREATE_VECTOR_INDEX('embeddings', 'e_hnsw_index', 'vec'); | ||
| ---- ok | ||
| -STATEMENT CALL CREATE_VECTOR_INDEX('embeddings', 'e_hnsw_index', 'vec'); | ||
| ---- error | ||
| Binder exception: Index e_hnsw_index already exists in table embeddings. | ||
| -STATEMENT CALL CREATE_VECTOR_INDEX('embeddings', 'e_hnsw_index', 'vec', skip_if_exists := true); | ||
| ---- ok | ||
| -STATEMENT CALL SHOW_INDEXES() RETURN * | ||
| ---- 1 | ||
| embeddings|e_hnsw_index|HNSW|[vec]|True|CALL CREATE_VECTOR_INDEX('embeddings', 'e_hnsw_index', 'vec', mu := 30, ml := 60, pu := 0.050000, metric := 'cosine', alpha := 1.100000, efc := 200); | ||
|
|
||
| -CASE DropSkipIfNotExists | ||
| -LOAD_DYNAMIC_EXTENSION vector | ||
| -STATEMENT CREATE NODE TABLE embeddings (id int64, vec FLOAT[8], PRIMARY KEY (id)); | ||
| ---- ok | ||
| -STATEMENT CALL DROP_VECTOR_INDEX('embeddings', 'e_hnsw_index'); | ||
| ---- error | ||
| Binder exception: Table embeddings doesn't have an index with name e_hnsw_index. | ||
| -STATEMENT CALL DROP_VECTOR_INDEX('embeddings', 'e_hnsw_index', skip_if_not_exists := true); | ||
| ---- ok |
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.