llama-index-vector-stores-postgres 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-index-vector-stores-postgres
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: llama-index vector_stores postgres integration
5
5
  License: MIT
6
6
  Author: Your Name
@@ -149,6 +149,7 @@ class PGVectorStore(BasePydanticVectorStore):
149
149
  debug: bool
150
150
  use_jsonb: bool
151
151
  create_engine_kwargs: Dict
152
+ initialization_fail_on_error: bool = False
152
153
 
153
154
  hnsw_kwargs: Optional[Dict[str, Any]]
154
155
 
@@ -175,6 +176,7 @@ class PGVectorStore(BasePydanticVectorStore):
175
176
  use_jsonb: bool = False,
176
177
  hnsw_kwargs: Optional[Dict[str, Any]] = None,
177
178
  create_engine_kwargs: Optional[Dict[str, Any]] = None,
179
+ initialization_fail_on_error: bool = False,
178
180
  ) -> None:
179
181
  """Constructor.
180
182
 
@@ -220,6 +222,7 @@ class PGVectorStore(BasePydanticVectorStore):
220
222
  use_jsonb=use_jsonb,
221
223
  hnsw_kwargs=hnsw_kwargs,
222
224
  create_engine_kwargs=create_engine_kwargs or {},
225
+ initialization_fail_on_error=initialization_fail_on_error,
223
226
  )
224
227
 
225
228
  # sqlalchemy model
@@ -341,7 +344,11 @@ class PGVectorStore(BasePydanticVectorStore):
341
344
  )
342
345
  self._async_session = sessionmaker(self._async_engine, class_=AsyncSession) # type: ignore
343
346
 
344
- def _create_schema_if_not_exists(self) -> None:
347
+ def _create_schema_if_not_exists(self) -> bool:
348
+ """
349
+ Create the schema if it does not exist.
350
+ Returns True if the schema was created, False if it already existed.
351
+ """
345
352
  if not re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", self.schema_name):
346
353
  raise ValueError(f"Invalid schema_name: {self.schema_name}")
347
354
  with self._session() as session, session.begin():
@@ -352,7 +359,8 @@ class PGVectorStore(BasePydanticVectorStore):
352
359
  result = session.execute(check_schema_statement).fetchone()
353
360
 
354
361
  # If the schema does not exist, then create it
355
- if not result:
362
+ schema_doesnt_exist = result is None
363
+ if schema_doesnt_exist:
356
364
  create_schema_statement = sqlalchemy.text(
357
365
  # DDL won't tolerate quoted string literal here for schema_name,
358
366
  # so use a format string to embed the schema_name directly, instead of a param.
@@ -361,6 +369,7 @@ class PGVectorStore(BasePydanticVectorStore):
361
369
  session.execute(create_schema_statement)
362
370
 
363
371
  session.commit()
372
+ return schema_doesnt_exist
364
373
 
365
374
  def _create_tables_if_not_exists(self) -> None:
366
375
  with self._session() as session, session.begin():
@@ -399,14 +408,35 @@ class PGVectorStore(BasePydanticVectorStore):
399
408
  session.commit()
400
409
 
401
410
  def _initialize(self) -> None:
411
+ fail_on_error = self.initialization_fail_on_error
402
412
  if not self._is_initialized:
403
413
  self._connect()
404
414
  if self.perform_setup:
405
- self._create_extension()
406
- self._create_schema_if_not_exists()
407
- self._create_tables_if_not_exists()
415
+ try:
416
+ self._create_schema_if_not_exists()
417
+ except Exception as e:
418
+ _logger.warning(f"PG Setup: Error creating schema: {e}")
419
+ if fail_on_error:
420
+ raise
421
+ try:
422
+ self._create_extension()
423
+ except Exception as e:
424
+ _logger.warning(f"PG Setup: Error creating extension: {e}")
425
+ if fail_on_error:
426
+ raise
427
+ try:
428
+ self._create_tables_if_not_exists()
429
+ except Exception as e:
430
+ _logger.warning(f"PG Setup: Error creating tables: {e}")
431
+ if fail_on_error:
432
+ raise
408
433
  if self.hnsw_kwargs is not None:
409
- self._create_hnsw_index()
434
+ try:
435
+ self._create_hnsw_index()
436
+ except Exception as e:
437
+ _logger.warning(f"PG Setup: Error creating HNSW index: {e}")
438
+ if fail_on_error:
439
+ raise
410
440
  self._is_initialized = True
411
441
 
412
442
  def _node_to_table_row(self, node: BaseNode) -> Any:
@@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
27
27
  license = "MIT"
28
28
  name = "llama-index-vector-stores-postgres"
29
29
  readme = "README.md"
30
- version = "0.3.0"
30
+ version = "0.3.2"
31
31
 
32
32
  [tool.poetry.dependencies]
33
33
  python = ">=3.9,<4.0"