Skip to content
Snippets Groups Projects
Commit 80f5914a authored by Marcus Schiesser's avatar Marcus Schiesser
Browse files

fix: raise exception if PG_CONNECTION_STRING is empty (generated value)

parent 1c4e7f9c
No related branches found
No related tags found
No related merge requests found
...@@ -6,18 +6,22 @@ from app.engine.constants import PGVECTOR_SCHEMA, PGVECTOR_TABLE ...@@ -6,18 +6,22 @@ from app.engine.constants import PGVECTOR_SCHEMA, PGVECTOR_TABLE
def init_pg_vector_store_from_env(): def init_pg_vector_store_from_env():
original_conn_string = os.environ.get("PG_CONNECTION_STRING") original_conn_string = os.environ.get("PG_CONNECTION_STRING")
if original_conn_string is None: if original_conn_string is None or original_conn_string == "":
raise ValueError("PG_CONNECTION_STRING environment variable is not set.") raise ValueError("PG_CONNECTION_STRING environment variable is not set.")
# The PGVectorStore requires both two connection strings, one for psycopg2 and one for asyncpg # The PGVectorStore requires both two connection strings, one for psycopg2 and one for asyncpg
# Update the configured scheme with the psycopg2 and asyncpg schemes # Update the configured scheme with the psycopg2 and asyncpg schemes
original_scheme = urlparse(original_conn_string).scheme + "://" original_scheme = urlparse(original_conn_string).scheme + "://"
conn_string = original_conn_string.replace(original_scheme, "postgresql+psycopg2://") conn_string = original_conn_string.replace(
async_conn_string = original_conn_string.replace(original_scheme, "postgresql+asyncpg://") original_scheme, "postgresql+psycopg2://"
)
async_conn_string = original_conn_string.replace(
original_scheme, "postgresql+asyncpg://"
)
return PGVectorStore( return PGVectorStore(
connection_string=conn_string, connection_string=conn_string,
async_connection_string=async_conn_string, async_connection_string=async_conn_string,
schema_name=PGVECTOR_SCHEMA, schema_name=PGVECTOR_SCHEMA,
table_name=PGVECTOR_TABLE table_name=PGVECTOR_TABLE,
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment