langchain-postgres 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.whl

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.
@@ -1,6 +1,7 @@
1
1
  from importlib import metadata
2
2
 
3
3
  from langchain_postgres.chat_message_histories import PostgresChatMessageHistory
4
+ from langchain_postgres.translator import PGVectorTranslator
4
5
  from langchain_postgres.vectorstores import PGVector
5
6
 
6
7
  try:
@@ -13,4 +14,5 @@ __all__ = [
13
14
  "__version__",
14
15
  "PostgresChatMessageHistory",
15
16
  "PGVector",
17
+ "PGVectorTranslator",
16
18
  ]
@@ -0,0 +1,52 @@
1
+ from typing import Dict, Tuple, Union
2
+
3
+ from langchain_core.structured_query import (
4
+ Comparator,
5
+ Comparison,
6
+ Operation,
7
+ Operator,
8
+ StructuredQuery,
9
+ Visitor,
10
+ )
11
+
12
+
13
+ class PGVectorTranslator(Visitor):
14
+ """Translate `PGVector` internal query language elements to valid filters."""
15
+
16
+ allowed_operators = [Operator.AND, Operator.OR]
17
+ """Subset of allowed logical operators."""
18
+ allowed_comparators = [
19
+ Comparator.EQ,
20
+ Comparator.NE,
21
+ Comparator.GT,
22
+ Comparator.LT,
23
+ Comparator.IN,
24
+ Comparator.NIN,
25
+ Comparator.CONTAIN,
26
+ Comparator.LIKE,
27
+ ]
28
+ """Subset of allowed logical comparators."""
29
+
30
+ def _format_func(self, func: Union[Operator, Comparator]) -> str:
31
+ self._validate_func(func)
32
+ return f"${func.value}"
33
+
34
+ def visit_operation(self, operation: Operation) -> Dict:
35
+ args = [arg.accept(self) for arg in operation.arguments]
36
+ return {self._format_func(operation.operator): args}
37
+
38
+ def visit_comparison(self, comparison: Comparison) -> Dict:
39
+ return {
40
+ comparison.attribute: {
41
+ self._format_func(comparison.comparator): comparison.value
42
+ }
43
+ }
44
+
45
+ def visit_structured_query(
46
+ self, structured_query: StructuredQuery
47
+ ) -> Tuple[str, dict]:
48
+ if structured_query.filter is None:
49
+ kwargs = {}
50
+ else:
51
+ kwargs = {"filter": structured_query.filter.accept(self)}
52
+ return structured_query.query, kwargs
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain-postgres
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: An integration package connecting Postgres and LangChain
5
5
  Home-page: https://github.com/langchain-ai/langchain-postgres
6
6
  License: MIT
7
- Requires-Python: >=3.9,<4.0
7
+ Requires-Python: >=3.8.1,<4.0.0
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.9
@@ -0,0 +1,10 @@
1
+ langchain_postgres/__init__.py,sha256=iH8JoksQ4c_36xRmbi9WoYzfBRETTH8r8PPDD_wrRt8,502
2
+ langchain_postgres/_utils.py,sha256=Johm50HEgA4qScLDaSDIfJfF3DygjA5KTBtNeVcD63I,2914
3
+ langchain_postgres/chat_message_histories.py,sha256=gh6hjBlrJ5GSo5kePQdh3VhiUYoWWdP37GXtZ1e25a4,14033
4
+ langchain_postgres/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ langchain_postgres/translator.py,sha256=6cTS2RJUodMUdsurJM-f-vgPXl6Ad6bfMo8ECuh5Jr4,1524
6
+ langchain_postgres/vectorstores.py,sha256=hV-J7tGp-s6ZiTLSi0uLnswVG_Gb8E6ZVZE0nzE2e2g,81052
7
+ langchain_postgres-0.0.9.dist-info/LICENSE,sha256=2btS8uNUDWD_UNjw9ba6ZJt_00aUjEw9CGyK-xIHY8c,1072
8
+ langchain_postgres-0.0.9.dist-info/METADATA,sha256=3Q22-FLRwCPRu9g4mMcSqKdgeqmA56EHnosAf-0bi5M,4019
9
+ langchain_postgres-0.0.9.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
10
+ langchain_postgres-0.0.9.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- langchain_postgres/__init__.py,sha256=9rXsSowLZpH_dqyWJUhpTVwviQ02wLTZj_kPi6OOfcc,415
2
- langchain_postgres/_utils.py,sha256=Johm50HEgA4qScLDaSDIfJfF3DygjA5KTBtNeVcD63I,2914
3
- langchain_postgres/chat_message_histories.py,sha256=gh6hjBlrJ5GSo5kePQdh3VhiUYoWWdP37GXtZ1e25a4,14033
4
- langchain_postgres/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- langchain_postgres/vectorstores.py,sha256=hV-J7tGp-s6ZiTLSi0uLnswVG_Gb8E6ZVZE0nzE2e2g,81052
6
- langchain_postgres-0.0.7.dist-info/LICENSE,sha256=2btS8uNUDWD_UNjw9ba6ZJt_00aUjEw9CGyK-xIHY8c,1072
7
- langchain_postgres-0.0.7.dist-info/METADATA,sha256=xG_riG4igA4C6m7zIy6kim2W9zN85Tmb45CzSqLKCOw,4015
8
- langchain_postgres-0.0.7.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
9
- langchain_postgres-0.0.7.dist-info/RECORD,,