pgvector-haystack 1.3.0__py3-none-any.whl → 3.0.0__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.
- haystack_integrations/document_stores/pgvector/document_store.py +9 -15
- haystack_integrations/document_stores/pgvector/filters.py +0 -5
- {pgvector_haystack-1.3.0.dist-info → pgvector_haystack-3.0.0.dist-info}/METADATA +3 -4
- {pgvector_haystack-1.3.0.dist-info → pgvector_haystack-3.0.0.dist-info}/RECORD +6 -6
- {pgvector_haystack-1.3.0.dist-info → pgvector_haystack-3.0.0.dist-info}/WHEEL +0 -0
- {pgvector_haystack-1.3.0.dist-info → pgvector_haystack-3.0.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -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
|
|
@@ -28,7 +27,6 @@ CREATE TABLE IF NOT EXISTS {schema_name}.{table_name} (
|
|
|
28
27
|
id VARCHAR(128) PRIMARY KEY,
|
|
29
28
|
embedding VECTOR({embedding_dimension}),
|
|
30
29
|
content TEXT,
|
|
31
|
-
dataframe JSONB,
|
|
32
30
|
blob_data BYTEA,
|
|
33
31
|
blob_meta JSONB,
|
|
34
32
|
blob_mime_type VARCHAR(255),
|
|
@@ -37,15 +35,14 @@ meta JSONB)
|
|
|
37
35
|
|
|
38
36
|
INSERT_STATEMENT = """
|
|
39
37
|
INSERT INTO {schema_name}.{table_name}
|
|
40
|
-
(id, embedding, content,
|
|
41
|
-
VALUES (%(id)s, %(embedding)s, %(content)s, %(
|
|
38
|
+
(id, embedding, content, blob_data, blob_meta, blob_mime_type, meta)
|
|
39
|
+
VALUES (%(id)s, %(embedding)s, %(content)s, %(blob_data)s, %(blob_meta)s, %(blob_mime_type)s, %(meta)s)
|
|
42
40
|
"""
|
|
43
41
|
|
|
44
42
|
UPDATE_STATEMENT = """
|
|
45
43
|
ON CONFLICT (id) DO UPDATE SET
|
|
46
44
|
embedding = EXCLUDED.embedding,
|
|
47
45
|
content = EXCLUDED.content,
|
|
48
|
-
dataframe = EXCLUDED.dataframe,
|
|
49
46
|
blob_data = EXCLUDED.blob_data,
|
|
50
47
|
blob_meta = EXCLUDED.blob_meta,
|
|
51
48
|
blob_mime_type = EXCLUDED.blob_mime_type,
|
|
@@ -195,7 +192,7 @@ class PgvectorDocumentStore:
|
|
|
195
192
|
try:
|
|
196
193
|
self._connection.close()
|
|
197
194
|
except Error as e:
|
|
198
|
-
logger.debug("Failed to close connection:
|
|
195
|
+
logger.debug("Failed to close connection: {e}", e=str(e))
|
|
199
196
|
|
|
200
197
|
conn_str = self.connection_string.resolve_value() or ""
|
|
201
198
|
connection = connect(conn_str)
|
|
@@ -297,7 +294,7 @@ class PgvectorDocumentStore:
|
|
|
297
294
|
cursor = cursor or self.cursor
|
|
298
295
|
|
|
299
296
|
sql_query_str = sql_query.as_string(cursor) if not isinstance(sql_query, str) else sql_query
|
|
300
|
-
logger.debug("SQL query:
|
|
297
|
+
logger.debug("SQL query: {query}\nParameters: {parameters}", query=sql_query_str, parameters=params)
|
|
301
298
|
|
|
302
299
|
try:
|
|
303
300
|
result = cursor.execute(sql_query, params)
|
|
@@ -514,7 +511,7 @@ class PgvectorDocumentStore:
|
|
|
514
511
|
sql_insert += SQL(" RETURNING id")
|
|
515
512
|
|
|
516
513
|
sql_query_str = sql_insert.as_string(self.cursor) if not isinstance(sql_insert, str) else sql_insert
|
|
517
|
-
logger.debug("SQL query:
|
|
514
|
+
logger.debug("SQL query: {query}\nParameters: {parameters}", query=sql_query_str, parameters=db_documents)
|
|
518
515
|
|
|
519
516
|
try:
|
|
520
517
|
self.cursor.executemany(sql_insert, db_documents, returning=True)
|
|
@@ -555,18 +552,16 @@ class PgvectorDocumentStore:
|
|
|
555
552
|
db_document["blob_data"] = blob.data if blob else None
|
|
556
553
|
db_document["blob_meta"] = Jsonb(blob.meta) if blob and blob.meta else None
|
|
557
554
|
db_document["blob_mime_type"] = blob.mime_type if blob and blob.mime_type else None
|
|
558
|
-
|
|
559
|
-
db_document["dataframe"] = Jsonb(db_document["dataframe"]) if db_document["dataframe"] else None
|
|
560
555
|
db_document["meta"] = Jsonb(db_document["meta"])
|
|
561
556
|
|
|
562
557
|
if "sparse_embedding" in db_document:
|
|
563
558
|
sparse_embedding = db_document.pop("sparse_embedding", None)
|
|
564
559
|
if sparse_embedding:
|
|
565
560
|
logger.warning(
|
|
566
|
-
"Document
|
|
561
|
+
"Document {doc_id} has the `sparse_embedding` field set,"
|
|
567
562
|
"but storing sparse embeddings in Pgvector is not currently supported."
|
|
568
563
|
"The `sparse_embedding` field will be ignored.",
|
|
569
|
-
db_document["id"],
|
|
564
|
+
doc_id=db_document["id"],
|
|
570
565
|
)
|
|
571
566
|
|
|
572
567
|
db_documents.append(db_document)
|
|
@@ -586,8 +581,7 @@ class PgvectorDocumentStore:
|
|
|
586
581
|
blob_meta = haystack_dict.pop("blob_meta")
|
|
587
582
|
blob_mime_type = haystack_dict.pop("blob_mime_type")
|
|
588
583
|
|
|
589
|
-
#
|
|
590
|
-
# so we need to convert it to a list of floats
|
|
584
|
+
# convert the embedding to a list of floats
|
|
591
585
|
if document.get("embedding") is not None:
|
|
592
586
|
haystack_dict["embedding"] = document["embedding"].tolist()
|
|
593
587
|
|
|
@@ -6,7 +6,6 @@ from itertools import chain
|
|
|
6
6
|
from typing import Any, Dict, List, Literal, Tuple
|
|
7
7
|
|
|
8
8
|
from haystack.errors import FilterError
|
|
9
|
-
from pandas import DataFrame
|
|
10
9
|
from psycopg.sql import SQL
|
|
11
10
|
from psycopg.types.json import Jsonb
|
|
12
11
|
|
|
@@ -93,10 +92,6 @@ def _parse_comparison_condition(condition: Dict[str, Any]) -> Tuple[str, List[An
|
|
|
93
92
|
raise FilterError(msg)
|
|
94
93
|
|
|
95
94
|
value: Any = condition["value"]
|
|
96
|
-
if isinstance(value, DataFrame):
|
|
97
|
-
# DataFrames are stored as JSONB and we query them as such
|
|
98
|
-
value = Jsonb(value.to_json())
|
|
99
|
-
field = f"({field})::jsonb"
|
|
100
95
|
|
|
101
96
|
if field.startswith("meta."):
|
|
102
97
|
field = _treat_meta_field(field, value)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pgvector-haystack
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
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.
|
|
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=
|
|
6
|
-
haystack_integrations/document_stores/pgvector/filters.py,sha256=
|
|
7
|
-
pgvector_haystack-
|
|
8
|
-
pgvector_haystack-
|
|
9
|
-
pgvector_haystack-
|
|
10
|
-
pgvector_haystack-
|
|
5
|
+
haystack_integrations/document_stores/pgvector/document_store.py,sha256=bs1MCwiQgoTw8Wrad8DaRRgIQokk8_t1fLmzxdufWS4,31267
|
|
6
|
+
haystack_integrations/document_stores/pgvector/filters.py,sha256=M-_wmM1iKS1QdKhnRk27N8t2W1st2YZWAwVSFUyyTtk,8508
|
|
7
|
+
pgvector_haystack-3.0.0.dist-info/METADATA,sha256=1rd0uO91j_NxG5hmxXIhn7RFPYJsDgO9w7XBqKMMw-Q,2184
|
|
8
|
+
pgvector_haystack-3.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
pgvector_haystack-3.0.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
|
|
10
|
+
pgvector_haystack-3.0.0.dist-info/RECORD,,
|
|
File without changes
|
{pgvector_haystack-1.3.0.dist-info → pgvector_haystack-3.0.0.dist-info}/licenses/LICENSE.txt
RENAMED
|
File without changes
|