pgvector-haystack 2.0.0__py3-none-any.whl → 3.0.1__py3-none-any.whl

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,10 +1,9 @@
1
1
  # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
- import logging
5
4
  from typing import Any, Dict, List, Literal, Optional
6
5
 
7
- from haystack import default_from_dict, default_to_dict
6
+ from haystack import default_from_dict, default_to_dict, logging
8
7
  from haystack.dataclasses.document import ByteStream, Document
9
8
  from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError
10
9
  from haystack.document_stores.types import DuplicatePolicy
@@ -24,7 +23,7 @@ from .filters import _convert_filters_to_where_clause_and_params
24
23
  logger = logging.getLogger(__name__)
25
24
 
26
25
  CREATE_TABLE_STATEMENT = """
27
- CREATE TABLE IF NOT EXISTS {schema_name}.{table_name} (
26
+ CREATE TABLE {schema_name}.{table_name} (
28
27
  id VARCHAR(128) PRIMARY KEY,
29
28
  embedding VECTOR({embedding_dimension}),
30
29
  content TEXT,
@@ -193,7 +192,7 @@ class PgvectorDocumentStore:
193
192
  try:
194
193
  self._connection.close()
195
194
  except Error as e:
196
- logger.debug("Failed to close connection: %s", str(e))
195
+ logger.debug("Failed to close connection: {e}", e=str(e))
197
196
 
198
197
  conn_str = self.connection_string.resolve_value() or ""
199
198
  connection = connect(conn_str)
@@ -295,7 +294,7 @@ class PgvectorDocumentStore:
295
294
  cursor = cursor or self.cursor
296
295
 
297
296
  sql_query_str = sql_query.as_string(cursor) if not isinstance(sql_query, str) else sql_query
298
- logger.debug("SQL query: %s\nParameters: %s", sql_query_str, params)
297
+ logger.debug("SQL query: {query}\nParameters: {parameters}", query=sql_query_str, parameters=params)
299
298
 
300
299
  try:
301
300
  result = cursor.execute(sql_query, params)
@@ -311,13 +310,22 @@ class PgvectorDocumentStore:
311
310
  Creates the table to store Haystack documents if it doesn't exist yet.
312
311
  """
313
312
 
314
- create_sql = SQL(CREATE_TABLE_STATEMENT).format(
315
- schema_name=Identifier(self.schema_name),
316
- table_name=Identifier(self.table_name),
317
- embedding_dimension=SQLLiteral(self.embedding_dimension),
313
+ table_exists = bool(
314
+ self._execute_sql(
315
+ "SELECT 1 FROM pg_tables WHERE schemaname = %s AND tablename = %s",
316
+ (self.schema_name, self.table_name),
317
+ "Could not check if table exists",
318
+ ).fetchone()
318
319
  )
319
320
 
320
- self._execute_sql(create_sql, error_msg="Could not create table in PgvectorDocumentStore")
321
+ if not table_exists:
322
+ create_sql = SQL(CREATE_TABLE_STATEMENT).format(
323
+ schema_name=Identifier(self.schema_name),
324
+ table_name=Identifier(self.table_name),
325
+ embedding_dimension=SQLLiteral(self.embedding_dimension),
326
+ )
327
+
328
+ self._execute_sql(create_sql, error_msg="Could not create table in PgvectorDocumentStore")
321
329
 
322
330
  def delete_table(self):
323
331
  """
@@ -512,7 +520,7 @@ class PgvectorDocumentStore:
512
520
  sql_insert += SQL(" RETURNING id")
513
521
 
514
522
  sql_query_str = sql_insert.as_string(self.cursor) if not isinstance(sql_insert, str) else sql_insert
515
- logger.debug("SQL query: %s\nParameters: %s", sql_query_str, db_documents)
523
+ logger.debug("SQL query: {query}\nParameters: {parameters}", query=sql_query_str, parameters=db_documents)
516
524
 
517
525
  try:
518
526
  self.cursor.executemany(sql_insert, db_documents, returning=True)
@@ -555,24 +563,14 @@ class PgvectorDocumentStore:
555
563
  db_document["blob_mime_type"] = blob.mime_type if blob and blob.mime_type else None
556
564
  db_document["meta"] = Jsonb(db_document["meta"])
557
565
 
558
- if "dataframe" in db_document:
559
- dataframe = db_document.pop("dataframe", None)
560
- if dataframe:
561
- logger.warning(
562
- "Document %s has the `dataframe` field set. "
563
- "PgvectorDocumentStore no longer supports dataframes and this field will be ignored. "
564
- "The `dataframe` field will soon be removed from Haystack Document.",
565
- db_document["id"],
566
- )
567
-
568
566
  if "sparse_embedding" in db_document:
569
567
  sparse_embedding = db_document.pop("sparse_embedding", None)
570
568
  if sparse_embedding:
571
569
  logger.warning(
572
- "Document %s has the `sparse_embedding` field set,"
570
+ "Document {doc_id} has the `sparse_embedding` field set,"
573
571
  "but storing sparse embeddings in Pgvector is not currently supported."
574
572
  "The `sparse_embedding` field will be ignored.",
575
- db_document["id"],
573
+ doc_id=db_document["id"],
576
574
  )
577
575
 
578
576
  db_documents.append(db_document)
@@ -591,20 +589,11 @@ class PgvectorDocumentStore:
591
589
  blob_data = haystack_dict.pop("blob_data")
592
590
  blob_meta = haystack_dict.pop("blob_meta")
593
591
  blob_mime_type = haystack_dict.pop("blob_mime_type")
594
- dataframe = haystack_dict.pop("dataframe", None)
595
592
 
596
593
  # convert the embedding to a list of floats
597
594
  if document.get("embedding") is not None:
598
595
  haystack_dict["embedding"] = document["embedding"].tolist()
599
596
 
600
- if dataframe:
601
- logger.warning(
602
- "Document %s has the `dataframe` field set. "
603
- "PgvectorDocumentStore no longer supports dataframes and this field will be ignored. "
604
- "The `dataframe` field will soon be removed from Haystack Document.",
605
- haystack_dict["id"],
606
- )
607
-
608
597
  haystack_document = Document.from_dict(haystack_dict)
609
598
 
610
599
  if blob_data:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgvector-haystack
3
- Version: 2.0.0
3
+ Version: 3.0.1
4
4
  Summary: An integration of pgvector (vector search extension for Postgres) with Haystack
5
5
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations
6
6
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/pgvector/README.md
@@ -11,15 +11,14 @@ License-File: LICENSE.txt
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.8
15
14
  Classifier: Programming Language :: Python :: 3.9
16
15
  Classifier: Programming Language :: Python :: 3.10
17
16
  Classifier: Programming Language :: Python :: 3.11
18
17
  Classifier: Programming Language :: Python :: 3.12
19
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
21
- Requires-Python: >=3.8
22
- Requires-Dist: haystack-ai
20
+ Requires-Python: >=3.9
21
+ Requires-Dist: haystack-ai>=2.11.0
23
22
  Requires-Dist: pgvector
24
23
  Requires-Dist: psycopg[binary]
25
24
  Description-Content-Type: text/markdown
@@ -2,9 +2,9 @@ haystack_integrations/components/retrievers/pgvector/__init__.py,sha256=n4q4pUAp
2
2
  haystack_integrations/components/retrievers/pgvector/embedding_retriever.py,sha256=IEIdgKy_IWgmL5Qy_Hqkwa2mq2JxnQ_JOdjm38JPxmE,7530
3
3
  haystack_integrations/components/retrievers/pgvector/keyword_retriever.py,sha256=SYHqjTkDczobYZ2qq0z8yS9p_g8aINnzwA5AN_nKdHI,5632
4
4
  haystack_integrations/document_stores/pgvector/__init__.py,sha256=Ge-7ggarfr3x8UqNdFHUuFGiu52u49sOVe3l16WEwZU,197
5
- haystack_integrations/document_stores/pgvector/document_store.py,sha256=rirjSAMaPLADimwPcj-WQohrQbnXpTWgOCSIJy3qpPg,32148
5
+ haystack_integrations/document_stores/pgvector/document_store.py,sha256=gzyJJkDdGFfi6gdpPjKpTw9Ya2dEY28p9HstSjiJbIU,31590
6
6
  haystack_integrations/document_stores/pgvector/filters.py,sha256=M-_wmM1iKS1QdKhnRk27N8t2W1st2YZWAwVSFUyyTtk,8508
7
- pgvector_haystack-2.0.0.dist-info/METADATA,sha256=NhUGkaP8KzfX8qrlU5LrI-pjEQ3B4UDCfqN-WvlXsGY,2226
8
- pgvector_haystack-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- pgvector_haystack-2.0.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
10
- pgvector_haystack-2.0.0.dist-info/RECORD,,
7
+ pgvector_haystack-3.0.1.dist-info/METADATA,sha256=9xjXoMRnchq0NlQOflI_EQHdmn4fwZgwzLS7vkUVmIw,2184
8
+ pgvector_haystack-3.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ pgvector_haystack-3.0.1.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
10
+ pgvector_haystack-3.0.1.dist-info/RECORD,,