diff --git a/backend/open_webui/routers/notes.py b/backend/open_webui/routers/notes.py index db6969d772..947674ca41 100644 --- a/backend/open_webui/routers/notes.py +++ b/backend/open_webui/routers/notes.py @@ -69,8 +69,12 @@ def truncate_note_data(data: Optional[dict], max_length: int = 1000, query: str return data page = matching_page(data, query) md = page['content'].get('md') or '' + text = md.lower() + hits = [text.find(term) for term in query.lower().split() if term in text] + # Start a little before the first search hit so the list can show the words around it. + start = max(0, min(hits) - 100) if hits else 0 return { - 'content': {'md': md[:max_length]}, + 'content': {'md': md[start : start + max_length]}, 'page_count': len(data.get('pages') or [None]), 'page_id': page['id'], 'page_title': page['title'],