Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tables for pgvector regardless of schema status #17100

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class PGVectorStore(BasePydanticVectorStore):
debug: bool
use_jsonb: bool
create_engine_kwargs: Dict
initialization_fail_on_error: bool = False

hnsw_kwargs: Optional[Dict[str, Any]]

Expand All @@ -175,6 +176,7 @@ def __init__(
use_jsonb: bool = False,
hnsw_kwargs: Optional[Dict[str, Any]] = None,
create_engine_kwargs: Optional[Dict[str, Any]] = None,
initialization_fail_on_error: bool = False,
) -> None:
"""Constructor.

Expand Down Expand Up @@ -220,6 +222,7 @@ def __init__(
use_jsonb=use_jsonb,
hnsw_kwargs=hnsw_kwargs,
create_engine_kwargs=create_engine_kwargs or {},
initialization_fail_on_error=initialization_fail_on_error,
)

# sqlalchemy model
Expand Down Expand Up @@ -405,17 +408,35 @@ def _create_hnsw_index(self) -> None:
session.commit()

def _initialize(self) -> None:
fail_on_error = self.initialization_fail_on_error
if not self._is_initialized:
self._connect()
if self.perform_setup:
schema_created = self._create_schema_if_not_exists()
if not schema_created:
self._is_initialized = True
return # Skip table creation if schema already existed
self._create_extension()
self._create_tables_if_not_exists()
try:
self._create_schema_if_not_exists()
except Exception as e:
_logger.warning(f"PG Setup: Error creating schema: {e}")
if fail_on_error:
raise
try:
self._create_extension()
except Exception as e:
_logger.warning(f"PG Setup: Error creating extension: {e}")
if fail_on_error:
raise
try:
self._create_tables_if_not_exists()
except Exception as e:
_logger.warning(f"PG Setup: Error creating tables: {e}")
if fail_on_error:
raise
if self.hnsw_kwargs is not None:
self._create_hnsw_index()
try:
self._create_hnsw_index()
except Exception as e:
_logger.warning(f"PG Setup: Error creating HNSW index: {e}")
if fail_on_error:
raise
self._is_initialized = True

def _node_to_table_row(self, node: BaseNode) -> Any:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-vector-stores-postgres"
readme = "README.md"
version = "0.3.1"
version = "0.3.2"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down
Loading