diff --git a/backend/app/database/falkor/code-graph-backend/api/graph.py b/backend/app/database/falkor/code-graph-backend/api/graph.py index 7c91405b..2a134ef9 100644 --- a/backend/app/database/falkor/code-graph-backend/api/graph.py +++ b/backend/app/database/falkor/code-graph-backend/api/graph.py @@ -46,20 +46,20 @@ def __init__(self, name: str) -> None: # Initialize the backlog as disabled by default self.backlog = None - # create indicies + self._safe_create_index(self.g.create_node_range_index, "File", "name", "ext") + self._safe_create_index(self.g.create_node_fulltext_index, "Searchable", "name") - # index File path, name and ext fields + def _safe_create_index(self, func, label, *args): try: - self.g.create_node_range_index("File", "name", "ext") - except Exception: - pass + func(label, *args) + logging.debug(f"Successfully created/verified index for '{label}'.") + except Exception as e: + if "already exists" in str(e).lower(): + logging.info(f"Index for '{label}' already exists.") + else: + logging.error(f"Failed to create index for '{label}': {e}", exc_info=True) - # index Function using full-text search - try: - self.g.create_node_fulltext_index("Searchable", "name") - except Exception: - pass def clone(self, clone: str) -> "Graph": """ diff --git a/backend/config.py b/backend/config.py index dd5caa3d..e94c76d4 100644 --- a/backend/config.py +++ b/backend/config.py @@ -1,4 +1,5 @@ from dotenv import load_dotenv, find_dotenv +import logging import os @@ -12,5 +13,9 @@ GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN") MODEL_NAME = os.getenv("EMBEDDING_MODEL", "BAAI/bge-small-en-v1.5") -MAX_BATCH_SIZE = int(os.getenv("EMBEDDING_MAX_BATCH_SIZE", "32")) +try: + MAX_BATCH_SIZE = int(os.getenv("EMBEDDING_MAX_BATCH_SIZE", "32")) +except ValueError: + logging.warning("Invalid integer for EMBEDDING_MAX_BATCH_SIZE. Defaulting to 32.") + MAX_BATCH_SIZE = 32 EMBEDDING_DEVICE = os.getenv("EMBEDDING_DEVICE", "cpu")