langchain[patch]: Migrate graphs to use optional community imports (#21100)

Migrate graphs to use optional community imports.
This commit is contained in:
Eugene Yurtsev 2024-04-30 16:24:06 -04:00 committed by GitHub
parent 8658d52587
commit 3853fe9f64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 311 additions and 38 deletions

View File

@ -1,13 +1,45 @@
"""**Graphs** provide a natural language interface to graph databases."""
from typing import Any
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
importer = create_importer(__package__, fallback_module="langchain_community.graphs")
if TYPE_CHECKING:
from langchain_community.graphs import (
ArangoGraph,
FalkorDBGraph,
HugeGraph,
KuzuGraph,
MemgraphGraph,
NebulaGraph,
Neo4jGraph,
NeptuneGraph,
NetworkxEntityGraph,
RdfGraph,
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"MemgraphGraph": "langchain_community.graphs",
"NetworkxEntityGraph": "langchain_community.graphs",
"Neo4jGraph": "langchain_community.graphs",
"NebulaGraph": "langchain_community.graphs",
"NeptuneGraph": "langchain_community.graphs",
"KuzuGraph": "langchain_community.graphs",
"HugeGraph": "langchain_community.graphs",
"RdfGraph": "langchain_community.graphs",
"ArangoGraph": "langchain_community.graphs",
"FalkorDBGraph": "langchain_community.graphs",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
return importer(name)
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [

View File

@ -1,4 +1,26 @@
from langchain_community.graphs.arangodb_graph import ArangoGraph, get_arangodb_client
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import ArangoGraph
from langchain_community.graphs.arangodb_graph import get_arangodb_client
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"ArangoGraph": "langchain_community.graphs",
"get_arangodb_client": "langchain_community.graphs.arangodb_graph",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"ArangoGraph",

View File

@ -1,6 +1,22 @@
from langchain_community.graphs.falkordb_graph import (
FalkorDBGraph,
)
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import FalkorDBGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"FalkorDBGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"FalkorDBGraph",

View File

@ -1,3 +1,33 @@
from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship
from typing import TYPE_CHECKING, Any
__all__ = ["Node", "Relationship", "GraphDocument"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs.graph_document import (
GraphDocument,
Node,
Relationship,
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"Node": "langchain_community.graphs.graph_document",
"Relationship": "langchain_community.graphs.graph_document",
"GraphDocument": "langchain_community.graphs.graph_document",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"Node",
"Relationship",
"GraphDocument",
]

View File

@ -1,3 +1,23 @@
from langchain_community.graphs.graph_store import GraphStore
from typing import TYPE_CHECKING, Any
__all__ = ["GraphStore"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs.graph_store import GraphStore
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"GraphStore": "langchain_community.graphs.graph_store"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"GraphStore",
]

View File

@ -1,3 +1,23 @@
from langchain_community.graphs.hugegraph import HugeGraph
from typing import TYPE_CHECKING, Any
__all__ = ["HugeGraph"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import HugeGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"HugeGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"HugeGraph",
]

View File

@ -1,3 +1,23 @@
from langchain_community.graphs.kuzu_graph import KuzuGraph
from typing import TYPE_CHECKING, Any
__all__ = ["KuzuGraph"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import KuzuGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"KuzuGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"KuzuGraph",
]

View File

@ -1,5 +1,23 @@
from langchain_community.graphs.memgraph_graph import (
MemgraphGraph,
)
from typing import TYPE_CHECKING, Any
__all__ = ["MemgraphGraph"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import MemgraphGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"MemgraphGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"MemgraphGraph",
]

View File

@ -1,3 +1,23 @@
from langchain_community.graphs.nebula_graph import NebulaGraph
from typing import TYPE_CHECKING, Any
__all__ = ["NebulaGraph"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import NebulaGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"NebulaGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"NebulaGraph",
]

View File

@ -1,5 +1,23 @@
from langchain_community.graphs.neo4j_graph import (
Neo4jGraph,
)
from typing import TYPE_CHECKING, Any
__all__ = ["Neo4jGraph"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import Neo4jGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"Neo4jGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"Neo4jGraph",
]

View File

@ -1,3 +1,23 @@
from langchain_community.graphs.neptune_graph import NeptuneGraph
from typing import TYPE_CHECKING, Any
__all__ = ["NeptuneGraph"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import NeptuneGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"NeptuneGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"NeptuneGraph",
]

View File

@ -1,13 +1,34 @@
from langchain_community.graphs.networkx_graph import (
KG_TRIPLE_DELIMITER,
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import NetworkxEntityGraph
from langchain_community.graphs.networkx_graph import (
KnowledgeTriple,
NetworkxEntityGraph,
get_entities,
parse_triples,
)
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"KnowledgeTriple": "langchain_community.graphs.networkx_graph",
"parse_triples": "langchain_community.graphs.networkx_graph",
"get_entities": "langchain_community.graphs.networkx_graph",
"NetworkxEntityGraph": "langchain_community.graphs",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"KG_TRIPLE_DELIMITER",
"KnowledgeTriple",
"parse_triples",
"get_entities",

View File

@ -1,6 +1,22 @@
from langchain_community.graphs.rdf_graph import (
RdfGraph,
)
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.graphs import RdfGraph
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"RdfGraph": "langchain_community.graphs"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"RdfGraph",