-
Notifications
You must be signed in to change notification settings - Fork 4.9k
feat: add per-instance prompt overrides via LightRAG.prompts field #2951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -698,16 +698,31 @@ class EntityExtractionPromptProfile(TypedDict): | |
| entity_extraction_json_examples: list[str] | ||
|
|
||
|
|
||
| def get_default_entity_extraction_prompt_profile() -> EntityExtractionPromptProfile: | ||
| def _get_prompt(key: str, global_config: dict | None = None) -> Any: | ||
| """Return per-instance prompt override if set, else fall back to global PROMPTS.""" | ||
| if global_config: | ||
| override = global_config.get("prompts", {}).get(key) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| if override is not None: | ||
| return override | ||
| return PROMPTS[key] | ||
|
|
||
|
|
||
| def get_default_entity_extraction_prompt_profile( | ||
| global_config: dict | None = None, | ||
| ) -> EntityExtractionPromptProfile: | ||
| """Return a copy of the built-in entity extraction prompt profile.""" | ||
|
|
||
| return { | ||
| "entity_types_guidance": PROMPTS["default_entity_types_guidance"].rstrip(), | ||
| "entity_types_guidance": _get_prompt( | ||
| "default_entity_types_guidance", global_config | ||
| ).rstrip(), | ||
| "entity_extraction_examples": [ | ||
| example.rstrip() for example in PROMPTS["entity_extraction_examples"] | ||
| example.rstrip() | ||
| for example in _get_prompt("entity_extraction_examples", global_config) | ||
| ], | ||
| "entity_extraction_json_examples": [ | ||
| example.rstrip() for example in PROMPTS["entity_extraction_json_examples"] | ||
| example.rstrip() | ||
| for example in _get_prompt("entity_extraction_json_examples", global_config) | ||
| ], | ||
| } | ||
|
|
||
|
|
@@ -847,10 +862,11 @@ def load_entity_extraction_prompt_profile( | |
| def resolve_entity_extraction_prompt_profile( | ||
| addon_params: Mapping[str, Any] | None, | ||
| use_json: bool, | ||
| global_config: dict | None = None, | ||
| ) -> EntityExtractionPromptProfile: | ||
| """Resolve and merge the configured entity extraction prompt profile.""" | ||
|
|
||
| default_profile = get_default_entity_extraction_prompt_profile() | ||
| default_profile = get_default_entity_extraction_prompt_profile(global_config) | ||
| addon_params = addon_params or {} | ||
| prompt_file = addon_params.get("entity_type_prompt_file") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract_entitiesnow resolves prompt profiles withglobal_configonly in theprompt_profile is Nonefallback path, but the normalLightRAGpath uses a precomputed_entity_extraction_prompt_profilecache that is still built without per-instanceprompts. As a result, overrides likedefault_entity_types_guidanceandentity_extraction_examplesare silently ignored for typical instances, so the new per-instance prompt feature does not work for entity extraction defaults unless callers bypass the cached path.Useful? React with 👍 / 👎.