langchain-postgres 0.0.7__tar.gz → 0.0.9__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.
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/PKG-INFO +2 -2
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/langchain_postgres/__init__.py +2 -0
- langchain_postgres-0.0.9/langchain_postgres/translator.py +52 -0
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/pyproject.toml +2 -2
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/LICENSE +0 -0
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/README.md +0 -0
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/langchain_postgres/_utils.py +0 -0
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/langchain_postgres/chat_message_histories.py +0 -0
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/langchain_postgres/py.typed +0 -0
- {langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/langchain_postgres/vectorstores.py +0 -0
@@ -1,10 +1,10 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: langchain-postgres
|
3
|
-
Version: 0.0.
|
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.
|
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
|
@@ -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,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "langchain-postgres"
|
3
|
-
version = "0.0.
|
3
|
+
version = "0.0.9"
|
4
4
|
description = "An integration package connecting Postgres and LangChain"
|
5
5
|
authors = []
|
6
6
|
readme = "README.md"
|
@@ -11,7 +11,7 @@ license = "MIT"
|
|
11
11
|
"Source Code" = "https://github.com/langchain-ai/langchain-postgres/tree/master/langchain_postgres"
|
12
12
|
|
13
13
|
[tool.poetry.dependencies]
|
14
|
-
python = "^3.
|
14
|
+
python = "^3.8.1"
|
15
15
|
langchain-core = ">=0.1.50,<0.3"
|
16
16
|
psycopg = "^3"
|
17
17
|
psycopg-pool = "^3.2.1"
|
File without changes
|
File without changes
|
File without changes
|
{langchain_postgres-0.0.7 → langchain_postgres-0.0.9}/langchain_postgres/chat_message_histories.py
RENAMED
File without changes
|
File without changes
|
File without changes
|