Skip to content

Commit 9c0dc11

Browse files
authored
fix: preserve table options when adding sparse vector indexes
Co-authored-by: xxsc0529 <xxsc0529@users.noreply.github.com>
1 parent a87901c commit 9c0dc11

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pyobvector/client/ob_vec_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,20 @@ def create_table_with_index_params(
9797
)
9898
if sparse_vidxs is not None and len(sparse_vidxs) > 0:
9999
create_table_sql = str(CreateTable(table).compile(self.engine))
100-
new_sql = create_table_sql[: create_table_sql.rfind(")")]
100+
# Preserve table options (e.g. ORGANIZATION=heap) after the closing ")"
101+
last_paren = create_table_sql.rfind(")")
102+
table_options_suffix = create_table_sql[
103+
last_paren:
104+
] # e.g. ")ORGANIZATION=heap"
105+
new_sql = create_table_sql[:last_paren]
101106
for sparse_vidx in sparse_vidxs:
102107
sparse_params = sparse_vidx._parse_kwargs()
103108
if "type" in sparse_params:
104109
new_sql += f",\n\tVECTOR INDEX {sparse_vidx.index_name}({sparse_vidx.field_name}) with (type={sparse_params['type']}, distance=inner_product)"
105110
else:
106111
new_sql += f",\n\tVECTOR INDEX {sparse_vidx.index_name}({sparse_vidx.field_name}) with (distance=inner_product)"
107-
new_sql += "\n)"
112+
# Restore table options after the new closing ")"
113+
new_sql += "\n)" + table_options_suffix[1:]
108114
conn.execute(text(new_sql))
109115
else:
110116
table.create(self.engine, checkfirst=True)

0 commit comments

Comments
 (0)