diff --git a/libs/neo4j/README.md b/libs/neo4j/README.md index df20dd2..1ceae6b 100644 --- a/libs/neo4j/README.md +++ b/libs/neo4j/README.md @@ -16,7 +16,7 @@ The `Neo4jGraph` class is a wrapper around Neo4j's Python driver. It provides a simple interface for interacting with a Neo4j database. ```python -from langchain_neo4j import Neo4jGraph +from langchain_neo4j.graphs import Neo4jGraph graph = Neo4jGraph(url="bolt://localhost:7687", username="neo4j", password="password") graph.query("MATCH (n) RETURN n LIMIT 1;") @@ -28,7 +28,7 @@ The `Neo4jChatMessageHistory` class is used to store chat message history in a N It stores messages as nodes and creates relationships between them, allowing for easy querying of the conversation history. ```python -from langchain_neo4j import Neo4jChatMessageHistory +from langchain_neo4j.chat_message_histories import Neo4jChatMessageHistory history = Neo4jChatMessageHistory( url="bolt://localhost:7687", @@ -50,7 +50,7 @@ It enables you to create new vector indexes, add vectors to existing indexes, an from langchain.docstore.document import Document from langchain_openai import OpenAIEmbeddings -from langchain_neo4j import Neo4jVector +from langchain_neo4j.vectorstores import Neo4jVector # Create a vector store from some documents and embeddings docs = [ @@ -83,10 +83,10 @@ It uses an LLM and the database's schema to translate a user's question into a C The resulting data is then sent along with the user's question to the LLM to generate a natural language response. ```python +from langchain_neo4j.chains import GraphCypherQAChain +from langchain_neo4j.graphs import Neo4jGraph from langchain_openai import ChatOpenAI -from langchain_neo4j import GraphCypherQAChain, Neo4jGraph - llm = ChatOpenAI( temperature=0, api_key="sk-...", # Replace with your OpenAI API key diff --git a/libs/neo4j/langchain_neo4j/__init__.py b/libs/neo4j/langchain_neo4j/__init__.py index fffeccf..b72404b 100644 --- a/libs/neo4j/langchain_neo4j/__init__.py +++ b/libs/neo4j/langchain_neo4j/__init__.py @@ -1,10 +1,5 @@ from importlib import metadata -from langchain_neo4j.chains.graph_qa.cypher import GraphCypherQAChain -from langchain_neo4j.chat_message_histories.neo4j import Neo4jChatMessageHistory -from langchain_neo4j.graphs.neo4j_graph import Neo4jGraph -from langchain_neo4j.vectorstores.neo4j_vector import Neo4jVector - try: __version__ = metadata.version(__package__) except metadata.PackageNotFoundError: @@ -13,9 +8,5 @@ del metadata # optional, avoids polluting the results of dir(__package__) __all__ = [ - "GraphCypherQAChain", - "Neo4jChatMessageHistory", - "Neo4jGraph", - "Neo4jVector", "__version__", ] diff --git a/libs/neo4j/langchain_neo4j/chains/__init__.py b/libs/neo4j/langchain_neo4j/chains/__init__.py index e69de29..4c5140b 100644 --- a/libs/neo4j/langchain_neo4j/chains/__init__.py +++ b/libs/neo4j/langchain_neo4j/chains/__init__.py @@ -0,0 +1,3 @@ +from langchain_neo4j.chains.graph_qa.cypher import GraphCypherQAChain + +__all__ = ["GraphCypherQAChain"] diff --git a/libs/neo4j/langchain_neo4j/chat_message_histories/__init__.py b/libs/neo4j/langchain_neo4j/chat_message_histories/__init__.py index e69de29..f48a626 100644 --- a/libs/neo4j/langchain_neo4j/chat_message_histories/__init__.py +++ b/libs/neo4j/langchain_neo4j/chat_message_histories/__init__.py @@ -0,0 +1,3 @@ +from langchain_neo4j.chat_message_histories.neo4j import Neo4jChatMessageHistory + +__all__ = ["Neo4jChatMessageHistory"] diff --git a/libs/neo4j/langchain_neo4j/graphs/__init__.py b/libs/neo4j/langchain_neo4j/graphs/__init__.py index e69de29..46e5ddf 100644 --- a/libs/neo4j/langchain_neo4j/graphs/__init__.py +++ b/libs/neo4j/langchain_neo4j/graphs/__init__.py @@ -0,0 +1,3 @@ +from langchain_neo4j.graphs.neo4j_graph import Neo4jGraph + +__all__ = ["Neo4jGraph"] diff --git a/libs/neo4j/langchain_neo4j/query_constructors/__init__.py b/libs/neo4j/langchain_neo4j/query_constructors/__init__.py index e69de29..fd4dd3a 100644 --- a/libs/neo4j/langchain_neo4j/query_constructors/__init__.py +++ b/libs/neo4j/langchain_neo4j/query_constructors/__init__.py @@ -0,0 +1,3 @@ +from langchain_neo4j.query_constructors.neo4j import Neo4jTranslator + +__all__ = ["Neo4jTranslator"] diff --git a/libs/neo4j/langchain_neo4j/vectorstores/__init__.py b/libs/neo4j/langchain_neo4j/vectorstores/__init__.py index e69de29..86b1736 100644 --- a/libs/neo4j/langchain_neo4j/vectorstores/__init__.py +++ b/libs/neo4j/langchain_neo4j/vectorstores/__init__.py @@ -0,0 +1,3 @@ +from langchain_neo4j.vectorstores.neo4j_vector import Neo4jVector + +__all__ = ["Neo4jVector"] diff --git a/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py b/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py index 863de6d..3dd7ddf 100644 --- a/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py +++ b/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py @@ -462,7 +462,7 @@ class Neo4jVector(VectorStore): Example: .. code-block:: python - from langchain_neo4j import Neo4jVector + from langchain_neo4j.vectorstores import Neo4jVector from langchain_community.embeddings.openai import OpenAIEmbeddings url="bolt://localhost:7687" @@ -477,7 +477,6 @@ class Neo4jVector(VectorStore): password=password, ) - """ def __init__( @@ -1233,13 +1232,13 @@ def from_embeddings( Example: .. code-block:: python - from langchain_neo4j import Neo4jVector from langchain_community.embeddings import OpenAIEmbeddings + from langchain_neo4j.vectorstores import Neo4jVector + embeddings = OpenAIEmbeddings() text_embeddings = embeddings.embed_documents(texts) text_embedding_pairs = list(zip(texts, text_embeddings)) - vectorstore = Neo4jVector.from_embeddings( - text_embedding_pairs, embeddings) + vectorstore = Neo4jVector.from_embeddings(text_embedding_pairs, embeddings) """ texts = [t[0] for t in text_embeddings] embeddings = [t[1] for t in text_embeddings] diff --git a/libs/neo4j/tests/integration_tests/graphs/test_neo4j.py b/libs/neo4j/tests/integration_tests/graphs/test_neo4j.py index a02cffa..b59e1a9 100644 --- a/libs/neo4j/tests/integration_tests/graphs/test_neo4j.py +++ b/libs/neo4j/tests/integration_tests/graphs/test_neo4j.py @@ -3,9 +3,9 @@ from langchain_community.graphs.graph_document import GraphDocument, Node, Relationship from langchain_core.documents import Document -from langchain_neo4j import Neo4jGraph from langchain_neo4j.graphs.neo4j_graph import ( BASE_ENTITY_LABEL, + Neo4jGraph, node_properties_query, rel_properties_query, rel_query, diff --git a/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py b/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py index f9c92c2..333cf4b 100644 --- a/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py +++ b/libs/neo4j/tests/integration_tests/vectorstores/test_neo4jvector.py @@ -8,7 +8,7 @@ from langchain_core.documents import Document from yaml import safe_load -from langchain_neo4j import Neo4jGraph +from langchain_neo4j.graphs.neo4j_graph import Neo4jGraph from langchain_neo4j.vectorstores.neo4j_vector import ( Neo4jVector, SearchType, diff --git a/libs/neo4j/tests/unit_tests/test_imports.py b/libs/neo4j/tests/unit_tests/test_imports.py index 571e2d5..3e498f2 100644 --- a/libs/neo4j/tests/unit_tests/test_imports.py +++ b/libs/neo4j/tests/unit_tests/test_imports.py @@ -1,13 +1,52 @@ -from langchain_neo4j import __all__ +def test_all_imports() -> None: + from langchain_neo4j import __all__ -EXPECTED_ALL = [ - "GraphCypherQAChain", - "Neo4jChatMessageHistory", - "Neo4jGraph", - "Neo4jVector", - "__version__", -] + EXPECTED_ALL = [ + "__version__", + ] + assert sorted(EXPECTED_ALL) == sorted(__all__) -def test_all_imports() -> None: +def test_chains_imports() -> None: + from langchain_neo4j.chains import __all__ + + EXPECTED_ALL = [ + "GraphCypherQAChain", + ] + assert sorted(EXPECTED_ALL) == sorted(__all__) + + +def test_chat_message_histories_imports() -> None: + from langchain_neo4j.chat_message_histories import __all__ + + EXPECTED_ALL = [ + "Neo4jChatMessageHistory", + ] + assert sorted(EXPECTED_ALL) == sorted(__all__) + + +def test_graphs_imports() -> None: + from langchain_neo4j.graphs import __all__ + + EXPECTED_ALL = [ + "Neo4jGraph", + ] + assert sorted(EXPECTED_ALL) == sorted(__all__) + + +def test_query_constructors_imports() -> None: + from langchain_neo4j.query_constructors import __all__ + + EXPECTED_ALL = [ + "Neo4jTranslator", + ] + assert sorted(EXPECTED_ALL) == sorted(__all__) + + +def test_vectorstores_imports() -> None: + from langchain_neo4j.vectorstores import __all__ + + EXPECTED_ALL = [ + "Neo4jVector", + ] assert sorted(EXPECTED_ALL) == sorted(__all__)