Skip to content

Commit

Permalink
Make index name unconfigurable
Browse files Browse the repository at this point in the history
  • Loading branch information
gkourie committed Jan 10, 2025
1 parent 99ad2f3 commit bdc02fd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
19 changes: 1 addition & 18 deletions app/Http/Controllers/Api/ImageAnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,6 @@ protected function performVectorSearch($featureVector, $trees, $topNLabels)
*/
protected function performAnnSearch($featureVector, $trees)
{
// check if the HNSW index exists
if (!$this->indexExists(config('labelbot.HNSW_ImgAnno_index_name'))) {
return [];
}
// Size of the dynamic candidate list during the search process.
// K is always bounded by this value so we set it to K.
$k = config('labelbot.K');
Expand Down Expand Up @@ -498,25 +494,12 @@ protected function performKnnSearch($featureVector, $trees)
return $topNLabels;
}

/**
* Check if the index exists.
*
* @param string $indexName The index name.
*
* @return boolean
*/
protected function indexExists($indexName)
{
return !empty(DB::select("SELECT indexname FROM pg_indexes WHERE indexname = '$indexName'"));
}

/**
* Drop the HNSW index if exists. This step is necessary to perform exact KNN search
* because the planner almost always prioritize the HNSW index to perform vector search.
*/
protected function dropHNSWIndex()
{
$indexName = config('labelbot.HNSW_ImgAnno_index_name');
DB::statement("DROP INDEX IF EXISTS $indexName");
DB::statement("DROP INDEX IF EXISTS image_annotation_label_feature_vectors_vector_idx");
}
}
23 changes: 0 additions & 23 deletions config/labelbot.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,4 @@
| and returned.
*/
'N' => 3,

/*
|--------------------------------------------------------------------------
| HNSW Index name (Image Annotation)
|--------------------------------------------------------------------------
|
| This is the name used when creating, dropping or checking the HNSW index.
| The HNSW index is built on the vector column in the
| image_annotation_label_feature_vectors table.
*/
'HNSW_ImgAnno_index_name' => 'image_annotation_label_feature_vectors_vector_idx',

/*
|--------------------------------------------------------------------------
| B-Tree Index name (Image Annotation)
|--------------------------------------------------------------------------
|
| This is the name used when creating, dropping or checking the B-Tree index.
| The B-Tree index is built on the label_tree_id column in the
| image_annotation_label_feature_vectors table.
*/
'B_Tree_ImgAnno_index_name' => 'image_annotation_label_feature_vectors_label_tree_id_index',

];

0 comments on commit bdc02fd

Please sign in to comment.