""" Start LightRAG server with local-only configuration Uses valid configuration options to avoid API dependencies """ 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({ # Use local embeddings "EMBEDDING_BINDING": "ollama", # Disable reranking "RERANK_BINDING": "null", # Use Ollama for LLM (local) "LLM_BINDING": "ollama", # Set summary tokens to 0 to minimize 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", "ollama", # Use local Ollama "--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: ollama (local)") print(" - Embedding Binding: ollama (local)") print(" - Rerank Binding: null (disabled)") print(" - Entity Extraction: disabled (summary tokens: 0)") 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 upload_test_document(): """Upload test document to the local server""" import requests url = "http://localhost:3017" headers = {"X-API-Key": "jleu1212"} test_file = "test.docx" if not os.path.exists(test_file): print(f"โŒ Test file {test_file} not found") return False try: with open(test_file, 'rb') as f: files = {'file': (test_file, f, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')} response = requests.post( f"{url}/documents/upload", files=files, headers=headers, timeout=30 ) if response.status_code == 200: print("โœ… Document uploaded successfully") result = response.json() print(f" Upload result: {result}") return True else: print(f"โŒ Upload failed: {response.status_code} - {response.text}") return False except Exception as e: print(f"โŒ Upload error: {e}") return False def main(): """Main function""" print("=" * 60) print("๐Ÿ”ง LIGHTRAG LOCAL SERVER SETUP") print("=" * 60) # 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!") # Upload test document print("\n๐Ÿ“ค Uploading test document...") if upload_test_document(): print("\nโœ… Document processing workflow completed!") print("๐Ÿ’ก You can now check the server logs for document processing details") print(" and verify that bee classification appears in the processed content.") else: print("\nโš ๏ธ Document upload failed, but server is running") print("\n๐Ÿ“ Next steps:") print(" 1. Check server logs for document processing details") print(" 2. Verify bee classification appears in processed content") print(" 3. Access Web UI at http://localhost:3017/webui") # 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()