Skip to content

Commit

Permalink
Adding a feature called create_extension in init method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qunfei Wu committed Nov 22, 2024
1 parent e2c04ed commit 1f818b7
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(
hnsw_index_name: str = "haystack_hnsw_index",
hnsw_ef_search: Optional[int] = None,
keyword_index_name: str = "haystack_keyword_index",
create_extension: bool = True,
):
"""
Creates a new PgvectorDocumentStore instance.
Expand Down Expand Up @@ -153,6 +154,7 @@ def __init__(
self.hnsw_ef_search = hnsw_ef_search
self.keyword_index_name = keyword_index_name
self.language = language
self.create_extension = create_extension
self._connection = None
self._cursor = None
self._dict_cursor = None
Expand Down Expand Up @@ -182,6 +184,8 @@ def _create_connection(self):
conn_str = self.connection_string.resolve_value() or ""
connection = connect(conn_str)
connection.autocommit = True
if self.create_extension:
connection.execute("CREATE EXTENSION IF NOT EXISTS vector")
register_vector(connection) # Note: this must be called before creating the cursors.

self._connection = connection
Expand Down

0 comments on commit 1f818b7

Please sign in to comment.