""" Start LightRAG server with local-only configuration Avoids external API dependencies for testing document processing """ import os import sys import subprocess import time def start_local_server(): """Start LightRAG server with local-only configuration""" # Environment variables for local-only operation env = os.environ.copy() env.update({ # Disable entity extraction to avoid API calls "OPTIMIZE_ENTITY_EXTRACTION": "false", "ENABLE_ENTITY_EXTRACTION": "false", # Use local embeddings "EMBEDDING_BINDING": "ollama", # Disable reranking "RERANK_BINDING": "null", # Disable LLM for search "LLM_BINDING": "null", # Set summary tokens to 0 to disable entity extraction "SUMMARY_MAX_TOKENS": "0" }) command = [ sys.executable, "-m", "lightrag.api.lightrag_server", "--port", "3017", # Use a different port "--working-dir", "rag_storage", "--input-dir", "inputs", "--key", "jleu1212", "--auto-scan-at-startup", "--llm-binding", "null", # Disable LLM "--embedding-binding", "ollama", # Use local embeddings "--rerank-binding", "null", # Disable reranking "--summary-max-tokens", "0" # Disable entity extraction ] print("๐Ÿš€ Starting LightRAG server with local-only configuration...") print(f"๐Ÿ“ก Command: {' '.join(command)}") print("โš™๏ธ Configuration:") print(" - LLM Binding: null (disabled)") print(" - Embedding Binding: ollama (local)") print(" - Rerank Binding: null (disabled)") print(" - Entity Extraction: disabled") print(" - Port: 3017") try: process = subprocess.Popen( command, env=env, cwd="LightRAG-main", stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) print("โณ Server starting...") # Wait a bit for server to start time.sleep(10) # Check if process is still running if process.poll() is None: print("โœ… Server started successfully on port 3017") return process else: stdout, stderr = process.communicate() print(f"โŒ Server failed to start:") print(f"STDOUT: {stdout}") print(f"STDERR: {stderr}") return None except Exception as e: print(f"โŒ Error starting server: {e}") return None def test_local_server(): """Test the local server""" import requests url = "http://localhost:3017" headers = {"X-API-Key": "jleu1212"} try: # Test health endpoint response = requests.get(f"{url}/", headers=headers, timeout=10) if response.status_code == 200: print("โœ… Server health check passed") return True else: print(f"โŒ Server health check failed: {response.status_code}") return False except Exception as e: print(f"โŒ Server test error: {e}") return False def main(): """Main function""" print("=" * 60) print("๐Ÿ”ง LIGHTRAG LOCAL SERVER SETUP") print("=" * 60) # Stop any existing servers on port 3017 try: subprocess.run(["netstat", "-ano"], capture_output=True, text=True) print("๐Ÿ›‘ Checking for existing servers on port 3017...") except: pass # Start the server process = start_local_server() if process: print("\n" + "=" * 60) print("๐Ÿงช TESTING LOCAL SERVER") print("=" * 60) # Test the server if test_local_server(): print("\n๐ŸŽ‰ Local server is running successfully!") print("๐Ÿ’ก You can now test the document processing workflow") print(" without external API dependencies.") print("\n๐Ÿ“ Next steps:") print(" 1. Upload test.docx to http://localhost:3017/webui") print(" 2. Check server logs for document processing details") print(" 3. Verify bee classification appears in processed content") # Keep the process running try: print("\n๐Ÿ”„ Server is running. Press Ctrl+C to stop.") process.wait() except KeyboardInterrupt: print("\n๐Ÿ›‘ Stopping server...") process.terminate() else: print("\nโŒ Server test failed") process.terminate() else: print("\nโŒ Failed to start server") if __name__ == "__main__": main()