pgvector-haystack 3.0.1__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.
Files changed (26) hide show
  1. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/CHANGELOG.md +143 -135
  2. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/PKG-INFO +2 -1
  3. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/pyproject.toml +4 -3
  4. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/src/haystack_integrations/components/retrievers/pgvector/embedding_retriever.py +35 -1
  5. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/src/haystack_integrations/components/retrievers/pgvector/keyword_retriever.py +30 -0
  6. pgvector_haystack-3.1.0/src/haystack_integrations/document_stores/pgvector/converters.py +65 -0
  7. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/src/haystack_integrations/document_stores/pgvector/document_store.py +582 -247
  8. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/src/haystack_integrations/document_stores/pgvector/filters.py +14 -1
  9. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/tests/conftest.py +31 -11
  10. pgvector_haystack-3.1.0/tests/test_converters.py +122 -0
  11. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/tests/test_document_store.py +15 -135
  12. pgvector_haystack-3.1.0/tests/test_document_store_async.py +189 -0
  13. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/tests/test_filters.py +14 -0
  14. pgvector_haystack-3.0.1/tests/test_embedding_retrieval.py → pgvector_haystack-3.1.0/tests/test_retrieval.py +47 -20
  15. pgvector_haystack-3.1.0/tests/test_retrieval_async.py +163 -0
  16. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/tests/test_retrievers.py +45 -0
  17. pgvector_haystack-3.0.1/tests/test_keyword_retrieval.py +0 -51
  18. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/.gitignore +0 -0
  19. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/LICENSE.txt +0 -0
  20. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/README.md +0 -0
  21. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/examples/embedding_retrieval.py +0 -0
  22. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/examples/hybrid_retrieval.py +0 -0
  23. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/pydoc/config.yml +0 -0
  24. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/src/haystack_integrations/components/retrievers/pgvector/__init__.py +0 -0
  25. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/src/haystack_integrations/document_stores/pgvector/__init__.py +0 -0
  26. {pgvector_haystack-3.0.1 → pgvector_haystack-3.1.0}/tests/__init__.py +0 -0
@@ -1,135 +1,143 @@
1
- # Changelog
2
-
3
- ## [integrations/pgvector-v3.0.0] - 2025-03-11
4
-
5
- ### 🧹 Chores
6
-
7
- - Remove Python 3.8 support (#1421)
8
- - Use Haystack logging across integrations (#1484)
9
- - Pgvector - pin haystack and remove dataframe checks (#1518)
10
-
11
- ## [integrations/pgvector-v2.0.0] - 2025-02-13
12
-
13
- ### 🧹 Chores
14
-
15
- - Pgvector - remove support for dataframe (#1370)
16
-
17
- ## [integrations/pgvector-v1.3.0] - 2025-02-03
18
-
19
- ### 🚀 Features
20
-
21
- - Pgvector - add like and not like filters (#1341)
22
-
23
- ### 🧹 Chores
24
-
25
- - Inherit from `FilterDocumentsTestWithDataframe` in Document Stores (#1290)
26
-
27
-
28
- ## [integrations/pgvector-v1.2.1] - 2025-01-10
29
-
30
- ### 🐛 Bug Fixes
31
-
32
- - PgvectorDocumentStore - use appropriate schema name if dropping index (#1277)
33
-
34
-
35
- ## [integrations/pgvector-v1.2.0] - 2024-11-22
36
-
37
- ### 🚀 Features
38
-
39
- - Add `create_extension` parameter to control vector extension creation (#1213)
40
-
41
-
42
- ## [integrations/pgvector-v1.1.0] - 2024-11-21
43
-
44
- ### 🚀 Features
45
-
46
- - Add filter_policy to pgvector integration (#820)
47
- - Add schema support to pgvector document store. (#1095)
48
- - Pgvector - recreate the connection if it is no longer valid (#1202)
49
-
50
- ### 🐛 Bug Fixes
51
-
52
- - `PgVector` - Fallback to default filter policy when deserializing retrievers without the init parameter (#900)
53
-
54
- ### 📚 Documentation
55
-
56
- - Explain different connection string formats in the docstring (#1132)
57
-
58
- ### 🧪 Testing
59
-
60
- - Do not retry tests in `hatch run test` command (#954)
61
-
62
- ### ⚙️ CI
63
-
64
- - Retry tests to reduce flakyness (#836)
65
- - Adopt uv as installer (#1142)
66
-
67
- ### 🧹 Chores
68
-
69
- - Update ruff invocation to include check parameter (#853)
70
- - PgVector - remove legacy filter support (#1068)
71
- - Update changelog after removing legacy filters (#1083)
72
- - Update ruff linting scripts and settings (#1105)
73
-
74
- ### 🌀 Miscellaneous
75
-
76
- - Ci: install `pytest-rerunfailures` where needed; add retry config to `test-cov` script (#845)
77
- - Chore: Minor retriever pydoc fix (#884)
78
- - Chore: Update pgvector test for the new `apply_filter_policy` usage (#970)
79
- - Chore: pgvector ruff update, don't ruff tests (#984)
80
-
81
- ## [integrations/pgvector-v0.4.0] - 2024-06-20
82
-
83
- ### 🚀 Features
84
-
85
- - Defer the database connection to when it's needed (#773)
86
- - Add customizable index names for pgvector (#818)
87
-
88
- ### 🌀 Miscellaneous
89
-
90
- - Docs: add missing api references (#728)
91
- - [deepset-ai/haystack-core-integrations#727] (#738)
92
-
93
- ## [integrations/pgvector-v0.2.0] - 2024-05-08
94
-
95
- ### 🚀 Features
96
-
97
- - `MongoDBAtlasEmbeddingRetriever` (#427)
98
- - Implement keyword retrieval for pgvector integration (#644)
99
-
100
- ### 🐛 Bug Fixes
101
-
102
- - Fix order of API docs (#447)
103
-
104
- ### 📚 Documentation
105
-
106
- - Update category slug (#442)
107
- - Disable-class-def (#556)
108
-
109
- ### 🌀 Miscellaneous
110
-
111
- - Pgvector - review docstrings and API reference (#502)
112
- - Refactor tests (#574)
113
- - Remove references to Python 3.7 (#601)
114
- - Make Document Stores initially skip `SparseEmbedding` (#606)
115
- - Chore: add license classifiers (#680)
116
- - Type hints in pgvector document store updated for 3.8 compability (#704)
117
- - Chore: change the pydoc renderer class (#718)
118
-
119
- ## [integrations/pgvector-v0.1.0] - 2024-02-14
120
-
121
- ### 🐛 Bug Fixes
122
-
123
- - Pgvector: fix linting (#328)
124
-
125
- ### 🌀 Miscellaneous
126
-
127
- - Pgvector Document Store - minimal implementation (#239)
128
- - Pgvector - filters (#257)
129
- - Pgvector - embedding retrieval (#298)
130
- - Pgvector - Embedding Retriever (#320)
131
- - Pgvector: generate API docs (#325)
132
- - Pgvector: add an example (#334)
133
- - Adopt `Secret` to pgvector (#402)
134
-
135
- <!-- generated by git-cliff -->
1
+ # Changelog
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
+
17
+ ## [integrations/pgvector-v2.0.0] - 2025-02-13
18
+
19
+ ### 🧹 Chores
20
+
21
+ - Pgvector - remove support for dataframe (#1370)
22
+
23
+ ### 🌀 Miscellaneous
24
+
25
+ ## [integrations/pgvector-v1.3.0] - 2025-02-03
26
+
27
+ ### 🚀 Features
28
+
29
+ - Pgvector - add like and not like filters (#1341)
30
+
31
+ ### 🧹 Chores
32
+
33
+ - Inherit from `FilterDocumentsTestWithDataframe` in Document Stores (#1290)
34
+
35
+
36
+ ## [integrations/pgvector-v1.2.1] - 2025-01-10
37
+
38
+ ### 🐛 Bug Fixes
39
+
40
+ - PgvectorDocumentStore - use appropriate schema name if dropping index (#1277)
41
+
42
+
43
+ ## [integrations/pgvector-v1.2.0] - 2024-11-22
44
+
45
+ ### 🚀 Features
46
+
47
+ - Add `create_extension` parameter to control vector extension creation (#1213)
48
+
49
+
50
+ ## [integrations/pgvector-v1.1.0] - 2024-11-21
51
+
52
+ ### 🚀 Features
53
+
54
+ - Add filter_policy to pgvector integration (#820)
55
+ - Add schema support to pgvector document store. (#1095)
56
+ - Pgvector - recreate the connection if it is no longer valid (#1202)
57
+
58
+ ### 🐛 Bug Fixes
59
+
60
+ - `PgVector` - Fallback to default filter policy when deserializing retrievers without the init parameter (#900)
61
+
62
+ ### 📚 Documentation
63
+
64
+ - Explain different connection string formats in the docstring (#1132)
65
+
66
+ ### 🧪 Testing
67
+
68
+ - Do not retry tests in `hatch run test` command (#954)
69
+
70
+ ### ⚙️ CI
71
+
72
+ - Retry tests to reduce flakyness (#836)
73
+ - Adopt uv as installer (#1142)
74
+
75
+ ### 🧹 Chores
76
+
77
+ - Update ruff invocation to include check parameter (#853)
78
+ - PgVector - remove legacy filter support (#1068)
79
+ - Update changelog after removing legacy filters (#1083)
80
+ - Update ruff linting scripts and settings (#1105)
81
+
82
+ ### 🌀 Miscellaneous
83
+
84
+ - Ci: install `pytest-rerunfailures` where needed; add retry config to `test-cov` script (#845)
85
+ - Chore: Minor retriever pydoc fix (#884)
86
+ - Chore: Update pgvector test for the new `apply_filter_policy` usage (#970)
87
+ - Chore: pgvector ruff update, don't ruff tests (#984)
88
+
89
+ ## [integrations/pgvector-v0.4.0] - 2024-06-20
90
+
91
+ ### 🚀 Features
92
+
93
+ - Defer the database connection to when it's needed (#773)
94
+ - Add customizable index names for pgvector (#818)
95
+
96
+ ### 🌀 Miscellaneous
97
+
98
+ - Docs: add missing api references (#728)
99
+ - [deepset-ai/haystack-core-integrations#727] (#738)
100
+
101
+ ## [integrations/pgvector-v0.2.0] - 2024-05-08
102
+
103
+ ### 🚀 Features
104
+
105
+ - `MongoDBAtlasEmbeddingRetriever` (#427)
106
+ - Implement keyword retrieval for pgvector integration (#644)
107
+
108
+ ### 🐛 Bug Fixes
109
+
110
+ - Fix order of API docs (#447)
111
+
112
+ ### 📚 Documentation
113
+
114
+ - Update category slug (#442)
115
+ - Disable-class-def (#556)
116
+
117
+ ### 🌀 Miscellaneous
118
+
119
+ - Pgvector - review docstrings and API reference (#502)
120
+ - Refactor tests (#574)
121
+ - Remove references to Python 3.7 (#601)
122
+ - Make Document Stores initially skip `SparseEmbedding` (#606)
123
+ - Chore: add license classifiers (#680)
124
+ - Type hints in pgvector document store updated for 3.8 compability (#704)
125
+ - Chore: change the pydoc renderer class (#718)
126
+
127
+ ## [integrations/pgvector-v0.1.0] - 2024-02-14
128
+
129
+ ### 🐛 Bug Fixes
130
+
131
+ - Pgvector: fix linting (#328)
132
+
133
+ ### 🌀 Miscellaneous
134
+
135
+ - Pgvector Document Store - minimal implementation (#239)
136
+ - Pgvector - filters (#257)
137
+ - Pgvector - embedding retrieval (#298)
138
+ - Pgvector - Embedding Retriever (#320)
139
+ - Pgvector: generate API docs (#325)
140
+ - Pgvector: add an example (#334)
141
+ - Adopt `Secret` to pgvector (#402)
142
+
143
+ <!-- generated by git-cliff -->
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pgvector-haystack
3
- Version: 3.0.1
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: List of Documents similar to `query_embedding`.
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