Milin commited on
Commit
d422172
·
1 Parent(s): 8151c0e

refactor(api): Code optimization based on review comments.

Browse files

- Removed authentication dependency for the health check endpoint in lightrag_server.py
- Removed the authentication dependency for the entire router in ollama_api.py
- Updated the parameter list and example usage in README.md, removing authentication-related parts
- Removed neo4j and tqdm dependencies from requirements.txt
- Deleted command-line argument parsing code related to authentication from utils_api.py

lightrag/api/README.md CHANGED
@@ -295,32 +295,26 @@ You can not change storage implementation selection after you add documents to L
295
 
296
  ### LightRag API Server Comand Line Options
297
 
298
- | Parameter | Default | Description |
299
- |-------------------------|----------------|-----------------------------------------------------------------------------------------------------------------------------|
300
- | --host | 0.0.0.0 | Server host |
301
- | --port | 9621 | Server port |
302
- | --working-dir | ./rag_storage | Working directory for RAG storage |
303
- | --input-dir | ./inputs | Directory containing input documents |
304
- | --max-async | 4 | Maximum async operations |
305
- | --max-tokens | 32768 | Maximum token size |
306
- | --timeout | 150 | Timeout in seconds. None for infinite timeout(not recommended) |
307
- | --log-level | INFO | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
308
- | --verbose | - | Verbose debug output (True, Flase) |
309
- | --key | None | API key for authentication. Protects lightrag server against unauthorized access |
310
- | --ssl | False | Enable HTTPS |
311
- | --ssl-certfile | None | Path to SSL certificate file (required if --ssl is enabled) |
312
- | --ssl-keyfile | None | Path to SSL private key file (required if --ssl is enabled) |
313
- | --top-k | 50 | Number of top-k items to retrieve; corresponds to entities in "local" mode and relationships in "global" mode. |
314
- | --cosine-threshold | 0.4 | The cossine threshold for nodes and relations retrieval, works with top-k to control the retrieval of nodes and relations. |
315
- | --llm-binding | ollama | LLM binding type (lollms, ollama, openai, openai-ollama, azure_openai) |
316
- | --embedding-binding | ollama | Embedding binding type (lollms, ollama, openai, azure_openai) |
317
- | --auto-scan-at-startup | - | Scan input directory for new files and start indexing |
318
- | --auth-username | - | Enable jwt if not empty |
319
- | --auth-password | - | Enable jwt if not empty |
320
- | --token-secret | - | JWT key |
321
- | --token-expire-hours | 4 | expire duration |
322
- | --whitelist-paths | /login,/health | white list |
323
-
324
 
325
  ### Example Usage
326
 
@@ -399,11 +393,11 @@ pip install lightrag-hku
399
  LightRAG API Server implements JWT-based authentication using HS256 algorithm. To enable secure access control, the following environment variables are required:
400
  ```bash
401
  # For jwt auth
402
- AUTH_USERNAME=admin # login name --auth-username
403
- AUTH_PASSWORD=admin123 # password --auth-password
404
- TOKEN_SECRET=your-key # JWT key --token-secret
405
- TOKEN_EXPIRE_HOURS=4 # expire duration --token-expire-hours
406
- WHITELIST_PATHS=/login,/health # white list --whitelist-paths
407
  ```
408
 
409
  ## API Endpoints
 
295
 
296
  ### LightRag API Server Comand Line Options
297
 
298
+ | Parameter | Default | Description |
299
+ |-----------|---------|-------------|
300
+ | --host | 0.0.0.0 | Server host |
301
+ | --port | 9621 | Server port |
302
+ | --working-dir | ./rag_storage | Working directory for RAG storage |
303
+ | --input-dir | ./inputs | Directory containing input documents |
304
+ | --max-async | 4 | Maximum async operations |
305
+ | --max-tokens | 32768 | Maximum token size |
306
+ | --timeout | 150 | Timeout in seconds. None for infinite timeout(not recommended) |
307
+ | --log-level | INFO | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
308
+ | --verbose | - | Verbose debug output (True, Flase) |
309
+ | --key | None | API key for authentication. Protects lightrag server against unauthorized access |
310
+ | --ssl | False | Enable HTTPS |
311
+ | --ssl-certfile | None | Path to SSL certificate file (required if --ssl is enabled) |
312
+ | --ssl-keyfile | None | Path to SSL private key file (required if --ssl is enabled) |
313
+ | --top-k | 50 | Number of top-k items to retrieve; corresponds to entities in "local" mode and relationships in "global" mode. |
314
+ | --cosine-threshold | 0.4 | The cossine threshold for nodes and relations retrieval, works with top-k to control the retrieval of nodes and relations. |
315
+ | --llm-binding | ollama | LLM binding type (lollms, ollama, openai, openai-ollama, azure_openai) |
316
+ | --embedding-binding | ollama | Embedding binding type (lollms, ollama, openai, azure_openai) |
317
+ | auto-scan-at-startup | - | Scan input directory for new files and start indexing |
 
 
 
 
 
 
318
 
319
  ### Example Usage
320
 
 
393
  LightRAG API Server implements JWT-based authentication using HS256 algorithm. To enable secure access control, the following environment variables are required:
394
  ```bash
395
  # For jwt auth
396
+ AUTH_USERNAME=admin # login name
397
+ AUTH_PASSWORD=admin123 # password
398
+ TOKEN_SECRET=your-key # JWT key
399
+ TOKEN_EXPIRE_HOURS=4 # expire duration
400
+ WHITELIST_PATHS=/api1,/api2 # white list. /login,/health,/docs,/redoc,/openapi.json are whitelisted by default.
401
  ```
402
 
403
  ## API Endpoints
lightrag/api/lightrag_server.py CHANGED
@@ -400,7 +400,7 @@ def create_app(args):
400
  "token_type": "bearer"
401
  }
402
 
403
- @app.get("/health", dependencies=[Depends(optional_api_key), Depends(get_auth_dependency())])
404
  async def get_status():
405
  """Get current system status"""
406
  # Get update flags status for all namespaces
 
400
  "token_type": "bearer"
401
  }
402
 
403
+ @app.get("/health", dependencies=[Depends(optional_api_key)])
404
  async def get_status():
405
  """Get current system status"""
406
  # Get update flags status for all namespaces
lightrag/api/requirements.txt CHANGED
@@ -8,14 +8,12 @@ python-multipart
8
  tenacity
9
  tiktoken
10
  uvicorn
11
- tqdm
12
  jiter
13
  httpcore
14
  distro
15
  httpx
16
  openai
17
  asyncpg
18
- neo4j
19
  pytz
20
  python-jose[cryptography]
21
  passlib[bcrypt]
 
8
  tenacity
9
  tiktoken
10
  uvicorn
 
11
  jiter
12
  httpcore
13
  distro
14
  httpx
15
  openai
16
  asyncpg
 
17
  pytz
18
  python-jose[cryptography]
19
  passlib[bcrypt]
lightrag/api/routers/ollama_api.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import APIRouter, HTTPException, Request, Depends
2
  from pydantic import BaseModel
3
  from typing import List, Dict, Any, Optional
4
  import logging
@@ -11,7 +11,7 @@ import asyncio
11
  from ascii_colors import trace_exception
12
  from lightrag import LightRAG, QueryParam
13
  from lightrag.utils import encode_string_by_tiktoken
14
- from ..utils_api import ollama_server_infos, get_auth_dependency
15
 
16
 
17
  # query mode according to query prefix (bypass is not LightRAG quer mode)
@@ -126,7 +126,7 @@ class OllamaAPI:
126
  self.rag = rag
127
  self.ollama_server_infos = ollama_server_infos
128
  self.top_k = top_k
129
- self.router = APIRouter(tags=["ollama"], dependencies=[Depends(get_auth_dependency())])
130
  self.setup_routes()
131
 
132
  def setup_routes(self):
 
1
+ from fastapi import APIRouter, HTTPException, Request
2
  from pydantic import BaseModel
3
  from typing import List, Dict, Any, Optional
4
  import logging
 
11
  from ascii_colors import trace_exception
12
  from lightrag import LightRAG, QueryParam
13
  from lightrag.utils import encode_string_by_tiktoken
14
+ from ..utils_api import ollama_server_infos
15
 
16
 
17
  # query mode according to query prefix (bypass is not LightRAG quer mode)
 
126
  self.rag = rag
127
  self.ollama_server_infos = ollama_server_infos
128
  self.top_k = top_k
129
+ self.router = APIRouter(tags=["ollama"])
130
  self.setup_routes()
131
 
132
  def setup_routes(self):
lightrag/api/utils_api.py CHANGED
@@ -312,38 +312,6 @@ def parse_args(is_uvicorn_mode: bool = False) -> argparse.Namespace:
312
  help="Embedding binding type (default: from env or ollama)",
313
  )
314
 
315
- # Authentication configuration
316
- parser.add_argument(
317
- "--auth-username",
318
- type=str,
319
- default=get_env_value("AUTH_USERNAME", ""),
320
- help="Login username (default: from env or empty)"
321
- )
322
- parser.add_argument(
323
- "--auth-password",
324
- type=str,
325
- default=get_env_value("AUTH_PASSWORD", ""),
326
- help="Login password (default: from env or empty)"
327
- )
328
- parser.add_argument(
329
- "--token-secret",
330
- type=str,
331
- default=get_env_value("TOKEN_SECRET", ""),
332
- help="JWT signing secret (default: from env or empty)"
333
- )
334
- parser.add_argument(
335
- "--token-expire-hours",
336
- type=int,
337
- default=get_env_value("TOKEN_EXPIRE_HOURS", 4, int),
338
- help="Token validity in hours (default: from env or 4)"
339
- )
340
- parser.add_argument(
341
- "--whitelist-paths",
342
- type=str,
343
- default=get_env_value("WHITELIST_PATHS", "/login,/health"),
344
- help="Comma-separated auth-exempt paths (default: from env or /login,/health)"
345
- )
346
-
347
  args = parser.parse_args()
348
 
349
  # If in uvicorn mode and workers > 1, force it to 1 and log warning
 
312
  help="Embedding binding type (default: from env or ollama)",
313
  )
314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  args = parser.parse_args()
316
 
317
  # If in uvicorn mode and workers > 1, force it to 1 and log warning