Skip to content

[Bug]: Wrong .env File Detection Path in LightRAG API #1218

@Starfallan

Description

@Starfallan

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

Incorrect .env file detection path in #1195

The check_env_file() function in utils_api.py incorrectly checks for the .env file in Working Directory instead of the API directory

This creates following issues:
Working directory constraint that requires users to start the server from a specific location

Current Behavior

  1. .env detection:
def check_env_file():
    """
    Check if .env file exists and handle user confirmation if needed.
    Returns True if should continue, False if should exit.
    """
    if not os.path.exists(".env"):
        warning_msg = (
            "Warning: .env file not found. Some features may not work properly."
        )
        ASCIIColors.yellow(warning_msg)

        # Check if running in interactive terminal
        if sys.stdin.isatty():
            response = input("Do you want to continue? (yes/no): ")
            if response.lower() != "yes":
                ASCIIColors.red("Server startup cancelled")
                return False
    return True

Suggested Solutions

  1. Update environment file detection (just a example):
def check_env_file():
    """
    Check if .env file exists and handle user confirmation if needed.
    Returns True if should continue, False if should exit.
    """
    # Get the absolute path of the current script's directory
    current_dir = os.path.dirname(os.path.abspath(__file__))
    env_path = os.path.join(current_dir, '.env')
    
    if not os.path.exists(env_path):
        # Add debug information
        warning_msg = (
            f"Warning: .env file not found at {env_path}. "
            "Some features may not work properly."
        )
        ASCIIColors.yellow(warning_msg)
        
        # Check if running in an interactive terminal
        if sys.stdin.isatty():
            response = input("Do you want to continue? (yes/no): ")
            if response.lower() != "yes":
                ASCIIColors.red("Server startup cancelled")
                return False
    else:
        ASCIIColors.green(f"Found .env file at: {env_path}")
    
    return True

Steps to reproduce

No response

Expected Behavior

  1. The server should be able to locate the .env file regardless of the working directory
  2. Users should be able to start the server from any location

LightRAG Config Used

Paste your config here

Logs and screenshots

No response

Additional Information

  • LightRAG Version:
  • Operating System:
  • Python Version:
  • Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions