mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-12 09:01:18 +00:00
fix: sort memory sections for stable system prompt ordering
Memory sections injected into the system prompt (`[User Memory]`, `[Memory Neighborhood]`, `[Relevant Context]`) are populated from vector similarity search, which can return results in different orders between requests even when the same memories are retrieved. This causes the system prompt to change on every turn, which invalidates the LLM's KV cache prefix. On local inference backends like Ollama, this forces a full prompt re-evaluation on every follow-up message — turning a ~3 second cache hit into a ~55 second reprocessing of the entire conversation context. The fix sorts each section alphabetically before rendering, ensuring a stable prompt prefix across turns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8faaf2cd1e
commit
5ebf7705c5
1 changed files with 3 additions and 3 deletions
|
|
@ -361,11 +361,11 @@ async def add_memory_context(request, form_data: dict, user, model: dict | None
|
|||
|
||||
parts = []
|
||||
if sections['user']:
|
||||
parts.append('[User Memory]\n' + '\n'.join(f'- {memory}' for memory in sections['user']))
|
||||
parts.append('[User Memory]\n' + '\n'.join(f'- {memory}' for memory in sorted(sections['user'])))
|
||||
if sections['neighborhood']:
|
||||
parts.append('[Memory Neighborhood]\n' + '\n'.join(f'- {memory}' for memory in sections['neighborhood']))
|
||||
parts.append('[Memory Neighborhood]\n' + '\n'.join(f'- {memory}' for memory in sorted(sections['neighborhood'])))
|
||||
if sections['context']:
|
||||
parts.append('[Relevant Context]\n' + '\n'.join(f'- {memory}' for memory in sections['context']))
|
||||
parts.append('[Relevant Context]\n' + '\n'.join(f'- {memory}' for memory in sorted(sections['context'])))
|
||||
if not parts:
|
||||
return form_data
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue