Open B14ckFox opened 3 days ago
I recently started testing LightRAG as well (thank you for developing this promising repository). I have encountered the same observation as the author of this issue: the model is insufficiently strict in adhering to the provided context and often produces generic answers.
While adjusting the temperature setting is a potential solution, my usual approach would be to resolve this issue through the system prompt. I attempted to add an instruction directly to the question (e.g., "limit your answer to the provided context"), but this resulted in no answers being generated, as the model deemed nothing to be in context.
I would, therefore, like to have control over modifying the system prompt and the overall query prompt. I reviewed the Python code to locate where these prompts are defined or managed. Unfortunately, the (undocumented) code appears somewhat inaccessible in this regard. For instance, prompt.py seems primarily intended for generating the knowledge graph.
Where in the codebase can I view and customize the system prompt and the query prompt used for generating answers from the model?
The prompt used for generating responses is defined in the prompt.py
file, and it is called rag_response
.
and this is how I adjust the temperature?
async def gpt_4o_mini_complete( prompt, system_prompt=None, history_messages=[], kwargs ) -> str: kwargs.setdefault("temperature", 0) return await openai_complete_if_cache( "gpt-4o-mini", prompt, system_prompt=system_prompt, history_messages=history_messages, kwargs, )
@B14ckFox I believe you can also directly pass your llm parameters via llm_model_kwargs to LightRAG without modifying anything else:
rag = LightRAG(
working_dir=WORKING_DIR,
llm_model_func=gpt_4o_mini_complete,
llm_model_kwargs={"temperature": 0.0}
)
Description I am using the following example code with LightRAG and the gpt_4o_mini_complete model. However, I noticed that the model generates made-up information that doesn't align with the provided knowledge graph. I would like the model to strictly adhere to the provided context and avoid introducing hallucinations.
Here are my specific questions:
How can I adjust the temperature of the model in this example to make the responses more deterministic and context-based? Should I also adapt the system prompt to enforce stricter adherence to the provided graph? If so, could you provide guidance or an example of how to adjust the prompt effectively?
testing after kg creation: --> not accurate response too much made up
Code from inster_custom_kg.py
The model should:
Temperature Adjustment: Where and how can I configure the model's temperature in the above example? Prompt Adaptation: Would modifying the system prompt improve context adherence, and if so, how should I approach this?
Thanks in advance for the help and guidance!