yangdx commited on
Commit
c11e4ce
·
1 Parent(s): 99d1103

Deprecate log_level and log_file_path in LightRAG.

Browse files

- Remove log_level from API initialization
- Add warnings for deprecated logging params

README.md CHANGED
@@ -106,6 +106,9 @@ import asyncio
106
  from lightrag import LightRAG, QueryParam
107
  from lightrag.llm.openai import gpt_4o_mini_complete, gpt_4o_complete, openai_embed
108
  from lightrag.kg.shared_storage import initialize_pipeline_status
 
 
 
109
 
110
  async def initialize_rag():
111
  rag = LightRAG(
@@ -344,6 +347,10 @@ from lightrag.llm.llama_index_impl import llama_index_complete_if_cache, llama_i
344
  from llama_index.embeddings.openai import OpenAIEmbedding
345
  from llama_index.llms.openai import OpenAI
346
  from lightrag.kg.shared_storage import initialize_pipeline_status
 
 
 
 
347
 
348
  async def initialize_rag():
349
  rag = LightRAG(
@@ -640,6 +647,9 @@ export NEO4J_URI="neo4j://localhost:7687"
640
  export NEO4J_USERNAME="neo4j"
641
  export NEO4J_PASSWORD="password"
642
 
 
 
 
643
  # When you launch the project be sure to override the default KG: NetworkX
644
  # by specifying kg="Neo4JStorage".
645
 
@@ -649,8 +659,12 @@ rag = LightRAG(
649
  working_dir=WORKING_DIR,
650
  llm_model_func=gpt_4o_mini_complete, # Use gpt_4o_mini_complete LLM model
651
  graph_storage="Neo4JStorage", #<-----------override KG default
652
- log_level="DEBUG" #<-----------override log_level default
653
  )
 
 
 
 
 
654
  ```
655
  see test_neo4j.py for a working example.
656
 
@@ -859,7 +873,6 @@ Valid modes are:
859
  | **kv\_storage** | `str` | Storage type for documents and text chunks. Supported types: `JsonKVStorage`, `OracleKVStorage` | `JsonKVStorage` |
860
  | **vector\_storage** | `str` | Storage type for embedding vectors. Supported types: `NanoVectorDBStorage`, `OracleVectorDBStorage` | `NanoVectorDBStorage` |
861
  | **graph\_storage** | `str` | Storage type for graph edges and nodes. Supported types: `NetworkXStorage`, `Neo4JStorage`, `OracleGraphStorage` | `NetworkXStorage` |
862
- | **log\_level** | | Log level for application runtime | `logging.DEBUG` |
863
  | **chunk\_token\_size** | `int` | Maximum token size per chunk when splitting documents | `1200` |
864
  | **chunk\_overlap\_token\_size** | `int` | Overlap token size between two chunks when splitting documents | `100` |
865
  | **tiktoken\_model\_name** | `str` | Model name for the Tiktoken encoder used to calculate token numbers | `gpt-4o-mini` |
@@ -881,7 +894,6 @@ Valid modes are:
881
  | **addon\_params** | `dict` | Additional parameters, e.g., `{"example_number": 1, "language": "Simplified Chinese", "entity_types": ["organization", "person", "geo", "event"], "insert_batch_size": 10}`: sets example limit, output language, and batch size for document processing | `example_number: all examples, language: English, insert_batch_size: 10` |
882
  | **convert\_response\_to\_json\_func** | `callable` | Not used | `convert_response_to_json` |
883
  | **embedding\_cache\_config** | `dict` | Configuration for question-answer caching. Contains three parameters:<br>- `enabled`: Boolean value to enable/disable cache lookup functionality. When enabled, the system will check cached responses before generating new answers.<br>- `similarity_threshold`: Float value (0-1), similarity threshold. When a new question's similarity with a cached question exceeds this threshold, the cached answer will be returned directly without calling the LLM.<br>- `use_llm_check`: Boolean value to enable/disable LLM similarity verification. When enabled, LLM will be used as a secondary check to verify the similarity between questions before returning cached answers. | Default: `{"enabled": False, "similarity_threshold": 0.95, "use_llm_check": False}` |
884
- |**log\_dir** | `str` | Directory to store logs. | `./` |
885
 
886
  </details>
887
 
 
106
  from lightrag import LightRAG, QueryParam
107
  from lightrag.llm.openai import gpt_4o_mini_complete, gpt_4o_complete, openai_embed
108
  from lightrag.kg.shared_storage import initialize_pipeline_status
109
+ from lightrag.utils import setup_logger
110
+
111
+ setup_logger("lightrag", level="INFO")
112
 
113
  async def initialize_rag():
114
  rag = LightRAG(
 
347
  from llama_index.embeddings.openai import OpenAIEmbedding
348
  from llama_index.llms.openai import OpenAI
349
  from lightrag.kg.shared_storage import initialize_pipeline_status
350
+ from lightrag.utils import setup_logger
351
+
352
+ # Setup log handler for LightRAG
353
+ setup_logger("lightrag", level="INFO")
354
 
355
  async def initialize_rag():
356
  rag = LightRAG(
 
647
  export NEO4J_USERNAME="neo4j"
648
  export NEO4J_PASSWORD="password"
649
 
650
+ # Setup logger for LightRAG
651
+ setup_logger("lightrag", level="INFO")
652
+
653
  # When you launch the project be sure to override the default KG: NetworkX
654
  # by specifying kg="Neo4JStorage".
655
 
 
659
  working_dir=WORKING_DIR,
660
  llm_model_func=gpt_4o_mini_complete, # Use gpt_4o_mini_complete LLM model
661
  graph_storage="Neo4JStorage", #<-----------override KG default
 
662
  )
663
+
664
+ # Initialize database connections
665
+ await rag.initialize_storages()
666
+ # Initialize pipeline status for document processing
667
+ await initialize_pipeline_status()
668
  ```
669
  see test_neo4j.py for a working example.
670
 
 
873
  | **kv\_storage** | `str` | Storage type for documents and text chunks. Supported types: `JsonKVStorage`, `OracleKVStorage` | `JsonKVStorage` |
874
  | **vector\_storage** | `str` | Storage type for embedding vectors. Supported types: `NanoVectorDBStorage`, `OracleVectorDBStorage` | `NanoVectorDBStorage` |
875
  | **graph\_storage** | `str` | Storage type for graph edges and nodes. Supported types: `NetworkXStorage`, `Neo4JStorage`, `OracleGraphStorage` | `NetworkXStorage` |
 
876
  | **chunk\_token\_size** | `int` | Maximum token size per chunk when splitting documents | `1200` |
877
  | **chunk\_overlap\_token\_size** | `int` | Overlap token size between two chunks when splitting documents | `100` |
878
  | **tiktoken\_model\_name** | `str` | Model name for the Tiktoken encoder used to calculate token numbers | `gpt-4o-mini` |
 
894
  | **addon\_params** | `dict` | Additional parameters, e.g., `{"example_number": 1, "language": "Simplified Chinese", "entity_types": ["organization", "person", "geo", "event"], "insert_batch_size": 10}`: sets example limit, output language, and batch size for document processing | `example_number: all examples, language: English, insert_batch_size: 10` |
895
  | **convert\_response\_to\_json\_func** | `callable` | Not used | `convert_response_to_json` |
896
  | **embedding\_cache\_config** | `dict` | Configuration for question-answer caching. Contains three parameters:<br>- `enabled`: Boolean value to enable/disable cache lookup functionality. When enabled, the system will check cached responses before generating new answers.<br>- `similarity_threshold`: Float value (0-1), similarity threshold. When a new question's similarity with a cached question exceeds this threshold, the cached answer will be returned directly without calling the LLM.<br>- `use_llm_check`: Boolean value to enable/disable LLM similarity verification. When enabled, LLM will be used as a secondary check to verify the similarity between questions before returning cached answers. | Default: `{"enabled": False, "similarity_threshold": 0.95, "use_llm_check": False}` |
 
897
 
898
  </details>
899
 
lightrag/api/lightrag_server.py CHANGED
@@ -329,7 +329,6 @@ def create_app(args):
329
  "similarity_threshold": 0.95,
330
  "use_llm_check": False,
331
  },
332
- log_level=args.log_level,
333
  namespace_prefix=args.namespace_prefix,
334
  auto_manage_storages_states=False,
335
  )
@@ -359,7 +358,6 @@ def create_app(args):
359
  "similarity_threshold": 0.95,
360
  "use_llm_check": False,
361
  },
362
- log_level=args.log_level,
363
  namespace_prefix=args.namespace_prefix,
364
  auto_manage_storages_states=False,
365
  )
 
329
  "similarity_threshold": 0.95,
330
  "use_llm_check": False,
331
  },
 
332
  namespace_prefix=args.namespace_prefix,
333
  auto_manage_storages_states=False,
334
  )
 
358
  "similarity_threshold": 0.95,
359
  "use_llm_check": False,
360
  },
 
361
  namespace_prefix=args.namespace_prefix,
362
  auto_manage_storages_states=False,
363
  )
lightrag/lightrag.py CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
3
  import asyncio
4
  import configparser
5
  import os
 
6
  from dataclasses import asdict, dataclass, field
7
  from datetime import datetime
8
  from functools import partial
@@ -85,14 +86,10 @@ class LightRAG:
85
  doc_status_storage: str = field(default="JsonDocStatusStorage")
86
  """Storage type for tracking document processing statuses."""
87
 
88
- # Logging
89
  # ---
90
-
91
  log_level: int = field(default=logger.level)
92
- """Logging level for the system (e.g., 'DEBUG', 'INFO', 'WARNING')."""
93
-
94
  log_file_path: str = field(default=os.path.join(os.getcwd(), "lightrag.log"))
95
- """Log file path."""
96
 
97
  # Entity extraction
98
  # ---
@@ -270,6 +267,24 @@ class LightRAG:
270
  initialize_share_data,
271
  )
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  initialize_share_data()
274
 
275
  if not os.path.exists(self.working_dir):
 
3
  import asyncio
4
  import configparser
5
  import os
6
+ import warnings
7
  from dataclasses import asdict, dataclass, field
8
  from datetime import datetime
9
  from functools import partial
 
86
  doc_status_storage: str = field(default="JsonDocStatusStorage")
87
  """Storage type for tracking document processing statuses."""
88
 
89
+ # Logging (Deprecated, use setup_logger in utils.py instead)
90
  # ---
 
91
  log_level: int = field(default=logger.level)
 
 
92
  log_file_path: str = field(default=os.path.join(os.getcwd(), "lightrag.log"))
 
93
 
94
  # Entity extraction
95
  # ---
 
267
  initialize_share_data,
268
  )
269
 
270
+ # Handle deprecated parameters
271
+ kwargs = self.__dict__
272
+ if "log_level" in kwargs:
273
+ warnings.warn(
274
+ "WARNING: log_level parameter is deprecated, use setup_logger in utils.py instead",
275
+ UserWarning,
276
+ stacklevel=2,
277
+ )
278
+ # Remove the attribute to prevent its use
279
+ delattr(self, "log_level")
280
+ if "log_file_path" in kwargs:
281
+ warnings.warn(
282
+ "WARNING: log_file_path parameter is deprecated, use setup_logger in utils.py instead",
283
+ UserWarning,
284
+ stacklevel=2,
285
+ )
286
+ delattr(self, "log_file_path")
287
+
288
  initialize_share_data()
289
 
290
  if not os.path.exists(self.working_dir):