diff --git a/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/llama_index/graph_stores/neo4j/neo4j_property_graph.py b/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/llama_index/graph_stores/neo4j/neo4j_property_graph.py index 30b00da042bd4..b8f64dc69c20c 100644 --- a/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/llama_index/graph_stores/neo4j/neo4j_property_graph.py +++ b/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/llama_index/graph_stores/neo4j/neo4j_property_graph.py @@ -151,6 +151,7 @@ def __init__( refresh_schema: bool = True, sanitize_query_output: bool = True, enhanced_schema: bool = False, + create_indexes: bool = True, **neo4j_kwargs: Any, ) -> None: self.sanitize_query_output = sanitize_query_output @@ -167,22 +168,24 @@ def __init__( self.structured_schema = {} if refresh_schema: self.refresh_schema() - # Create index for faster imports and retrieval - self.structured_query( - f"""CREATE CONSTRAINT IF NOT EXISTS FOR (n:`{BASE_NODE_LABEL}`) - REQUIRE n.id IS UNIQUE;""" - ) - self.structured_query( - f"""CREATE CONSTRAINT IF NOT EXISTS FOR (n:`{BASE_ENTITY_LABEL}`) - REQUIRE n.id IS UNIQUE;""" - ) # Verify version to check if we can use vector index self.verify_version() - if self._supports_vector_index: + # Create index for faster imports and retrieval + if create_indexes: self.structured_query( - f"CREATE VECTOR INDEX {VECTOR_INDEX_NAME} IF NOT EXISTS " - "FOR (m:__Entity__) ON m.embedding" + f"""CREATE CONSTRAINT IF NOT EXISTS FOR (n:`{BASE_NODE_LABEL}`) + REQUIRE n.id IS UNIQUE;""" ) + self.structured_query( + f"""CREATE CONSTRAINT IF NOT EXISTS FOR (n:`{BASE_ENTITY_LABEL}`) + REQUIRE n.id IS UNIQUE;""" + ) + + if self._supports_vector_index: + self.structured_query( + f"CREATE VECTOR INDEX {VECTOR_INDEX_NAME} IF NOT EXISTS " + "FOR (m:__Entity__) ON m.embedding" + ) @property def client(self): diff --git a/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/pyproject.toml b/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/pyproject.toml index ffce23eee7ca4..66e19715407db 100644 --- a/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/pyproject.toml +++ b/llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/pyproject.toml @@ -28,7 +28,7 @@ exclude = ["**/BUILD"] license = "MIT" name = "llama-index-graph-stores-neo4j" readme = "README.md" -version = "0.4.0" +version = "0.4.1" [tool.poetry.dependencies] python = ">=3.9,<4.0"