diff --git a/surfsense_backend/app/tasks/chat/stream_new_chat.py b/surfsense_backend/app/tasks/chat/stream_new_chat.py index 2038e85dc..940538bff 100644 --- a/surfsense_backend/app/tasks/chat/stream_new_chat.py +++ b/surfsense_backend/app/tasks/chat/stream_new_chat.py @@ -59,11 +59,28 @@ def format_mentioned_documents_as_context(documents: list[Document]) -> str: "These documents are directly relevant to the query and should be prioritized as primary sources." ) for i, doc in enumerate(documents, 1): - context_parts.append( - f"" - ) - context_parts.append(f"") - context_parts.append("") + # Prepare retriever-style structure + doc_metadata = doc.document_metadata if doc.document_metadata else {} + xml_doc = f""" + + {doc.id} + + 1.0 + + + {doc.id}-full + + + + + {doc.id} + <![CDATA[{doc.title}]]> + {doc.document_type.value} + + + {doc.document_type.value} + """ + context_parts.append(xml_doc.strip()) context_parts.append("") return "\n".join(context_parts)