Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your_password_here
NEO4J_DATABASE= # Optional: specify database name (defaults to Neo4j's default database)

# Project Configuration
ROOT_PATH=/Users/pepemanu/Desktop/Trabajo/Blar/Dev/blarify
Expand Down
2 changes: 2 additions & 0 deletions blarify/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def add_arguments(parser: ArgumentParser) -> None:
)
parser.add_argument("--neo4j-username", help="Neo4j username")
parser.add_argument("--neo4j-password", help="Neo4j password")
parser.add_argument("--neo4j-database", help="Neo4j database name (optional, defaults to Neo4j's default database)")

# Graph building options
parser.add_argument(
Expand Down Expand Up @@ -385,6 +386,7 @@ def execute(args: Namespace) -> int:
uri=args.neo4j_uri,
user=args.neo4j_username,
password=args.neo4j_password,
database=args.neo4j_database,
repo_id=repo_id,
entity_id=args.entity_id,
)
Expand Down
10 changes: 6 additions & 4 deletions blarify/repositories/graph_db_manager/neo4j_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ def __init__(
uri: Optional[str] = None,
user: Optional[str] = None,
password: Optional[str] = None,
database: Optional[str] = None,
max_connections: int = 50,
):
uri = uri or os.getenv("NEO4J_URI")
user = user or os.getenv("NEO4J_USERNAME")
password = password or os.getenv("NEO4J_PASSWORD")
self.database = database or os.getenv("NEO4J_DATABASE")

if not uri or not user or not password:
raise ValueError("Missing required Neo4j connection parameters")
Expand Down Expand Up @@ -83,7 +85,7 @@ def create_nodes(self, nodeList: List[Any]):
if self.repo_id is None:
raise ValueError("repo_id is required for creating nodes. Cannot create nodes with entity-wide scope.")

with self.driver.session() as session:
with self.driver.session(database=self.database) as session:
session.execute_write(
self._create_nodes_txn,
nodeList,
Expand All @@ -102,7 +104,7 @@ def create_edges(self, edgesList: List[Any]):
total_edges = len(edgesList)
logger.info(f"Creating {total_edges} edges in batches of {batch_size}")

with self.driver.session() as session:
with self.driver.session(database=self.database) as session:
for i in range(0, total_edges, batch_size):
batch = edgesList[i:i + batch_size]
logger.info(f"Processing edges batch {i // batch_size + 1}/{(total_edges + batch_size - 1) // batch_size} ({i}/{total_edges})")
Expand Down Expand Up @@ -205,7 +207,7 @@ def detatch_delete_nodes_with_path(self, path: str):
if self.repo_id is None:
raise ValueError("repo_id is required for deleting nodes. Cannot delete nodes with entity-wide scope.")

with self.driver.session() as session:
with self.driver.session(database=self.database) as session:
result = session.run(
"""
MATCH (n {path: $path, repoId: $repo_id, entityId: $entity_id})
Expand Down Expand Up @@ -243,7 +245,7 @@ def query(
parameters["entity_id"] = self.entity_id

try:
with self.driver.session() as session:
with self.driver.session(database=self.database) as session:
result = []
if transaction:
result = session.execute_write(
Expand Down
Loading