Prompt Fine-Tuning

This guide will help you fine-tune prompts for NodeRAG to optimize performance and accuracy.

Prompt Tuning

You can find all prompt templates here.

The simplest way to customize prompts is to open the files and directly modify the English and Chinese prompt text as needed.

New Language Support

You can add support for additional languages by defining corresponding prompts and registering them in the prompt manager.


1. Add Prompt

To add a new language (e.g., German), define prompts for that language in the relevant prompt file.
For example, in the decompose.py, add:

decompos_query = '''
Please break down the following query into a single list...
Query:{query}
'''

decompos_query_Chinese = '''
请将以下问题分解为一个 list...
问题:{query}
'''

decompos_query_German = '''
Bitte zerlegen Sie die folgende Anfrage in eine einzelne Liste...
Anfrage:{query}
'''

2. Register in Prompt Manager

Next, register your new prompt in the prompt manager:
Open prompt_manager.py and do the following:

  • Import your new prompt variable(s)
  • Add a new case in the match statement to handle the language

Example at line 67:

@property
def answer(self):
    match self.language:
        case 'English':
            return answer_prompt
        case 'Chinese':
            return answer_prompt_Chinese
        case 'German':
            return answer_prompt_German
        case _:
            return self.translate(answer_prompt)

Last modified April 5, 2025: update reproduce (f23a25c)