llama-index-vector-stores-postgres 0.4.2__tar.gz → 0.5.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.
- llama_index_vector_stores_postgres-0.5.0/LICENSE +21 -0
- {llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/PKG-INFO +1 -1
- {llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/llama_index/vector_stores/postgres/base.py +34 -17
- {llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/pyproject.toml +2 -1
- {llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/README.md +0 -0
- {llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/llama_index/py.typed +0 -0
- {llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/llama_index/vector_stores/postgres/__init__.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Jerry Liu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class DBEmbeddingRow(NamedTuple):
|
|
32
|
-
node_id: str
|
|
32
|
+
node_id: str
|
|
33
33
|
text: str
|
|
34
34
|
metadata: dict
|
|
35
35
|
similarity: float
|
|
@@ -138,7 +138,6 @@ class PGVectorStore(BasePydanticVectorStore):
|
|
|
138
138
|
table_name="paul_graham_essay",
|
|
139
139
|
embed_dim=1536 # openai embedding dimension
|
|
140
140
|
use_halfvec=True # Enable half precision
|
|
141
|
-
|
|
142
141
|
)
|
|
143
142
|
```
|
|
144
143
|
"""
|
|
@@ -166,18 +165,20 @@ class PGVectorStore(BasePydanticVectorStore):
|
|
|
166
165
|
|
|
167
166
|
_base: Any = PrivateAttr()
|
|
168
167
|
_table_class: Any = PrivateAttr()
|
|
169
|
-
_engine:
|
|
170
|
-
_session:
|
|
171
|
-
_async_engine:
|
|
172
|
-
|
|
168
|
+
_engine: Optional[sqlalchemy.engine.Engine] = PrivateAttr(default=None)
|
|
169
|
+
_session: sqlalchemy.orm.Session = PrivateAttr()
|
|
170
|
+
_async_engine: Optional[sqlalchemy.ext.asyncio.AsyncEngine] = PrivateAttr(
|
|
171
|
+
default=None
|
|
172
|
+
)
|
|
173
|
+
_async_session: sqlalchemy.ext.asyncio.AsyncSession = PrivateAttr()
|
|
173
174
|
_is_initialized: bool = PrivateAttr(default=False)
|
|
174
175
|
|
|
175
176
|
def __init__(
|
|
176
177
|
self,
|
|
177
|
-
connection_string: Union[str, sqlalchemy.engine.URL],
|
|
178
|
-
async_connection_string: Union[str, sqlalchemy.engine.URL],
|
|
179
|
-
table_name: str,
|
|
180
|
-
schema_name: str,
|
|
178
|
+
connection_string: Optional[Union[str, sqlalchemy.engine.URL]] = None,
|
|
179
|
+
async_connection_string: Optional[Union[str, sqlalchemy.engine.URL]] = None,
|
|
180
|
+
table_name: Optional[str] = None,
|
|
181
|
+
schema_name: Optional[str] = None,
|
|
181
182
|
hybrid_search: bool = False,
|
|
182
183
|
text_search_config: str = "english",
|
|
183
184
|
embed_dim: int = 1536,
|
|
@@ -189,6 +190,8 @@ class PGVectorStore(BasePydanticVectorStore):
|
|
|
189
190
|
create_engine_kwargs: Optional[Dict[str, Any]] = None,
|
|
190
191
|
initialization_fail_on_error: bool = False,
|
|
191
192
|
use_halfvec: bool = False,
|
|
193
|
+
engine: Optional[sqlalchemy.engine.Engine] = None,
|
|
194
|
+
async_engine: Optional[sqlalchemy.ext.asyncio.AsyncEngine] = None,
|
|
192
195
|
) -> None:
|
|
193
196
|
"""Constructor.
|
|
194
197
|
|
|
@@ -209,9 +212,11 @@ class PGVectorStore(BasePydanticVectorStore):
|
|
|
209
212
|
which turns off HNSW search.
|
|
210
213
|
create_engine_kwargs (Optional[Dict[str, Any]], optional): Engine parameters to pass to create_engine. Defaults to None.
|
|
211
214
|
use_halfvec (bool, optional): If `True`, use half-precision vectors. Defaults to False.
|
|
215
|
+
engine (Optional[sqlalchemy.engine.Engine], optional): SQLAlchemy engine instance to use. Defaults to None.
|
|
216
|
+
async_engine (Optional[sqlalchemy.ext.asyncio.AsyncEngine], optional): SQLAlchemy async engine instance to use. Defaults to None.
|
|
212
217
|
"""
|
|
213
|
-
table_name = table_name.lower()
|
|
214
|
-
schema_name = schema_name.lower()
|
|
218
|
+
table_name = table_name.lower() if table_name else "llamaindex"
|
|
219
|
+
schema_name = schema_name.lower() if schema_name else "public"
|
|
215
220
|
|
|
216
221
|
if hybrid_search and text_search_config is None:
|
|
217
222
|
raise ValueError(
|
|
@@ -253,14 +258,26 @@ class PGVectorStore(BasePydanticVectorStore):
|
|
|
253
258
|
use_halfvec=use_halfvec,
|
|
254
259
|
)
|
|
255
260
|
|
|
261
|
+
# both engine and async_engine must be provided, or both must be None
|
|
262
|
+
if engine is not None and async_engine is not None:
|
|
263
|
+
self._engine = engine
|
|
264
|
+
self._async_engine = async_engine
|
|
265
|
+
elif engine is None and async_engine is None:
|
|
266
|
+
pass
|
|
267
|
+
else:
|
|
268
|
+
raise ValueError(
|
|
269
|
+
"Both engine and async_engine must be provided, or both must be None"
|
|
270
|
+
)
|
|
271
|
+
|
|
256
272
|
async def close(self) -> None:
|
|
257
273
|
if not self._is_initialized:
|
|
258
274
|
return
|
|
259
275
|
|
|
260
276
|
self._session.close_all()
|
|
261
|
-
self._engine
|
|
262
|
-
|
|
263
|
-
|
|
277
|
+
if self._engine:
|
|
278
|
+
self._engine.dispose()
|
|
279
|
+
if self._async_engine:
|
|
280
|
+
await self._async_engine.dispose()
|
|
264
281
|
|
|
265
282
|
@classmethod
|
|
266
283
|
def class_name(cls) -> str:
|
|
@@ -352,12 +369,12 @@ class PGVectorStore(BasePydanticVectorStore):
|
|
|
352
369
|
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
|
353
370
|
from sqlalchemy.orm import sessionmaker
|
|
354
371
|
|
|
355
|
-
self._engine = create_engine(
|
|
372
|
+
self._engine = self._engine or create_engine(
|
|
356
373
|
self.connection_string, echo=self.debug, **self.create_engine_kwargs
|
|
357
374
|
)
|
|
358
375
|
self._session = sessionmaker(self._engine)
|
|
359
376
|
|
|
360
|
-
self._async_engine = create_async_engine(
|
|
377
|
+
self._async_engine = self._async_engine or create_async_engine(
|
|
361
378
|
self.async_connection_string, **self.create_engine_kwargs
|
|
362
379
|
)
|
|
363
380
|
self._async_session = sessionmaker(self._async_engine, class_=AsyncSession) # type: ignore
|
{llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/pyproject.toml
RENAMED
|
@@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
|
|
|
27
27
|
license = "MIT"
|
|
28
28
|
name = "llama-index-vector-stores-postgres"
|
|
29
29
|
readme = "README.md"
|
|
30
|
-
version = "0.
|
|
30
|
+
version = "0.5.0"
|
|
31
31
|
|
|
32
32
|
[tool.poetry.dependencies]
|
|
33
33
|
python = ">=3.9,<4.0"
|
|
@@ -47,6 +47,7 @@ mypy = "0.991"
|
|
|
47
47
|
pre-commit = "3.2.0"
|
|
48
48
|
pylint = "2.15.10"
|
|
49
49
|
pytest = "7.2.1"
|
|
50
|
+
pytest-asyncio = "0.21.0"
|
|
50
51
|
pytest-mock = "3.11.1"
|
|
51
52
|
ruff = "0.0.292"
|
|
52
53
|
tree-sitter-languages = "^1.8.0"
|
{llama_index_vector_stores_postgres-0.4.2 → llama_index_vector_stores_postgres-0.5.0}/README.md
RENAMED
|
File without changes
|
|
File without changes
|