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