Skip to content
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

Refactor mix prompt construction in mix_kg_vector_query function #1200

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

OxidBurn
Copy link
Contributor

Description

This PR enhances the way LightRAG manages custom system prompts in the "mix" query! Before, when you provided a custom system prompt, it missed out on including the retrieval information. The only option was to stick with a predefined prompt. But now, it also takes into account situations where the custom system prompt might not have all the key parameters. In such cases, it seamlessly extends the prompt with theflexible and user-friendly. retrieved data, making it more

Changes Made

  • Added try-except blocks to handle format string errors gracefully in all query functions:
    • mix_kg_vector_query - handles both knowledge graph and vector contexts
    • kg_query - handles knowledge graph context
    • naive_query - handles vector search results
    • Enhanced prompt generation to intelligently append KG and vector context when formatting keys aren't present
    • Added clear section headers (### Knowledge Graph Context, ### Vector Context) for better prompt organization

Use Cases Addressed

  1. Custom prompts without format placeholders: Users can now provide completely custom prompts without having to include specific format placeholders.
  2. Simplified prompt customization: Reduces the complexity of creating custom prompts as users don't need to understand the internal formatting requirements.

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

This change allows users to provide custom prompts with and without having to include specific formatting placeholders. The system will now intelligently append any available context information to the end of the prompt with proper section headers when formatting keys aren't present.

- Improved error handling for prompt formatting with try-except block
- Enhanced prompt generation to include data source information when context is available
@danielaskdd
Copy link
Collaborator

This is a commendable enhancement. Could you please ensure that kg_query incorporates the same functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants