pgvector-haystack 0.3.0__tar.gz → 0.4.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-0.4.0/CHANGELOG.md +35 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/PKG-INFO +1 -1
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/src/haystack_integrations/document_stores/pgvector/document_store.py +13 -9
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/test_document_store.py +8 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/test_retrievers.py +12 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/.gitignore +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/LICENSE.txt +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/README.md +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/examples/embedding_retrieval.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/examples/hybrid_retrieval.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/pydoc/config.yml +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/pyproject.toml +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/src/haystack_integrations/components/retrievers/pgvector/__init__.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/src/haystack_integrations/components/retrievers/pgvector/embedding_retriever.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/src/haystack_integrations/components/retrievers/pgvector/keyword_retriever.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/src/haystack_integrations/document_stores/pgvector/__init__.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/src/haystack_integrations/document_stores/pgvector/filters.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/__init__.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/conftest.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/test_embedding_retrieval.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/test_filters.py +0 -0
- {pgvector_haystack-0.3.0 → pgvector_haystack-0.4.0}/tests/test_keyword_retrieval.py +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [unreleased]
|
|
4
|
+
|
|
5
|
+
### 🚀 Features
|
|
6
|
+
|
|
7
|
+
- Defer the database connection to when it's needed (#773)
|
|
8
|
+
|
|
9
|
+
## [integrations/pgvector-v0.2.0] - 2024-05-08
|
|
10
|
+
|
|
11
|
+
### 🚀 Features
|
|
12
|
+
|
|
13
|
+
- `MongoDBAtlasEmbeddingRetriever` (#427)
|
|
14
|
+
- Implement keyword retrieval for pgvector integration (#644)
|
|
15
|
+
|
|
16
|
+
### 🐛 Bug Fixes
|
|
17
|
+
|
|
18
|
+
- Fix order of API docs (#447)
|
|
19
|
+
|
|
20
|
+
This PR will also push the docs to Readme
|
|
21
|
+
|
|
22
|
+
### 📚 Documentation
|
|
23
|
+
|
|
24
|
+
- Update category slug (#442)
|
|
25
|
+
- Disable-class-def (#556)
|
|
26
|
+
|
|
27
|
+
## [integrations/pgvector-v0.1.0] - 2024-02-14
|
|
28
|
+
|
|
29
|
+
### 🐛 Bug Fixes
|
|
30
|
+
|
|
31
|
+
- Fix linting (#328)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
<!-- generated by git-cliff -->
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: pgvector-haystack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.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
|
|
@@ -69,10 +69,6 @@ VECTOR_FUNCTION_TO_POSTGRESQL_OPS = {
|
|
|
69
69
|
|
|
70
70
|
HNSW_INDEX_CREATION_VALID_KWARGS = ["m", "ef_construction"]
|
|
71
71
|
|
|
72
|
-
HNSW_INDEX_NAME = "haystack_hnsw_index"
|
|
73
|
-
|
|
74
|
-
KEYWORD_INDEX_NAME = "haystack_keyword_index"
|
|
75
|
-
|
|
76
72
|
|
|
77
73
|
class PgvectorDocumentStore:
|
|
78
74
|
"""
|
|
@@ -91,7 +87,9 @@ class PgvectorDocumentStore:
|
|
|
91
87
|
search_strategy: Literal["exact_nearest_neighbor", "hnsw"] = "exact_nearest_neighbor",
|
|
92
88
|
hnsw_recreate_index_if_exists: bool = False,
|
|
93
89
|
hnsw_index_creation_kwargs: Optional[Dict[str, int]] = None,
|
|
90
|
+
hnsw_index_name: str = "haystack_hnsw_index",
|
|
94
91
|
hnsw_ef_search: Optional[int] = None,
|
|
92
|
+
keyword_index_name: str = "haystack_keyword_index",
|
|
95
93
|
):
|
|
96
94
|
"""
|
|
97
95
|
Creates a new PgvectorDocumentStore instance.
|
|
@@ -127,9 +125,11 @@ class PgvectorDocumentStore:
|
|
|
127
125
|
:param hnsw_index_creation_kwargs: Additional keyword arguments to pass to the HNSW index creation.
|
|
128
126
|
Only used if search_strategy is set to `"hnsw"`. You can find the list of valid arguments in the
|
|
129
127
|
[pgvector documentation](https://github.com/pgvector/pgvector?tab=readme-ov-file#hnsw)
|
|
128
|
+
:param hnsw_index_name: Index name for the HNSW index.
|
|
130
129
|
:param hnsw_ef_search: The `ef_search` parameter to use at query time. Only used if search_strategy is set to
|
|
131
130
|
`"hnsw"`. You can find more information about this parameter in the
|
|
132
131
|
[pgvector documentation](https://github.com/pgvector/pgvector?tab=readme-ov-file#hnsw).
|
|
132
|
+
:param keyword_index_name: Index name for the Keyword index.
|
|
133
133
|
"""
|
|
134
134
|
|
|
135
135
|
self.connection_string = connection_string
|
|
@@ -143,7 +143,9 @@ class PgvectorDocumentStore:
|
|
|
143
143
|
self.search_strategy = search_strategy
|
|
144
144
|
self.hnsw_recreate_index_if_exists = hnsw_recreate_index_if_exists
|
|
145
145
|
self.hnsw_index_creation_kwargs = hnsw_index_creation_kwargs or {}
|
|
146
|
+
self.hnsw_index_name = hnsw_index_name
|
|
146
147
|
self.hnsw_ef_search = hnsw_ef_search
|
|
148
|
+
self.keyword_index_name = keyword_index_name
|
|
147
149
|
self.language = language
|
|
148
150
|
self._connection = None
|
|
149
151
|
self._cursor = None
|
|
@@ -209,7 +211,9 @@ class PgvectorDocumentStore:
|
|
|
209
211
|
search_strategy=self.search_strategy,
|
|
210
212
|
hnsw_recreate_index_if_exists=self.hnsw_recreate_index_if_exists,
|
|
211
213
|
hnsw_index_creation_kwargs=self.hnsw_index_creation_kwargs,
|
|
214
|
+
hnsw_index_name=self.hnsw_index_name,
|
|
212
215
|
hnsw_ef_search=self.hnsw_ef_search,
|
|
216
|
+
keyword_index_name=self.keyword_index_name,
|
|
213
217
|
language=self.language,
|
|
214
218
|
)
|
|
215
219
|
|
|
@@ -281,7 +285,7 @@ class PgvectorDocumentStore:
|
|
|
281
285
|
index_exists = bool(
|
|
282
286
|
self._execute_sql(
|
|
283
287
|
"SELECT 1 FROM pg_indexes WHERE tablename = %s AND indexname = %s",
|
|
284
|
-
(self.table_name,
|
|
288
|
+
(self.table_name, self.keyword_index_name),
|
|
285
289
|
"Could not check if keyword index exists",
|
|
286
290
|
).fetchone()
|
|
287
291
|
)
|
|
@@ -289,7 +293,7 @@ class PgvectorDocumentStore:
|
|
|
289
293
|
sql_create_index = SQL(
|
|
290
294
|
"CREATE INDEX {index_name} ON {table_name} USING GIN (to_tsvector({language}, content))"
|
|
291
295
|
).format(
|
|
292
|
-
index_name=Identifier(
|
|
296
|
+
index_name=Identifier(self.keyword_index_name),
|
|
293
297
|
table_name=Identifier(self.table_name),
|
|
294
298
|
language=SQLLiteral(self.language),
|
|
295
299
|
)
|
|
@@ -312,7 +316,7 @@ class PgvectorDocumentStore:
|
|
|
312
316
|
index_exists = bool(
|
|
313
317
|
self._execute_sql(
|
|
314
318
|
"SELECT 1 FROM pg_indexes WHERE tablename = %s AND indexname = %s",
|
|
315
|
-
(self.table_name,
|
|
319
|
+
(self.table_name, self.hnsw_index_name),
|
|
316
320
|
"Could not check if HNSW index exists",
|
|
317
321
|
).fetchone()
|
|
318
322
|
)
|
|
@@ -325,7 +329,7 @@ class PgvectorDocumentStore:
|
|
|
325
329
|
)
|
|
326
330
|
return
|
|
327
331
|
|
|
328
|
-
sql_drop_index = SQL("DROP INDEX IF EXISTS {index_name}").format(index_name=Identifier(
|
|
332
|
+
sql_drop_index = SQL("DROP INDEX IF EXISTS {index_name}").format(index_name=Identifier(self.hnsw_index_name))
|
|
329
333
|
self._execute_sql(sql_drop_index, error_msg="Could not drop HNSW index")
|
|
330
334
|
|
|
331
335
|
self._create_hnsw_index()
|
|
@@ -343,7 +347,7 @@ class PgvectorDocumentStore:
|
|
|
343
347
|
}
|
|
344
348
|
|
|
345
349
|
sql_create_index = SQL("CREATE INDEX {index_name} ON {table_name} USING hnsw (embedding {ops}) ").format(
|
|
346
|
-
index_name=Identifier(
|
|
350
|
+
index_name=Identifier(self.hnsw_index_name), table_name=Identifier(self.table_name), ops=SQL(pg_ops)
|
|
347
351
|
)
|
|
348
352
|
|
|
349
353
|
if actual_hnsw_index_creation_kwargs:
|
|
@@ -53,7 +53,9 @@ def test_init(monkeypatch):
|
|
|
53
53
|
search_strategy="hnsw",
|
|
54
54
|
hnsw_recreate_index_if_exists=True,
|
|
55
55
|
hnsw_index_creation_kwargs={"m": 32, "ef_construction": 128},
|
|
56
|
+
hnsw_index_name="my_hnsw_index",
|
|
56
57
|
hnsw_ef_search=50,
|
|
58
|
+
keyword_index_name="my_keyword_index",
|
|
57
59
|
)
|
|
58
60
|
|
|
59
61
|
assert document_store.table_name == "my_table"
|
|
@@ -63,7 +65,9 @@ def test_init(monkeypatch):
|
|
|
63
65
|
assert document_store.search_strategy == "hnsw"
|
|
64
66
|
assert document_store.hnsw_recreate_index_if_exists
|
|
65
67
|
assert document_store.hnsw_index_creation_kwargs == {"m": 32, "ef_construction": 128}
|
|
68
|
+
assert document_store.hnsw_index_name == "my_hnsw_index"
|
|
66
69
|
assert document_store.hnsw_ef_search == 50
|
|
70
|
+
assert document_store.keyword_index_name == "my_keyword_index"
|
|
67
71
|
|
|
68
72
|
|
|
69
73
|
@pytest.mark.usefixtures("patches_for_unit_tests")
|
|
@@ -78,7 +82,9 @@ def test_to_dict(monkeypatch):
|
|
|
78
82
|
search_strategy="hnsw",
|
|
79
83
|
hnsw_recreate_index_if_exists=True,
|
|
80
84
|
hnsw_index_creation_kwargs={"m": 32, "ef_construction": 128},
|
|
85
|
+
hnsw_index_name="my_hnsw_index",
|
|
81
86
|
hnsw_ef_search=50,
|
|
87
|
+
keyword_index_name="my_keyword_index",
|
|
82
88
|
)
|
|
83
89
|
|
|
84
90
|
assert document_store.to_dict() == {
|
|
@@ -93,7 +99,9 @@ def test_to_dict(monkeypatch):
|
|
|
93
99
|
"hnsw_recreate_index_if_exists": True,
|
|
94
100
|
"language": "english",
|
|
95
101
|
"hnsw_index_creation_kwargs": {"m": 32, "ef_construction": 128},
|
|
102
|
+
"hnsw_index_name": "my_hnsw_index",
|
|
96
103
|
"hnsw_ef_search": 50,
|
|
104
|
+
"keyword_index_name": "my_keyword_index",
|
|
97
105
|
},
|
|
98
106
|
}
|
|
99
107
|
|
|
@@ -48,7 +48,9 @@ class TestEmbeddingRetriever:
|
|
|
48
48
|
"hnsw_recreate_index_if_exists": False,
|
|
49
49
|
"language": "english",
|
|
50
50
|
"hnsw_index_creation_kwargs": {},
|
|
51
|
+
"hnsw_index_name": "haystack_hnsw_index",
|
|
51
52
|
"hnsw_ef_search": None,
|
|
53
|
+
"keyword_index_name": "haystack_keyword_index",
|
|
52
54
|
},
|
|
53
55
|
},
|
|
54
56
|
"filters": {"field": "value"},
|
|
@@ -75,7 +77,9 @@ class TestEmbeddingRetriever:
|
|
|
75
77
|
"search_strategy": "exact_nearest_neighbor",
|
|
76
78
|
"hnsw_recreate_index_if_exists": False,
|
|
77
79
|
"hnsw_index_creation_kwargs": {},
|
|
80
|
+
"hnsw_index_name": "haystack_hnsw_index",
|
|
78
81
|
"hnsw_ef_search": None,
|
|
82
|
+
"keyword_index_name": "haystack_keyword_index",
|
|
79
83
|
},
|
|
80
84
|
},
|
|
81
85
|
"filters": {"field": "value"},
|
|
@@ -96,7 +100,9 @@ class TestEmbeddingRetriever:
|
|
|
96
100
|
assert document_store.search_strategy == "exact_nearest_neighbor"
|
|
97
101
|
assert not document_store.hnsw_recreate_index_if_exists
|
|
98
102
|
assert document_store.hnsw_index_creation_kwargs == {}
|
|
103
|
+
assert document_store.hnsw_index_name == "haystack_hnsw_index"
|
|
99
104
|
assert document_store.hnsw_ef_search is None
|
|
105
|
+
assert document_store.keyword_index_name == "haystack_keyword_index"
|
|
100
106
|
|
|
101
107
|
assert retriever.filters == {"field": "value"}
|
|
102
108
|
assert retriever.top_k == 5
|
|
@@ -149,7 +155,9 @@ class TestKeywordRetriever:
|
|
|
149
155
|
"hnsw_recreate_index_if_exists": False,
|
|
150
156
|
"language": "english",
|
|
151
157
|
"hnsw_index_creation_kwargs": {},
|
|
158
|
+
"hnsw_index_name": "haystack_hnsw_index",
|
|
152
159
|
"hnsw_ef_search": None,
|
|
160
|
+
"keyword_index_name": "haystack_keyword_index",
|
|
153
161
|
},
|
|
154
162
|
},
|
|
155
163
|
"filters": {"field": "value"},
|
|
@@ -175,7 +183,9 @@ class TestKeywordRetriever:
|
|
|
175
183
|
"search_strategy": "exact_nearest_neighbor",
|
|
176
184
|
"hnsw_recreate_index_if_exists": False,
|
|
177
185
|
"hnsw_index_creation_kwargs": {},
|
|
186
|
+
"hnsw_index_name": "haystack_hnsw_index",
|
|
178
187
|
"hnsw_ef_search": None,
|
|
188
|
+
"keyword_index_name": "haystack_keyword_index",
|
|
179
189
|
},
|
|
180
190
|
},
|
|
181
191
|
"filters": {"field": "value"},
|
|
@@ -195,7 +205,9 @@ class TestKeywordRetriever:
|
|
|
195
205
|
assert document_store.search_strategy == "exact_nearest_neighbor"
|
|
196
206
|
assert not document_store.hnsw_recreate_index_if_exists
|
|
197
207
|
assert document_store.hnsw_index_creation_kwargs == {}
|
|
208
|
+
assert document_store.hnsw_index_name == "haystack_hnsw_index"
|
|
198
209
|
assert document_store.hnsw_ef_search is None
|
|
210
|
+
assert document_store.keyword_index_name == "haystack_keyword_index"
|
|
199
211
|
|
|
200
212
|
assert retriever.filters == {"field": "value"}
|
|
201
213
|
assert retriever.top_k == 5
|
|
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
|