pgvector-haystack 3.0.0__tar.gz → 3.1.0__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.
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/CHANGELOG.md +16 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/PKG-INFO +2 -1
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/pyproject.toml +4 -3
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/src/haystack_integrations/components/retrievers/pgvector/embedding_retriever.py +35 -1
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/src/haystack_integrations/components/retrievers/pgvector/keyword_retriever.py +30 -0
- pgvector_haystack-3.1.0/src/haystack_integrations/document_stores/pgvector/converters.py +65 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/src/haystack_integrations/document_stores/pgvector/document_store.py +585 -241
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/src/haystack_integrations/document_stores/pgvector/filters.py +14 -1
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/tests/conftest.py +31 -11
- pgvector_haystack-3.1.0/tests/test_converters.py +122 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/tests/test_document_store.py +57 -130
- pgvector_haystack-3.1.0/tests/test_document_store_async.py +189 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/tests/test_filters.py +14 -0
- pgvector_haystack-3.0.0/tests/test_embedding_retrieval.py → pgvector_haystack-3.1.0/tests/test_retrieval.py +47 -20
- pgvector_haystack-3.1.0/tests/test_retrieval_async.py +163 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/tests/test_retrievers.py +45 -0
- pgvector_haystack-3.0.0/tests/test_keyword_retrieval.py +0 -51
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/.gitignore +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/LICENSE.txt +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/README.md +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/examples/embedding_retrieval.py +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/examples/hybrid_retrieval.py +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/pydoc/config.yml +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/src/haystack_integrations/components/retrievers/pgvector/__init__.py +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/src/haystack_integrations/document_stores/pgvector/__init__.py +0 -0
- {pgvector_haystack-3.0.0 → pgvector_haystack-3.1.0}/tests/__init__.py +0 -0
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [integrations/pgvector-v3.0.1] - 2025-03-12
|
|
4
|
+
|
|
5
|
+
### 🌀 Miscellaneous
|
|
6
|
+
|
|
7
|
+
- Fix: pgvector - improve `_create_table_if_not_exists` to be used without admin rights (#1490)
|
|
8
|
+
|
|
9
|
+
## [integrations/pgvector-v3.0.0] - 2025-03-11
|
|
10
|
+
|
|
11
|
+
### 🧹 Chores
|
|
12
|
+
|
|
13
|
+
- Remove Python 3.8 support (#1421)
|
|
14
|
+
- Use Haystack logging across integrations (#1484)
|
|
15
|
+
- Pgvector - pin haystack and remove dataframe checks (#1518)
|
|
16
|
+
|
|
3
17
|
## [integrations/pgvector-v2.0.0] - 2025-02-13
|
|
4
18
|
|
|
5
19
|
### 🧹 Chores
|
|
6
20
|
|
|
7
21
|
- Pgvector - remove support for dataframe (#1370)
|
|
8
22
|
|
|
23
|
+
### 🌀 Miscellaneous
|
|
24
|
+
|
|
9
25
|
## [integrations/pgvector-v1.3.0] - 2025-02-03
|
|
10
26
|
|
|
11
27
|
### 🚀 Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pgvector-haystack
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1.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
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
19
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
20
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
21
|
Requires-Python: >=3.9
|
|
@@ -19,6 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Programming Language :: Python :: 3.10",
|
|
20
20
|
"Programming Language :: Python :: 3.11",
|
|
21
21
|
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
22
23
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
24
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
25
|
]
|
|
@@ -48,6 +49,7 @@ dependencies = [
|
|
|
48
49
|
"pytest-rerunfailures",
|
|
49
50
|
"ipython",
|
|
50
51
|
"haystack-pydoc-tools",
|
|
52
|
+
"pytest-asyncio",
|
|
51
53
|
]
|
|
52
54
|
[tool.hatch.envs.default.scripts]
|
|
53
55
|
test = "pytest {args:tests}"
|
|
@@ -58,9 +60,6 @@ cov = ["test-cov", "cov-report"]
|
|
|
58
60
|
cov-retry = ["test-cov-retry", "cov-report"]
|
|
59
61
|
docs = ["pydoc-markdown pydoc/config.yml"]
|
|
60
62
|
|
|
61
|
-
[[tool.hatch.envs.all.matrix]]
|
|
62
|
-
python = [ "3.9", "3.10", "3.11", "3.12"]
|
|
63
|
-
|
|
64
63
|
[tool.hatch.envs.lint]
|
|
65
64
|
installer = "uv"
|
|
66
65
|
detached = true
|
|
@@ -125,6 +124,8 @@ ignore = [
|
|
|
125
124
|
"PLR0915",
|
|
126
125
|
# ignore function-call-in-default-argument
|
|
127
126
|
"B008",
|
|
127
|
+
# ignore assertions
|
|
128
|
+
"S101",
|
|
128
129
|
]
|
|
129
130
|
unfixable = [
|
|
130
131
|
# Don't touch unused imports
|
|
@@ -151,7 +151,8 @@ class PgvectorEmbeddingRetriever:
|
|
|
151
151
|
:param top_k: Maximum number of Documents to return.
|
|
152
152
|
:param vector_function: The similarity function to use when searching for similar embeddings.
|
|
153
153
|
|
|
154
|
-
:returns:
|
|
154
|
+
:returns: A dictionary with the following keys:
|
|
155
|
+
- `documents`: List of `Document`s that are similar to `query_embedding`.
|
|
155
156
|
"""
|
|
156
157
|
filters = apply_filter_policy(self.filter_policy, self.filters, filters)
|
|
157
158
|
top_k = top_k or self.top_k
|
|
@@ -164,3 +165,36 @@ class PgvectorEmbeddingRetriever:
|
|
|
164
165
|
vector_function=vector_function,
|
|
165
166
|
)
|
|
166
167
|
return {"documents": docs}
|
|
168
|
+
|
|
169
|
+
@component.output_types(documents=List[Document])
|
|
170
|
+
async def run_async(
|
|
171
|
+
self,
|
|
172
|
+
query_embedding: List[float],
|
|
173
|
+
filters: Optional[Dict[str, Any]] = None,
|
|
174
|
+
top_k: Optional[int] = None,
|
|
175
|
+
vector_function: Optional[Literal["cosine_similarity", "inner_product", "l2_distance"]] = None,
|
|
176
|
+
):
|
|
177
|
+
"""
|
|
178
|
+
Asynchronously retrieve documents from the `PgvectorDocumentStore`, based on their embeddings.
|
|
179
|
+
|
|
180
|
+
:param query_embedding: Embedding of the query.
|
|
181
|
+
:param filters: Filters applied to the retrieved Documents. The way runtime filters are applied depends on
|
|
182
|
+
the `filter_policy` chosen at retriever initialization. See init method docstring for more
|
|
183
|
+
details.
|
|
184
|
+
:param top_k: Maximum number of Documents to return.
|
|
185
|
+
:param vector_function: The similarity function to use when searching for similar embeddings.
|
|
186
|
+
|
|
187
|
+
:returns: A dictionary with the following keys:
|
|
188
|
+
- `documents`: List of `Document`s that are similar to `query_embedding`.
|
|
189
|
+
"""
|
|
190
|
+
filters = apply_filter_policy(self.filter_policy, self.filters, filters)
|
|
191
|
+
top_k = top_k or self.top_k
|
|
192
|
+
vector_function = vector_function or self.vector_function
|
|
193
|
+
|
|
194
|
+
docs = await self.document_store._embedding_retrieval_async(
|
|
195
|
+
query_embedding=query_embedding,
|
|
196
|
+
filters=filters,
|
|
197
|
+
top_k=top_k,
|
|
198
|
+
vector_function=vector_function,
|
|
199
|
+
)
|
|
200
|
+
return {"documents": docs}
|
|
@@ -136,3 +136,33 @@ class PgvectorKeywordRetriever:
|
|
|
136
136
|
top_k=top_k,
|
|
137
137
|
)
|
|
138
138
|
return {"documents": docs}
|
|
139
|
+
|
|
140
|
+
@component.output_types(documents=List[Document])
|
|
141
|
+
async def run_async(
|
|
142
|
+
self,
|
|
143
|
+
query: str,
|
|
144
|
+
filters: Optional[Dict[str, Any]] = None,
|
|
145
|
+
top_k: Optional[int] = None,
|
|
146
|
+
):
|
|
147
|
+
"""
|
|
148
|
+
Asynchronously retrieve documents from the `PgvectorDocumentStore`, based on keywords.
|
|
149
|
+
|
|
150
|
+
:param query: String to search in `Document`s' content.
|
|
151
|
+
:param filters: Filters applied to the retrieved Documents. The way runtime filters are applied depends on
|
|
152
|
+
the `filter_policy` chosen at retriever initialization. See init method docstring for more
|
|
153
|
+
details.
|
|
154
|
+
:param top_k: Maximum number of Documents to return.
|
|
155
|
+
|
|
156
|
+
:returns: A dictionary with the following keys:
|
|
157
|
+
- `documents`: List of `Document`s that match the query.
|
|
158
|
+
"""
|
|
159
|
+
filters = apply_filter_policy(self.filter_policy, self.filters, filters)
|
|
160
|
+
|
|
161
|
+
top_k = top_k or self.top_k
|
|
162
|
+
|
|
163
|
+
docs = await self.document_store._keyword_retrieval_async(
|
|
164
|
+
query=query,
|
|
165
|
+
filters=filters,
|
|
166
|
+
top_k=top_k,
|
|
167
|
+
)
|
|
168
|
+
return {"documents": docs}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
|
|
3
|
+
from haystack import logging
|
|
4
|
+
from haystack.dataclasses import ByteStream, Document
|
|
5
|
+
from psycopg.types.json import Jsonb
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _from_haystack_to_pg_documents(documents: List[Document]) -> List[Dict[str, Any]]:
|
|
11
|
+
"""
|
|
12
|
+
Internal method to convert a list of Haystack Documents to a list of dictionaries that can be used to insert
|
|
13
|
+
documents into the PgvectorDocumentStore.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
db_documents = []
|
|
17
|
+
for document in documents:
|
|
18
|
+
db_document = {k: v for k, v in document.to_dict(flatten=False).items() if k not in ["score", "blob"]}
|
|
19
|
+
|
|
20
|
+
blob = document.blob
|
|
21
|
+
db_document["blob_data"] = blob.data if blob else None
|
|
22
|
+
db_document["blob_meta"] = Jsonb(blob.meta) if blob and blob.meta else None
|
|
23
|
+
db_document["blob_mime_type"] = blob.mime_type if blob and blob.mime_type else None
|
|
24
|
+
db_document["meta"] = Jsonb(db_document["meta"])
|
|
25
|
+
|
|
26
|
+
if "sparse_embedding" in db_document:
|
|
27
|
+
sparse_embedding = db_document.pop("sparse_embedding", None)
|
|
28
|
+
if sparse_embedding:
|
|
29
|
+
logger.warning(
|
|
30
|
+
"Document {doc_id} has the `sparse_embedding` field set,"
|
|
31
|
+
"but storing sparse embeddings in Pgvector is not currently supported."
|
|
32
|
+
"The `sparse_embedding` field will be ignored.",
|
|
33
|
+
doc_id=db_document["id"],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
db_documents.append(db_document)
|
|
37
|
+
|
|
38
|
+
return db_documents
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _from_pg_to_haystack_documents(documents: List[Dict[str, Any]]) -> List[Document]:
|
|
42
|
+
"""
|
|
43
|
+
Internal method to convert a list of dictionaries from pgvector to a list of Haystack Documents.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
haystack_documents = []
|
|
47
|
+
for document in documents:
|
|
48
|
+
haystack_dict = dict(document)
|
|
49
|
+
blob_data = haystack_dict.pop("blob_data")
|
|
50
|
+
blob_meta = haystack_dict.pop("blob_meta")
|
|
51
|
+
blob_mime_type = haystack_dict.pop("blob_mime_type")
|
|
52
|
+
|
|
53
|
+
# convert the embedding to a list of floats
|
|
54
|
+
if document.get("embedding") is not None:
|
|
55
|
+
haystack_dict["embedding"] = document["embedding"].tolist()
|
|
56
|
+
|
|
57
|
+
haystack_document = Document.from_dict(haystack_dict)
|
|
58
|
+
|
|
59
|
+
if blob_data:
|
|
60
|
+
blob = ByteStream(data=blob_data, meta=blob_meta, mime_type=blob_mime_type)
|
|
61
|
+
haystack_document.blob = blob
|
|
62
|
+
|
|
63
|
+
haystack_documents.append(haystack_document)
|
|
64
|
+
|
|
65
|
+
return haystack_documents
|