@@ -65,7 +65,7 @@ pub fn init_embedding_table_query(
6565 transformer : & types:: Transformer ,
6666 search_alg : & types:: SimilarityAlg ,
6767 transform_method : & TableMethod ,
68- ) -> String {
68+ ) -> Vec < String > {
6969 // TODO: when adding support for other models, add the output dimension to the transformer attributes
7070 // so that they can be read here, not hard-coded here below
7171 // currently only supports the text-embedding-ada-002 embedding model - output dim 1536
@@ -80,8 +80,15 @@ pub fn init_embedding_table_query(
8080 ( types:: Transformer :: openai, types:: SimilarityAlg :: pgv_cosine_similarity) => "vector(1536)" ,
8181 } ;
8282 match transform_method {
83- TableMethod :: append => append_embedding_column ( job_name, schema, table, col_type) ,
84- TableMethod :: join => create_embedding_table ( job_name, col_type) ,
83+ TableMethod :: append => {
84+ vec ! [
85+ append_embedding_column( job_name, schema, table, col_type) ,
86+ create_hnsw_cosine_index( job_name, schema, table) ,
87+ ]
88+ }
89+ TableMethod :: join => {
90+ vec ! [ create_embedding_table( job_name, col_type) ]
91+ }
8592 }
8693}
8794
@@ -97,6 +104,13 @@ fn create_embedding_table(job_name: &str, col_type: &str) -> String {
97104 )
98105}
99106
107+ fn create_hnsw_cosine_index ( job_name : & str , schema : & str , table : & str ) -> String {
108+ format ! (
109+ "CREATE INDEX IF NOT EXISTS {job_name}_idx ON {schema}.{table} USING hnsw ({job_name}_embeddings vector_cosine_ops);
110+ " ,
111+ )
112+ }
113+
100114fn append_embedding_column ( job_name : & str , schema : & str , table : & str , col_type : & str ) -> String {
101115 // TODO: when adding support for other models, add the output dimension to the transformer attributes
102116 // so that they can be read here, not hard-coded here below
0 commit comments