Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ SUMMARY_LANGUAGE=English
### Entity types that the LLM will attempt to recognize
# ENTITY_TYPES='["Person", "Creature", "Organization", "Location", "Event", "Concept", "Method", "Content", "Data", "Artifact", "NaturalObject"]'

### Prompt overrides (optional, env vars)
### Override extraction/query prompts without modifying source code.
### String prompts: set the env var to the full prompt text.
### List prompts (examples): set the env var to a JSON array of strings.
### If not set, built-in defaults are used. See lightrag/prompt.py for defaults.
### Note: this is a lightweight bridge until the full prompt template system (#2623) lands.
# ENTITY_EXTRACTION_SYSTEM_PROMPT=<your custom extraction system prompt>
# ENTITY_EXTRACTION_USER_PROMPT=<your custom extraction user prompt>
# ENTITY_EXTRACTION_EXAMPLES=<JSON array of example strings>
# SUMMARIZE_ENTITY_DESCRIPTIONS_PROMPT=<your custom summarization prompt>
# RAG_RESPONSE_PROMPT=<your custom RAG response prompt>
# NAIVE_RAG_RESPONSE_PROMPT=<your custom naive RAG response prompt>
# KEYWORDS_EXTRACTION_PROMPT=<your custom keywords extraction prompt>
# KEYWORDS_EXTRACTION_EXAMPLES=<JSON array of example strings>

### Chunk size for document splitting, 500~1500 is recommended
# CHUNK_SIZE=1200
# CHUNK_OVERLAP_SIZE=100
Expand Down
42 changes: 42 additions & 0 deletions lightrag/prompt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import annotations
import json
import os
from typing import Any


Expand Down Expand Up @@ -430,3 +432,43 @@

""",
]

# ── Environment variable overrides ───────────────────────────────────
# Allow users to customize prompts via environment variables without
# modifying this file. Each override is optional — if the env var is
# not set, the hardcoded default above is used.
#
# This is a lightweight bridge until the full prompt template management
# system (see #2623 / #2652) is available.
#
# String prompts: set the env var to the full prompt text.
# List prompts (examples): set the env var to a JSON array of strings.

_PROMPT_ENV_OVERRIDES: dict[str, str] = {
"entity_extraction_system_prompt": "ENTITY_EXTRACTION_SYSTEM_PROMPT",
"entity_extraction_user_prompt": "ENTITY_EXTRACTION_USER_PROMPT",
"summarize_entity_descriptions": "SUMMARIZE_ENTITY_DESCRIPTIONS_PROMPT",
"rag_response": "RAG_RESPONSE_PROMPT",
"naive_rag_response": "NAIVE_RAG_RESPONSE_PROMPT",
"keywords_extraction": "KEYWORDS_EXTRACTION_PROMPT",
}

_LIST_PROMPT_ENV_OVERRIDES: dict[str, str] = {
"entity_extraction_examples": "ENTITY_EXTRACTION_EXAMPLES",
"keywords_extraction_examples": "KEYWORDS_EXTRACTION_EXAMPLES",
}

for _key, _env_var in _PROMPT_ENV_OVERRIDES.items():
_val = os.environ.get(_env_var)
if _val is not None:
PROMPTS[_key] = _val

for _key, _env_var in _LIST_PROMPT_ENV_OVERRIDES.items():
_val = os.environ.get(_env_var)
if _val is not None:
try:
parsed = json.loads(_val)
if isinstance(parsed, list):
PROMPTS[_key] = parsed
except (json.JSONDecodeError, TypeError):
pass # Ignore malformed JSON — keep the default