Skip to content

Commit 9d5603d

Browse files
committed
Set the default LLM temperature to 1.0 and centralize constant management
1 parent 3c530b2 commit 9d5603d

7 files changed

Lines changed: 31 additions & 14 deletions

File tree

env.example

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,21 @@ MAX_PARALLEL_INSERT=2
111111
#######################
112112
### LLM Configuration
113113
#######################
114-
### Time out in seconds for LLM, None for infinite timeout
115-
TIMEOUT=240
116-
### Some models like o1-mini require temperature to be set to 1
117-
TEMPERATURE=0
114+
### Some models like o1-mini require temperature to be set to 1, some LLM can fall into output loops with low temperature
115+
# TEMPERATURE=1.0
116+
118117
### LLM Binding type: openai, ollama, lollms, azure_openai
119118
LLM_BINDING=openai
120119
LLM_MODEL=gpt-4o
121120
LLM_BINDING_HOST=https://api.openai.com/v1
122121
LLM_BINDING_API_KEY=your_api_key
123122

124-
### Set as num_ctx option for Ollama LLM (Must be larger than MAX_TOTAL_TOKENS+2000)
123+
### Most Commont Parameters for Ollama Server
125124
### see also env.ollama-binding-options.example for fine tuning ollama
125+
### OLLAMA_LLM_NUM_CTX must be larger than MAX_TOTAL_TOKENS + 2000
126126
# OLLAMA_LLM_NUM_CTX=32768
127+
### Time out in seconds, None for infinite timeout
128+
TIMEOUT=240
127129

128130
### Optional for Azure
129131
# AZURE_OPENAI_API_VERSION=2024-08-01-preview

lightrag/api/README-zh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ MAX_PARALLEL_INSERT=2
468468

469469
### LLM Configuration (Use valid host. For local services installed with docker, you can use host.docker.internal)
470470
TIMEOUT=200
471-
TEMPERATURE=0.0
472471
MAX_ASYNC=4
473472

474473
LLM_BINDING=openai

lightrag/api/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ MAX_PARALLEL_INSERT=2
476476

477477
### LLM Configuration (Use valid host. For local services installed with docker, you can use host.docker.internal)
478478
TIMEOUT=200
479-
TEMPERATURE=0.0
480479
MAX_ASYNC=4
481480

482481
LLM_BINDING=openai

lightrag/api/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
DEFAULT_OLLAMA_MODEL_SIZE,
3434
DEFAULT_OLLAMA_CREATED_AT,
3535
DEFAULT_OLLAMA_DIGEST,
36+
DEFAULT_TEMPERATURE,
3637
)
3738

3839
# use the .env that is inside the current folder
@@ -332,7 +333,7 @@ def parse_args() -> argparse.Namespace:
332333
args.enable_llm_cache = get_env_value("ENABLE_LLM_CACHE", True, bool)
333334

334335
# Inject LLM temperature configuration
335-
args.temperature = get_env_value("TEMPERATURE", 0.5, float)
336+
args.temperature = get_env_value("TEMPERATURE", DEFAULT_TEMPERATURE, float)
336337

337338
# Select Document loading tool (DOCLING, DEFAULT)
338339
args.document_loading_engine = get_env_value("DOCUMENT_LOADING_ENGINE", "DEFAULT")

lightrag/constants.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Default values for server settings
1010
DEFAULT_WOKERS = 2
11-
DEFAULT_TIMEOUT = 150
11+
DEFAULT_MAX_GRAPH_NODES = 1000
1212

1313
# Default values for extraction settings
1414
DEFAULT_SUMMARY_LANGUAGE = "English" # Default language for summaries
@@ -34,16 +34,23 @@
3434
DEFAULT_ENABLE_RERANK = True
3535
DEFAULT_MIN_RERANK_SCORE = 0.0
3636

37-
# File path configuration for vector and graph database
37+
# File path configuration for vector and graph database(Should not be changed, used in Milvus Schema)
3838
DEFAULT_MAX_FILE_PATH_LENGTH = 4090
3939

40+
# Default temperature for LLM
41+
DEFAULT_TEMPERATURE = 1.0
42+
4043
# Async configuration defaults
4144
DEFAULT_MAX_ASYNC = 4 # Default maximum async operations
45+
DEFAULT_MAX_PARALLEL_INSERT = 2 # Default maximum parallel insert operations
4246

4347
# Embedding configuration defaults
4448
DEFAULT_EMBEDDING_FUNC_MAX_ASYNC = 8 # Default max async for embedding functions
4549
DEFAULT_EMBEDDING_BATCH_NUM = 10 # Default batch size for embedding computations
4650

51+
# Ollama Server Timetout in seconds
52+
DEFAULT_TIMEOUT = 150
53+
4754
# Logging configuration defaults
4855
DEFAULT_LOG_MAX_BYTES = 10485760 # Default 10MB
4956
DEFAULT_LOG_BACKUP_COUNT = 5 # Default 5 backups

lightrag/lightrag.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
DEFAULT_RELATED_CHUNK_NUMBER,
3434
DEFAULT_MIN_RERANK_SCORE,
3535
DEFAULT_SUMMARY_MAX_TOKENS,
36+
DEFAULT_MAX_ASYNC,
37+
DEFAULT_MAX_PARALLEL_INSERT,
38+
DEFAULT_MAX_GRAPH_NODES,
3639
)
3740
from lightrag.utils import get_env_value
3841

@@ -283,7 +286,9 @@ class LightRAG:
283286
)
284287
"""Maximum number of tokens allowed per LLM response."""
285288

286-
llm_model_max_async: int = field(default=int(os.getenv("MAX_ASYNC", 4)))
289+
llm_model_max_async: int = field(
290+
default=int(os.getenv("MAX_ASYNC", DEFAULT_MAX_ASYNC))
291+
)
287292
"""Maximum number of concurrent LLM calls."""
288293

289294
llm_model_kwargs: dict[str, Any] = field(default_factory=dict)
@@ -315,10 +320,14 @@ class LightRAG:
315320
# Extensions
316321
# ---
317322

318-
max_parallel_insert: int = field(default=int(os.getenv("MAX_PARALLEL_INSERT", 2)))
323+
max_parallel_insert: int = field(
324+
default=int(os.getenv("MAX_PARALLEL_INSERT", DEFAULT_MAX_PARALLEL_INSERT))
325+
)
319326
"""Maximum number of parallel insert operations."""
320327

321-
max_graph_nodes: int = field(default=get_env_value("MAX_GRAPH_NODES", 1000, int))
328+
max_graph_nodes: int = field(
329+
default=get_env_value("MAX_GRAPH_NODES", DEFAULT_MAX_GRAPH_NODES, int)
330+
)
322331
"""Maximum number of graph nodes to return in knowledge graph queries."""
323332

324333
addon_params: dict[str, Any] = field(

lightrag/llm/lollms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def lollms_model_if_cache(
5959
"personality": kwargs.get("personality", -1),
6060
"n_predict": kwargs.get("n_predict", None),
6161
"stream": stream,
62-
"temperature": kwargs.get("temperature", 0.1),
62+
"temperature": kwargs.get("temperature", 0.8),
6363
"top_k": kwargs.get("top_k", 50),
6464
"top_p": kwargs.get("top_p", 0.95),
6565
"repeat_penalty": kwargs.get("repeat_penalty", 0.8),

0 commit comments

Comments
 (0)