pgvector-haystack 5.5.0__tar.gz → 6.0.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-5.5.0 → pgvector_haystack-6.0.0}/CHANGELOG.md +7 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/PKG-INFO +3 -4
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/pyproject.toml +3 -9
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/components/retrievers/pgvector/embedding_retriever.py +10 -10
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/components/retrievers/pgvector/keyword_retriever.py +7 -7
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/document_stores/pgvector/document_store.py +34 -34
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/document_stores/pgvector/filters.py +2 -2
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_document_store.py +1 -1
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_filters.py +1 -1
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/.gitignore +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/LICENSE.txt +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/README.md +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/examples/embedding_retrieval.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/examples/hybrid_retrieval.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/pydoc/config_docusaurus.yml +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/components/retrievers/pgvector/__init__.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/components/retrievers/py.typed +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/document_stores/pgvector/__init__.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/document_stores/pgvector/converters.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/src/haystack_integrations/document_stores/py.typed +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/__init__.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/conftest.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_converters.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_document_store_async.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_retrieval.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_retrieval_async.py +0 -0
- {pgvector_haystack-5.5.0 → pgvector_haystack-6.0.0}/tests/test_retrievers.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pgvector-haystack
|
|
3
|
-
Version:
|
|
3
|
+
Version: 6.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.9
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.13
|
|
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>=2.
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: haystack-ai>=2.22.0
|
|
23
22
|
Requires-Dist: pgvector>=0.3.0
|
|
24
23
|
Requires-Dist: psycopg[binary]
|
|
25
24
|
Description-Content-Type: text/markdown
|
|
@@ -7,7 +7,7 @@ name = "pgvector-haystack"
|
|
|
7
7
|
dynamic = ["version"]
|
|
8
8
|
description = "An integration of pgvector (vector search extension for Postgres) with Haystack"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
keywords = []
|
|
13
13
|
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
|
|
@@ -15,7 +15,6 @@ classifiers = [
|
|
|
15
15
|
"License :: OSI Approved :: Apache Software License",
|
|
16
16
|
"Development Status :: 4 - Beta",
|
|
17
17
|
"Programming Language :: Python",
|
|
18
|
-
"Programming Language :: Python :: 3.9",
|
|
19
18
|
"Programming Language :: Python :: 3.10",
|
|
20
19
|
"Programming Language :: Python :: 3.11",
|
|
21
20
|
"Programming Language :: Python :: 3.12",
|
|
@@ -23,7 +22,7 @@ classifiers = [
|
|
|
23
22
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
24
23
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
25
24
|
]
|
|
26
|
-
dependencies = ["haystack-ai>=2.
|
|
25
|
+
dependencies = ["haystack-ai>=2.22.0", "pgvector>=0.3.0", "psycopg[binary]"]
|
|
27
26
|
|
|
28
27
|
[project.urls]
|
|
29
28
|
Source = "https://github.com/deepset-ai/haystack-core-integrations"
|
|
@@ -47,7 +46,7 @@ dependencies = ["haystack-pydoc-tools", "ruff"]
|
|
|
47
46
|
|
|
48
47
|
[tool.hatch.envs.default.scripts]
|
|
49
48
|
docs = ["pydoc-markdown pydoc/config_docusaurus.yml"]
|
|
50
|
-
fmt = "ruff check --fix {args}
|
|
49
|
+
fmt = "ruff check --fix {args}; ruff format {args}"
|
|
51
50
|
fmt-check = "ruff check {args} && ruff format --check {args}"
|
|
52
51
|
|
|
53
52
|
[tool.hatch.envs.test]
|
|
@@ -83,7 +82,6 @@ ignore_missing_imports = true
|
|
|
83
82
|
|
|
84
83
|
|
|
85
84
|
[tool.ruff]
|
|
86
|
-
target-version = "py39"
|
|
87
85
|
line-length = 120
|
|
88
86
|
|
|
89
87
|
[tool.ruff.lint]
|
|
@@ -134,10 +132,6 @@ ignore = [
|
|
|
134
132
|
# ignore assertions
|
|
135
133
|
"S101",
|
|
136
134
|
]
|
|
137
|
-
unfixable = [
|
|
138
|
-
# Don't touch unused imports
|
|
139
|
-
"F401",
|
|
140
|
-
]
|
|
141
135
|
|
|
142
136
|
[tool.ruff.lint.isort]
|
|
143
137
|
known-first-party = ["haystack_integrations"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
from typing import Any, Literal
|
|
4
|
+
from typing import Any, Literal
|
|
5
5
|
|
|
6
6
|
from haystack import component, default_from_dict, default_to_dict
|
|
7
7
|
from haystack.dataclasses import Document
|
|
@@ -62,10 +62,10 @@ class PgvectorEmbeddingRetriever:
|
|
|
62
62
|
self,
|
|
63
63
|
*,
|
|
64
64
|
document_store: PgvectorDocumentStore,
|
|
65
|
-
filters:
|
|
65
|
+
filters: dict[str, Any] | None = None,
|
|
66
66
|
top_k: int = 10,
|
|
67
|
-
vector_function:
|
|
68
|
-
filter_policy:
|
|
67
|
+
vector_function: Literal["cosine_similarity", "inner_product", "l2_distance"] | None = None,
|
|
68
|
+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
|
|
69
69
|
):
|
|
70
70
|
"""
|
|
71
71
|
:param document_store: An instance of `PgvectorDocumentStore`.
|
|
@@ -137,9 +137,9 @@ class PgvectorEmbeddingRetriever:
|
|
|
137
137
|
def run(
|
|
138
138
|
self,
|
|
139
139
|
query_embedding: list[float],
|
|
140
|
-
filters:
|
|
141
|
-
top_k:
|
|
142
|
-
vector_function:
|
|
140
|
+
filters: dict[str, Any] | None = None,
|
|
141
|
+
top_k: int | None = None,
|
|
142
|
+
vector_function: Literal["cosine_similarity", "inner_product", "l2_distance"] | None = None,
|
|
143
143
|
) -> dict[str, list[Document]]:
|
|
144
144
|
"""
|
|
145
145
|
Retrieve documents from the `PgvectorDocumentStore`, based on their embeddings.
|
|
@@ -170,9 +170,9 @@ class PgvectorEmbeddingRetriever:
|
|
|
170
170
|
async def run_async(
|
|
171
171
|
self,
|
|
172
172
|
query_embedding: list[float],
|
|
173
|
-
filters:
|
|
174
|
-
top_k:
|
|
175
|
-
vector_function:
|
|
173
|
+
filters: dict[str, Any] | None = None,
|
|
174
|
+
top_k: int | None = None,
|
|
175
|
+
vector_function: Literal["cosine_similarity", "inner_product", "l2_distance"] | None = None,
|
|
176
176
|
) -> dict[str, list[Document]]:
|
|
177
177
|
"""
|
|
178
178
|
Asynchronously retrieve documents from the `PgvectorDocumentStore`, based on their embeddings.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
from typing import Any
|
|
4
|
+
from typing import Any
|
|
5
5
|
|
|
6
6
|
from haystack import component, default_from_dict, default_to_dict
|
|
7
7
|
from haystack.dataclasses import Document
|
|
@@ -52,9 +52,9 @@ class PgvectorKeywordRetriever:
|
|
|
52
52
|
self,
|
|
53
53
|
*,
|
|
54
54
|
document_store: PgvectorDocumentStore,
|
|
55
|
-
filters:
|
|
55
|
+
filters: dict[str, Any] | None = None,
|
|
56
56
|
top_k: int = 10,
|
|
57
|
-
filter_policy:
|
|
57
|
+
filter_policy: str | FilterPolicy = FilterPolicy.REPLACE,
|
|
58
58
|
):
|
|
59
59
|
"""
|
|
60
60
|
:param document_store: An instance of `PgvectorDocumentStore`.
|
|
@@ -111,8 +111,8 @@ class PgvectorKeywordRetriever:
|
|
|
111
111
|
def run(
|
|
112
112
|
self,
|
|
113
113
|
query: str,
|
|
114
|
-
filters:
|
|
115
|
-
top_k:
|
|
114
|
+
filters: dict[str, Any] | None = None,
|
|
115
|
+
top_k: int | None = None,
|
|
116
116
|
) -> dict[str, list[Document]]:
|
|
117
117
|
"""
|
|
118
118
|
Retrieve documents from the `PgvectorDocumentStore`, based on keywords.
|
|
@@ -141,8 +141,8 @@ class PgvectorKeywordRetriever:
|
|
|
141
141
|
async def run_async(
|
|
142
142
|
self,
|
|
143
143
|
query: str,
|
|
144
|
-
filters:
|
|
145
|
-
top_k:
|
|
144
|
+
filters: dict[str, Any] | None = None,
|
|
145
|
+
top_k: int | None = None,
|
|
146
146
|
) -> dict[str, list[Document]]:
|
|
147
147
|
"""
|
|
148
148
|
Asynchronously retrieve documents from the `PgvectorDocumentStore`, based on keywords.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
-
from typing import Any, Literal,
|
|
5
|
+
from typing import Any, Literal, overload
|
|
6
6
|
|
|
7
7
|
from haystack import default_from_dict, default_to_dict, logging
|
|
8
8
|
from haystack.dataclasses.document import Document
|
|
@@ -92,9 +92,9 @@ class PgvectorDocumentStore:
|
|
|
92
92
|
recreate_table: bool = False,
|
|
93
93
|
search_strategy: Literal["exact_nearest_neighbor", "hnsw"] = "exact_nearest_neighbor",
|
|
94
94
|
hnsw_recreate_index_if_exists: bool = False,
|
|
95
|
-
hnsw_index_creation_kwargs:
|
|
95
|
+
hnsw_index_creation_kwargs: dict[str, int] | None = None,
|
|
96
96
|
hnsw_index_name: str = "haystack_hnsw_index",
|
|
97
|
-
hnsw_ef_search:
|
|
97
|
+
hnsw_ef_search: int | None = None,
|
|
98
98
|
keyword_index_name: str = "haystack_keyword_index",
|
|
99
99
|
):
|
|
100
100
|
"""
|
|
@@ -175,12 +175,12 @@ class PgvectorDocumentStore:
|
|
|
175
175
|
self.keyword_index_name = keyword_index_name
|
|
176
176
|
self.language = language
|
|
177
177
|
|
|
178
|
-
self._connection:
|
|
179
|
-
self._async_connection:
|
|
180
|
-
self._cursor:
|
|
181
|
-
self._async_cursor:
|
|
182
|
-
self._dict_cursor:
|
|
183
|
-
self._async_dict_cursor:
|
|
178
|
+
self._connection: Connection | None = None
|
|
179
|
+
self._async_connection: AsyncConnection | None = None
|
|
180
|
+
self._cursor: Cursor | None = None
|
|
181
|
+
self._async_cursor: AsyncCursor | None = None
|
|
182
|
+
self._dict_cursor: Cursor[DictRow] | None = None
|
|
183
|
+
self._async_dict_cursor: AsyncCursor[DictRow] | None = None
|
|
184
184
|
self._table_initialized = False
|
|
185
185
|
|
|
186
186
|
def to_dict(self) -> dict[str, Any]:
|
|
@@ -250,21 +250,21 @@ class PgvectorDocumentStore:
|
|
|
250
250
|
|
|
251
251
|
@overload
|
|
252
252
|
def _execute_sql(
|
|
253
|
-
self, cursor: Cursor, sql_query: Composed, params:
|
|
253
|
+
self, cursor: Cursor, sql_query: Composed, params: tuple | None = None, error_msg: str = ""
|
|
254
254
|
) -> Cursor: ...
|
|
255
255
|
|
|
256
256
|
@overload
|
|
257
257
|
def _execute_sql(
|
|
258
|
-
self, cursor: Cursor[DictRow], sql_query: Composed, params:
|
|
258
|
+
self, cursor: Cursor[DictRow], sql_query: Composed, params: tuple | None = None, error_msg: str = ""
|
|
259
259
|
) -> Cursor[DictRow]: ...
|
|
260
260
|
|
|
261
261
|
def _execute_sql(
|
|
262
262
|
self,
|
|
263
|
-
cursor:
|
|
263
|
+
cursor: Cursor | Cursor[DictRow],
|
|
264
264
|
sql_query: Composed,
|
|
265
|
-
params:
|
|
265
|
+
params: tuple | None = None,
|
|
266
266
|
error_msg: str = "",
|
|
267
|
-
) ->
|
|
267
|
+
) -> Cursor | Cursor[DictRow]:
|
|
268
268
|
"""
|
|
269
269
|
Internal method to execute SQL statements and handle exceptions.
|
|
270
270
|
|
|
@@ -299,21 +299,21 @@ class PgvectorDocumentStore:
|
|
|
299
299
|
|
|
300
300
|
@overload
|
|
301
301
|
async def _execute_sql_async(
|
|
302
|
-
self, cursor: AsyncCursor, sql_query: Composed, params:
|
|
302
|
+
self, cursor: AsyncCursor, sql_query: Composed, params: tuple | None = None, error_msg: str = ""
|
|
303
303
|
) -> AsyncCursor: ...
|
|
304
304
|
|
|
305
305
|
@overload
|
|
306
306
|
async def _execute_sql_async(
|
|
307
|
-
self, cursor: AsyncCursor[DictRow], sql_query: Composed, params:
|
|
307
|
+
self, cursor: AsyncCursor[DictRow], sql_query: Composed, params: tuple | None = None, error_msg: str = ""
|
|
308
308
|
) -> AsyncCursor[DictRow]: ...
|
|
309
309
|
|
|
310
310
|
async def _execute_sql_async(
|
|
311
311
|
self,
|
|
312
|
-
cursor:
|
|
312
|
+
cursor: AsyncCursor | AsyncCursor[DictRow],
|
|
313
313
|
sql_query: Composed,
|
|
314
|
-
params:
|
|
314
|
+
params: tuple | None = None,
|
|
315
315
|
error_msg: str = "",
|
|
316
|
-
) ->
|
|
316
|
+
) -> AsyncCursor | AsyncCursor[DictRow]:
|
|
317
317
|
"""
|
|
318
318
|
Internal method to asynchronously execute SQL statements and handle exceptions.
|
|
319
319
|
|
|
@@ -759,12 +759,12 @@ class PgvectorDocumentStore:
|
|
|
759
759
|
return result[0]
|
|
760
760
|
return 0
|
|
761
761
|
|
|
762
|
-
def filter_documents(self, filters:
|
|
762
|
+
def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Document]:
|
|
763
763
|
"""
|
|
764
764
|
Returns the documents that match the filters provided.
|
|
765
765
|
|
|
766
766
|
For a detailed specification of the filters,
|
|
767
|
-
refer to the [documentation](https://docs.haystack.deepset.ai/
|
|
767
|
+
refer to the [documentation](https://docs.haystack.deepset.ai/docs/metadata-filtering)
|
|
768
768
|
|
|
769
769
|
:param filters: The filters to apply to the document list.
|
|
770
770
|
:raises TypeError: If `filters` is not a dictionary.
|
|
@@ -796,12 +796,12 @@ class PgvectorDocumentStore:
|
|
|
796
796
|
docs = _from_pg_to_haystack_documents(records)
|
|
797
797
|
return docs
|
|
798
798
|
|
|
799
|
-
async def filter_documents_async(self, filters:
|
|
799
|
+
async def filter_documents_async(self, filters: dict[str, Any] | None = None) -> list[Document]:
|
|
800
800
|
"""
|
|
801
801
|
Asynchronously returns the documents that match the filters provided.
|
|
802
802
|
|
|
803
803
|
For a detailed specification of the filters,
|
|
804
|
-
refer to the [documentation](https://docs.haystack.deepset.ai/
|
|
804
|
+
refer to the [documentation](https://docs.haystack.deepset.ai/docs/metadata-filtering)
|
|
805
805
|
|
|
806
806
|
:param filters: The filters to apply to the document list.
|
|
807
807
|
|
|
@@ -1223,7 +1223,7 @@ class PgvectorDocumentStore:
|
|
|
1223
1223
|
raise DocumentStoreError(msg) from e
|
|
1224
1224
|
|
|
1225
1225
|
def _build_keyword_retrieval_query(
|
|
1226
|
-
self, query: str, top_k: int, filters:
|
|
1226
|
+
self, query: str, top_k: int, filters: dict[str, Any] | None = None
|
|
1227
1227
|
) -> tuple[Composed, tuple]:
|
|
1228
1228
|
"""
|
|
1229
1229
|
Builds the SQL query and the where parameters for keyword retrieval.
|
|
@@ -1236,7 +1236,7 @@ class PgvectorDocumentStore:
|
|
|
1236
1236
|
)
|
|
1237
1237
|
|
|
1238
1238
|
where_params = ()
|
|
1239
|
-
sql_where_clause:
|
|
1239
|
+
sql_where_clause: Composed | SQL = SQL("")
|
|
1240
1240
|
if filters:
|
|
1241
1241
|
sql_where_clause, where_params = _convert_filters_to_where_clause_and_params(
|
|
1242
1242
|
filters=filters, operator="AND"
|
|
@@ -1252,7 +1252,7 @@ class PgvectorDocumentStore:
|
|
|
1252
1252
|
self,
|
|
1253
1253
|
query: str,
|
|
1254
1254
|
*,
|
|
1255
|
-
filters:
|
|
1255
|
+
filters: dict[str, Any] | None = None,
|
|
1256
1256
|
top_k: int = 10,
|
|
1257
1257
|
) -> list[Document]:
|
|
1258
1258
|
"""
|
|
@@ -1287,7 +1287,7 @@ class PgvectorDocumentStore:
|
|
|
1287
1287
|
self,
|
|
1288
1288
|
query: str,
|
|
1289
1289
|
*,
|
|
1290
|
-
filters:
|
|
1290
|
+
filters: dict[str, Any] | None = None,
|
|
1291
1291
|
top_k: int = 10,
|
|
1292
1292
|
) -> list[Document]:
|
|
1293
1293
|
"""
|
|
@@ -1315,9 +1315,9 @@ class PgvectorDocumentStore:
|
|
|
1315
1315
|
def _check_and_build_embedding_retrieval_query(
|
|
1316
1316
|
self,
|
|
1317
1317
|
query_embedding: list[float],
|
|
1318
|
-
vector_function:
|
|
1318
|
+
vector_function: Literal["cosine_similarity", "inner_product", "l2_distance"] | None,
|
|
1319
1319
|
top_k: int,
|
|
1320
|
-
filters:
|
|
1320
|
+
filters: dict[str, Any] | None = None,
|
|
1321
1321
|
) -> tuple[Composed, tuple]:
|
|
1322
1322
|
"""
|
|
1323
1323
|
Performs checks and builds the SQL query and the where parameters for embedding retrieval.
|
|
@@ -1357,7 +1357,7 @@ class PgvectorDocumentStore:
|
|
|
1357
1357
|
score=SQL(score_definition),
|
|
1358
1358
|
)
|
|
1359
1359
|
|
|
1360
|
-
sql_where_clause:
|
|
1360
|
+
sql_where_clause: Composed | SQL = SQL("")
|
|
1361
1361
|
params = ()
|
|
1362
1362
|
if filters:
|
|
1363
1363
|
sql_where_clause, params = _convert_filters_to_where_clause_and_params(filters)
|
|
@@ -1379,9 +1379,9 @@ class PgvectorDocumentStore:
|
|
|
1379
1379
|
self,
|
|
1380
1380
|
query_embedding: list[float],
|
|
1381
1381
|
*,
|
|
1382
|
-
filters:
|
|
1382
|
+
filters: dict[str, Any] | None = None,
|
|
1383
1383
|
top_k: int = 10,
|
|
1384
|
-
vector_function:
|
|
1384
|
+
vector_function: Literal["cosine_similarity", "inner_product", "l2_distance"] | None = None,
|
|
1385
1385
|
) -> list[Document]:
|
|
1386
1386
|
"""
|
|
1387
1387
|
Retrieves documents that are most similar to the query embedding using a vector similarity metric.
|
|
@@ -1413,9 +1413,9 @@ class PgvectorDocumentStore:
|
|
|
1413
1413
|
self,
|
|
1414
1414
|
query_embedding: list[float],
|
|
1415
1415
|
*,
|
|
1416
|
-
filters:
|
|
1416
|
+
filters: dict[str, Any] | None = None,
|
|
1417
1417
|
top_k: int = 10,
|
|
1418
|
-
vector_function:
|
|
1418
|
+
vector_function: Literal["cosine_similarity", "inner_product", "l2_distance"] | None = None,
|
|
1419
1419
|
) -> list[Document]:
|
|
1420
1420
|
"""
|
|
1421
1421
|
Asynchronously retrieves documents that are most similar to the query embedding using a
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from itertools import chain
|
|
6
|
-
from typing import Any, Literal
|
|
6
|
+
from typing import Any, Literal
|
|
7
7
|
|
|
8
8
|
from haystack.errors import FilterError
|
|
9
9
|
from psycopg.sql import SQL, Composed
|
|
@@ -21,7 +21,7 @@ PYTHON_TYPES_TO_PG_TYPES = {
|
|
|
21
21
|
NO_VALUE = "no_value"
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def _validate_filters(filters:
|
|
24
|
+
def _validate_filters(filters: dict[str, Any] | None = None) -> None:
|
|
25
25
|
"""
|
|
26
26
|
Validates the filters provided.
|
|
27
27
|
"""
|
|
@@ -154,7 +154,7 @@ def test_halfvec_hnsw_write_documents(document_store_w_halfvec_hnsw_index: Pgvec
|
|
|
154
154
|
retrieved_docs = document_store_w_halfvec_hnsw_index.filter_documents()
|
|
155
155
|
retrieved_docs.sort(key=lambda x: x.id)
|
|
156
156
|
|
|
157
|
-
for original_doc, retrieved_doc in zip(documents, retrieved_docs):
|
|
157
|
+
for original_doc, retrieved_doc in zip(documents, retrieved_docs, strict=True):
|
|
158
158
|
assert original_doc.id == retrieved_doc.id
|
|
159
159
|
assert original_doc.content == retrieved_doc.content
|
|
160
160
|
assert len(original_doc.embedding) == len(retrieved_doc.embedding)
|
|
@@ -24,7 +24,7 @@ class TestFilters(FilterDocumentsTest):
|
|
|
24
24
|
assert len(received) == len(expected)
|
|
25
25
|
received.sort(key=lambda x: x.id)
|
|
26
26
|
expected.sort(key=lambda x: x.id)
|
|
27
|
-
for received_doc, expected_doc in zip(received, expected):
|
|
27
|
+
for received_doc, expected_doc in zip(received, expected, strict=True):
|
|
28
28
|
# we first compare the embeddings approximately
|
|
29
29
|
if received_doc.embedding is None:
|
|
30
30
|
assert expected_doc.embedding is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|