ParisNeo commited on
Commit
8abe7d4
Β·
1 Parent(s): d09df4c

Fixed linting

Browse files
.env.example CHANGED
@@ -57,4 +57,4 @@ LOG_LEVEL=INFO
57
  # AZURE_OPENAI_ENDPOINT=https://myendpoint.openai.azure.com
58
 
59
  # AZURE_EMBEDDING_DEPLOYMENT=text-embedding-3-large
60
- # AZURE_EMBEDDING_API_VERSION=2023-05-15
 
57
  # AZURE_OPENAI_ENDPOINT=https://myendpoint.openai.azure.com
58
 
59
  # AZURE_EMBEDDING_DEPLOYMENT=text-embedding-3-large
60
+ # AZURE_EMBEDDING_API_VERSION=2023-05-15
docker-compose.yml CHANGED
@@ -19,4 +19,4 @@ services:
19
  - "host.docker.internal:host-gateway"
20
  networks:
21
  lightrag_net:
22
- driver: bridge
 
19
  - "host.docker.internal:host-gateway"
20
  networks:
21
  lightrag_net:
22
+ driver: bridge
docs/DockerDeployment.md CHANGED
@@ -5,7 +5,7 @@ A lightweight Knowledge Graph Retrieval-Augmented Generation system with multipl
5
  ## πŸš€ Installation
6
 
7
  ### Prerequisites
8
- - Python 3.10+
9
  - Git
10
  - Docker (optional for Docker deployment)
11
 
@@ -171,4 +171,4 @@ pip install -r requirements.txt
171
  git pull
172
  .\venv\Scripts\Activate
173
  pip install -r requirements.txt
174
- ```
 
5
  ## πŸš€ Installation
6
 
7
  ### Prerequisites
8
+ - Python 3.10+
9
  - Git
10
  - Docker (optional for Docker deployment)
11
 
 
171
  git pull
172
  .\venv\Scripts\Activate
173
  pip install -r requirements.txt
174
+ ```
docs/LightRagAPI.md CHANGED
@@ -358,4 +358,4 @@ This intelligent caching mechanism:
358
  - Documents already in the database are not re-vectorized
359
  - Only new documents in the input directory will be processed
360
  - This optimization significantly reduces startup time for subsequent runs
361
- - The working directory (`--working-dir`) stores the vectorized documents database
 
358
  - Documents already in the database are not re-vectorized
359
  - Only new documents in the input directory will be processed
360
  - This optimization significantly reduces startup time for subsequent runs
361
+ - The working directory (`--working-dir`) stores the vectorized documents database
lightrag/api/README.md CHANGED
@@ -358,4 +358,4 @@ This intelligent caching mechanism:
358
  - Documents already in the database are not re-vectorized
359
  - Only new documents in the input directory will be processed
360
  - This optimization significantly reduces startup time for subsequent runs
361
- - The working directory (`--working-dir`) stores the vectorized documents database
 
358
  - Documents already in the database are not re-vectorized
359
  - Only new documents in the input directory will be processed
360
  - This optimization significantly reduces startup time for subsequent runs
361
+ - The working directory (`--working-dir`) stores the vectorized documents database
lightrag/api/lightrag_server.py CHANGED
@@ -38,36 +38,38 @@ def get_default_host(binding_type: str) -> str:
38
  binding_type, "http://localhost:11434"
39
  ) # fallback to ollama if unknown
40
 
 
41
  from dotenv import load_dotenv
42
- import os
43
 
44
  def get_env_value(env_key: str, default: Any, value_type: type = str) -> Any:
45
  """
46
  Get value from environment variable with type conversion
47
-
48
  Args:
49
  env_key (str): Environment variable key
50
  default (Any): Default value if env variable is not set
51
  value_type (type): Type to convert the value to
52
-
53
  Returns:
54
  Any: Converted value from environment or default
55
  """
56
  value = os.getenv(env_key)
57
  if value is None:
58
  return default
59
-
60
  if value_type == bool:
61
- return value.lower() in ('true', '1', 'yes')
62
  try:
63
  return value_type(value)
64
  except ValueError:
65
  return default
66
 
 
67
  def display_splash_screen(args: argparse.Namespace) -> None:
68
  """
69
  Display a colorful splash screen showing LightRAG server configuration
70
-
71
  Args:
72
  args: Parsed command line arguments
73
  """
@@ -81,61 +83,61 @@ def display_splash_screen(args: argparse.Namespace) -> None:
81
 
82
  # Server Configuration
83
  ASCIIColors.magenta("\nπŸ“‘ Server Configuration:")
84
- ASCIIColors.white(f" β”œβ”€ Host: ", end="")
85
  ASCIIColors.yellow(f"{args.host}")
86
- ASCIIColors.white(f" β”œβ”€ Port: ", end="")
87
  ASCIIColors.yellow(f"{args.port}")
88
- ASCIIColors.white(f" β”œβ”€ SSL Enabled: ", end="")
89
  ASCIIColors.yellow(f"{args.ssl}")
90
  if args.ssl:
91
- ASCIIColors.white(f" β”œβ”€ SSL Cert: ", end="")
92
  ASCIIColors.yellow(f"{args.ssl_certfile}")
93
- ASCIIColors.white(f" └─ SSL Key: ", end="")
94
  ASCIIColors.yellow(f"{args.ssl_keyfile}")
95
 
96
  # Directory Configuration
97
  ASCIIColors.magenta("\nπŸ“‚ Directory Configuration:")
98
- ASCIIColors.white(f" β”œβ”€ Working Directory: ", end="")
99
  ASCIIColors.yellow(f"{args.working_dir}")
100
- ASCIIColors.white(f" └─ Input Directory: ", end="")
101
  ASCIIColors.yellow(f"{args.input_dir}")
102
 
103
  # LLM Configuration
104
  ASCIIColors.magenta("\nπŸ€– LLM Configuration:")
105
- ASCIIColors.white(f" β”œβ”€ Binding: ", end="")
106
  ASCIIColors.yellow(f"{args.llm_binding}")
107
- ASCIIColors.white(f" β”œβ”€ Host: ", end="")
108
  ASCIIColors.yellow(f"{args.llm_binding_host}")
109
- ASCIIColors.white(f" └─ Model: ", end="")
110
  ASCIIColors.yellow(f"{args.llm_model}")
111
 
112
  # Embedding Configuration
113
  ASCIIColors.magenta("\nπŸ“Š Embedding Configuration:")
114
- ASCIIColors.white(f" β”œβ”€ Binding: ", end="")
115
  ASCIIColors.yellow(f"{args.embedding_binding}")
116
- ASCIIColors.white(f" β”œβ”€ Host: ", end="")
117
  ASCIIColors.yellow(f"{args.embedding_binding_host}")
118
- ASCIIColors.white(f" β”œβ”€ Model: ", end="")
119
  ASCIIColors.yellow(f"{args.embedding_model}")
120
- ASCIIColors.white(f" └─ Dimensions: ", end="")
121
  ASCIIColors.yellow(f"{args.embedding_dim}")
122
 
123
  # RAG Configuration
124
  ASCIIColors.magenta("\nβš™οΈ RAG Configuration:")
125
- ASCIIColors.white(f" β”œβ”€ Max Async Operations: ", end="")
126
  ASCIIColors.yellow(f"{args.max_async}")
127
- ASCIIColors.white(f" β”œβ”€ Max Tokens: ", end="")
128
  ASCIIColors.yellow(f"{args.max_tokens}")
129
- ASCIIColors.white(f" └─ Max Embed Tokens: ", end="")
130
  ASCIIColors.yellow(f"{args.max_embed_tokens}")
131
 
132
  # System Configuration
133
  ASCIIColors.magenta("\nπŸ› οΈ System Configuration:")
134
- ASCIIColors.white(f" β”œβ”€ Log Level: ", end="")
135
  ASCIIColors.yellow(f"{args.log_level}")
136
- ASCIIColors.white(f" β”œβ”€ Timeout: ", end="")
137
  ASCIIColors.yellow(f"{args.timeout if args.timeout else 'None (infinite)'}")
138
- ASCIIColors.white(f" └─ API Key: ", end="")
139
  ASCIIColors.yellow("Set" if args.key else "Not Set")
140
 
141
  # Server Status
@@ -153,7 +155,7 @@ def display_splash_screen(args: argparse.Namespace) -> None:
153
  ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/docs")
154
  ASCIIColors.white(" └─ Alternative Documentation (local): ", end="")
155
  ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/redoc")
156
-
157
  ASCIIColors.yellow("\nπŸ“ Note:")
158
  ASCIIColors.white(""" Since the server is running on 0.0.0.0:
159
  - Use 'localhost' or '127.0.0.1' for local access
@@ -174,10 +176,10 @@ def display_splash_screen(args: argparse.Namespace) -> None:
174
 
175
  # Usage Examples
176
  ASCIIColors.magenta("\nπŸ“š Quick Start Guide:")
177
- ASCIIColors.cyan("""
178
  1. Access the Swagger UI:
179
  Open your browser and navigate to the API documentation URL above
180
-
181
  2. API Authentication:""")
182
  if args.key:
183
  ASCIIColors.cyan(""" Add the following header to your requests:
@@ -185,12 +187,12 @@ def display_splash_screen(args: argparse.Namespace) -> None:
185
  """)
186
  else:
187
  ASCIIColors.cyan(" No authentication required\n")
188
-
189
  ASCIIColors.cyan(""" 3. Basic Operations:
190
  - POST /upload_document: Upload new documents to RAG
191
  - POST /query: Query your document collection
192
  - GET /collections: List available collections
193
-
194
  4. Monitor the server:
195
  - Check server logs for detailed operation information
196
  - Use healthcheck endpoint: GET /health
@@ -202,21 +204,20 @@ def display_splash_screen(args: argparse.Namespace) -> None:
202
  ASCIIColors.white(""" API Key authentication is enabled.
203
  Make sure to include the X-API-Key header in all your requests.
204
  """)
205
-
206
- ASCIIColors.green("Server is ready to accept connections! πŸš€\n")
207
 
 
208
 
209
 
210
  def parse_args() -> argparse.Namespace:
211
  """
212
  Parse command line arguments with environment variable fallback
213
-
214
  Returns:
215
  argparse.Namespace: Parsed arguments
216
  """
217
  # Load environment variables from .env file
218
  load_dotenv()
219
-
220
  parser = argparse.ArgumentParser(
221
  description="LightRAG FastAPI Server with separate working and input directories"
222
  )
@@ -240,13 +241,13 @@ def parse_args() -> argparse.Namespace:
240
  parser.add_argument(
241
  "--host",
242
  default=get_env_value("HOST", "0.0.0.0"),
243
- help="Server host (default: from env or 0.0.0.0)"
244
  )
245
  parser.add_argument(
246
  "--port",
247
  type=int,
248
  default=get_env_value("PORT", 9621, int),
249
- help="Server port (default: from env or 9621)"
250
  )
251
 
252
  # Directory configuration
@@ -262,7 +263,9 @@ def parse_args() -> argparse.Namespace:
262
  )
263
 
264
  # LLM Model configuration
265
- default_llm_host = get_env_value("LLM_BINDING_HOST", get_default_host(temp_args.llm_binding))
 
 
266
  parser.add_argument(
267
  "--llm-binding-host",
268
  default=default_llm_host,
@@ -276,7 +279,9 @@ def parse_args() -> argparse.Namespace:
276
  )
277
 
278
  # Embedding model configuration
279
- default_embedding_host = get_env_value("EMBEDDING_BINDING_HOST", get_default_host(temp_args.embedding_binding))
 
 
280
  parser.add_argument(
281
  "--embedding-binding-host",
282
  default=default_embedding_host,
@@ -306,7 +311,7 @@ def parse_args() -> argparse.Namespace:
306
  "--max-async",
307
  type=int,
308
  default=get_env_value("MAX_ASYNC", 4, int),
309
- help="Maximum async operations (default: from env or 4)"
310
  )
311
  parser.add_argument(
312
  "--max-tokens",
@@ -347,7 +352,7 @@ def parse_args() -> argparse.Namespace:
347
  "--ssl",
348
  action="store_true",
349
  default=get_env_value("SSL", False, bool),
350
- help="Enable HTTPS (default: from env or False)"
351
  )
352
  parser.add_argument(
353
  "--ssl-certfile",
@@ -628,8 +633,7 @@ def create_app(args):
628
  logging.info(f"Successfully indexed file: {file_path}")
629
  else:
630
  logging.warning(f"No content extracted from file: {file_path}")
631
-
632
-
633
  @asynccontextmanager
634
  async def lifespan(app: FastAPI):
635
  """Lifespan context manager for startup and shutdown events"""
 
38
  binding_type, "http://localhost:11434"
39
  ) # fallback to ollama if unknown
40
 
41
+
42
  from dotenv import load_dotenv
43
+
44
 
45
  def get_env_value(env_key: str, default: Any, value_type: type = str) -> Any:
46
  """
47
  Get value from environment variable with type conversion
48
+
49
  Args:
50
  env_key (str): Environment variable key
51
  default (Any): Default value if env variable is not set
52
  value_type (type): Type to convert the value to
53
+
54
  Returns:
55
  Any: Converted value from environment or default
56
  """
57
  value = os.getenv(env_key)
58
  if value is None:
59
  return default
60
+
61
  if value_type == bool:
62
+ return value.lower() in ("true", "1", "yes")
63
  try:
64
  return value_type(value)
65
  except ValueError:
66
  return default
67
 
68
+
69
  def display_splash_screen(args: argparse.Namespace) -> None:
70
  """
71
  Display a colorful splash screen showing LightRAG server configuration
72
+
73
  Args:
74
  args: Parsed command line arguments
75
  """
 
83
 
84
  # Server Configuration
85
  ASCIIColors.magenta("\nπŸ“‘ Server Configuration:")
86
+ ASCIIColors.white(" β”œβ”€ Host: ", end="")
87
  ASCIIColors.yellow(f"{args.host}")
88
+ ASCIIColors.white(" β”œβ”€ Port: ", end="")
89
  ASCIIColors.yellow(f"{args.port}")
90
+ ASCIIColors.white(" β”œβ”€ SSL Enabled: ", end="")
91
  ASCIIColors.yellow(f"{args.ssl}")
92
  if args.ssl:
93
+ ASCIIColors.white(" β”œβ”€ SSL Cert: ", end="")
94
  ASCIIColors.yellow(f"{args.ssl_certfile}")
95
+ ASCIIColors.white(" └─ SSL Key: ", end="")
96
  ASCIIColors.yellow(f"{args.ssl_keyfile}")
97
 
98
  # Directory Configuration
99
  ASCIIColors.magenta("\nπŸ“‚ Directory Configuration:")
100
+ ASCIIColors.white(" β”œβ”€ Working Directory: ", end="")
101
  ASCIIColors.yellow(f"{args.working_dir}")
102
+ ASCIIColors.white(" └─ Input Directory: ", end="")
103
  ASCIIColors.yellow(f"{args.input_dir}")
104
 
105
  # LLM Configuration
106
  ASCIIColors.magenta("\nπŸ€– LLM Configuration:")
107
+ ASCIIColors.white(" β”œβ”€ Binding: ", end="")
108
  ASCIIColors.yellow(f"{args.llm_binding}")
109
+ ASCIIColors.white(" β”œβ”€ Host: ", end="")
110
  ASCIIColors.yellow(f"{args.llm_binding_host}")
111
+ ASCIIColors.white(" └─ Model: ", end="")
112
  ASCIIColors.yellow(f"{args.llm_model}")
113
 
114
  # Embedding Configuration
115
  ASCIIColors.magenta("\nπŸ“Š Embedding Configuration:")
116
+ ASCIIColors.white(" β”œβ”€ Binding: ", end="")
117
  ASCIIColors.yellow(f"{args.embedding_binding}")
118
+ ASCIIColors.white(" β”œβ”€ Host: ", end="")
119
  ASCIIColors.yellow(f"{args.embedding_binding_host}")
120
+ ASCIIColors.white(" β”œβ”€ Model: ", end="")
121
  ASCIIColors.yellow(f"{args.embedding_model}")
122
+ ASCIIColors.white(" └─ Dimensions: ", end="")
123
  ASCIIColors.yellow(f"{args.embedding_dim}")
124
 
125
  # RAG Configuration
126
  ASCIIColors.magenta("\nβš™οΈ RAG Configuration:")
127
+ ASCIIColors.white(" β”œβ”€ Max Async Operations: ", end="")
128
  ASCIIColors.yellow(f"{args.max_async}")
129
+ ASCIIColors.white(" β”œβ”€ Max Tokens: ", end="")
130
  ASCIIColors.yellow(f"{args.max_tokens}")
131
+ ASCIIColors.white(" └─ Max Embed Tokens: ", end="")
132
  ASCIIColors.yellow(f"{args.max_embed_tokens}")
133
 
134
  # System Configuration
135
  ASCIIColors.magenta("\nπŸ› οΈ System Configuration:")
136
+ ASCIIColors.white(" β”œβ”€ Log Level: ", end="")
137
  ASCIIColors.yellow(f"{args.log_level}")
138
+ ASCIIColors.white(" β”œβ”€ Timeout: ", end="")
139
  ASCIIColors.yellow(f"{args.timeout if args.timeout else 'None (infinite)'}")
140
+ ASCIIColors.white(" └─ API Key: ", end="")
141
  ASCIIColors.yellow("Set" if args.key else "Not Set")
142
 
143
  # Server Status
 
155
  ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/docs")
156
  ASCIIColors.white(" └─ Alternative Documentation (local): ", end="")
157
  ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/redoc")
158
+
159
  ASCIIColors.yellow("\nπŸ“ Note:")
160
  ASCIIColors.white(""" Since the server is running on 0.0.0.0:
161
  - Use 'localhost' or '127.0.0.1' for local access
 
176
 
177
  # Usage Examples
178
  ASCIIColors.magenta("\nπŸ“š Quick Start Guide:")
179
+ ASCIIColors.cyan("""
180
  1. Access the Swagger UI:
181
  Open your browser and navigate to the API documentation URL above
182
+
183
  2. API Authentication:""")
184
  if args.key:
185
  ASCIIColors.cyan(""" Add the following header to your requests:
 
187
  """)
188
  else:
189
  ASCIIColors.cyan(" No authentication required\n")
190
+
191
  ASCIIColors.cyan(""" 3. Basic Operations:
192
  - POST /upload_document: Upload new documents to RAG
193
  - POST /query: Query your document collection
194
  - GET /collections: List available collections
195
+
196
  4. Monitor the server:
197
  - Check server logs for detailed operation information
198
  - Use healthcheck endpoint: GET /health
 
204
  ASCIIColors.white(""" API Key authentication is enabled.
205
  Make sure to include the X-API-Key header in all your requests.
206
  """)
 
 
207
 
208
+ ASCIIColors.green("Server is ready to accept connections! πŸš€\n")
209
 
210
 
211
  def parse_args() -> argparse.Namespace:
212
  """
213
  Parse command line arguments with environment variable fallback
214
+
215
  Returns:
216
  argparse.Namespace: Parsed arguments
217
  """
218
  # Load environment variables from .env file
219
  load_dotenv()
220
+
221
  parser = argparse.ArgumentParser(
222
  description="LightRAG FastAPI Server with separate working and input directories"
223
  )
 
241
  parser.add_argument(
242
  "--host",
243
  default=get_env_value("HOST", "0.0.0.0"),
244
+ help="Server host (default: from env or 0.0.0.0)",
245
  )
246
  parser.add_argument(
247
  "--port",
248
  type=int,
249
  default=get_env_value("PORT", 9621, int),
250
+ help="Server port (default: from env or 9621)",
251
  )
252
 
253
  # Directory configuration
 
263
  )
264
 
265
  # LLM Model configuration
266
+ default_llm_host = get_env_value(
267
+ "LLM_BINDING_HOST", get_default_host(temp_args.llm_binding)
268
+ )
269
  parser.add_argument(
270
  "--llm-binding-host",
271
  default=default_llm_host,
 
279
  )
280
 
281
  # Embedding model configuration
282
+ default_embedding_host = get_env_value(
283
+ "EMBEDDING_BINDING_HOST", get_default_host(temp_args.embedding_binding)
284
+ )
285
  parser.add_argument(
286
  "--embedding-binding-host",
287
  default=default_embedding_host,
 
311
  "--max-async",
312
  type=int,
313
  default=get_env_value("MAX_ASYNC", 4, int),
314
+ help="Maximum async operations (default: from env or 4)",
315
  )
316
  parser.add_argument(
317
  "--max-tokens",
 
352
  "--ssl",
353
  action="store_true",
354
  default=get_env_value("SSL", False, bool),
355
+ help="Enable HTTPS (default: from env or False)",
356
  )
357
  parser.add_argument(
358
  "--ssl-certfile",
 
633
  logging.info(f"Successfully indexed file: {file_path}")
634
  else:
635
  logging.warning(f"No content extracted from file: {file_path}")
636
+
 
637
  @asynccontextmanager
638
  async def lifespan(app: FastAPI):
639
  """Lifespan context manager for startup and shutdown events"""
lightrag/api/requirements.txt CHANGED
@@ -9,6 +9,7 @@ ollama
9
  openai
10
  pipmaster
11
  python-dotenv
 
12
  python-multipart
13
  tenacity
14
  tiktoken
@@ -16,4 +17,3 @@ torch
16
  tqdm
17
  transformers
18
  uvicorn
19
- python-dotenv
 
9
  openai
10
  pipmaster
11
  python-dotenv
12
+ python-dotenv
13
  python-multipart
14
  tenacity
15
  tiktoken
 
17
  tqdm
18
  transformers
19
  uvicorn