fix(pgvector): replace hyphens with underscores in table names (#1385)

# What does this PR do?
Fix SQL syntax errors caused by hyphens in Vector DB IDs by sanitizing
table

# (Closes #1332 )

## Test Plan
Test confirms table names with hyphens are properly converted to
underscores
This commit is contained in:
Alexey Rybak 2025-03-04 07:06:35 -08:00 committed by GitHub
parent 468edfd92c
commit d57cffb495
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,7 +58,11 @@ class PGVectorIndex(EmbeddingIndex):
def __init__(self, vector_db: VectorDB, dimension: int, conn): def __init__(self, vector_db: VectorDB, dimension: int, conn):
self.conn = conn self.conn = conn
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur: with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
self.table_name = f"vector_store_{vector_db.identifier}" # Sanitize the table name by replacing hyphens with underscores
# SQL doesn't allow hyphens in table names, and vector_db.identifier may contain hyphens
# when created with patterns like "test-vector-db-{uuid4()}"
sanitized_identifier = vector_db.identifier.replace("-", "_")
self.table_name = f"vector_store_{sanitized_identifier}"
cur.execute( cur.execute(
f""" f"""