feat: env var overrides for extraction and query prompts#2944
Open
NaveRazy-Rhino wants to merge 1 commit intoHKUDS:mainfrom
Open
feat: env var overrides for extraction and query prompts#2944NaveRazy-Rhino wants to merge 1 commit intoHKUDS:mainfrom
NaveRazy-Rhino wants to merge 1 commit intoHKUDS:mainfrom
Conversation
…mpts Allow users to customize entity extraction, summarization, and query prompts via environment variables without modifying source code. This is a common request (HKUDS#308, HKUDS#1672, HKUDS#2623) — domain-specific use cases (code analysis, legal, medical) need different extraction prompts but currently require editing prompt.py directly. Each override is optional. If the env var is not set, the hardcoded default is used. String prompts are set directly; list prompts (examples) are parsed as JSON arrays. This is a lightweight, non-breaking bridge until the full prompt template management system (HKUDS#2652) is available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add environment variable overrides for the key prompts in
lightrag/prompt.py, allowing users to customize entity extraction, summarization, and query prompts without modifying source code.This is a minimal, non-breaking bridge until the full prompt template management system (#2652) lands. It follows the same pattern LightRAG already uses for
ENTITY_TYPESandSUMMARY_LANGUAGE.Related Issues
Changes Made
lightrag/prompt.py(42 lines added):import os, jsonPROMPTSentry; otherwise the hardcoded default is preservedENTITY_EXTRACTION_SYSTEM_PROMPT,ENTITY_EXTRACTION_USER_PROMPT,SUMMARIZE_ENTITY_DESCRIPTIONS_PROMPT,RAG_RESPONSE_PROMPT,NAIVE_RAG_RESPONSE_PROMPT,KEYWORDS_EXTRACTION_PROMPTENTITY_EXTRACTION_EXAMPLES,KEYWORDS_EXTRACTION_EXAMPLESenv.example(15 lines added):ENTITY_TYPESWhy This Matters
Domain-specific use cases — code analysis, legal, medical, DevOps — need different extraction prompts. For example, the default prompt title-cases all entity names (
Split And Save Layers), which is wrong for code identifiers that must preservesnake_case. Currently the only options are editingprompt.pydirectly or monkey-patching at runtime.This PR lets users set
ENTITY_EXTRACTION_SYSTEM_PROMPTin.envand get custom extraction behavior with zero code changes, zero new dependencies, and zero risk to existing users.Example Usage
Checklist
pre-commit run --all-files)Additional Notes
This is intentionally minimal. The full prompt template system in #2652 (Jinja2, git-backed, WebUI editor) is the right long-term solution. This PR is a 57-line bridge that unblocks the community today — it can be deprecated when #2652 merges.