diff --git a/backend/app/services/rag.py b/backend/app/services/rag.py index bc3a017..b711ff4 100644 --- a/backend/app/services/rag.py +++ b/backend/app/services/rag.py @@ -95,8 +95,10 @@ class RAGService: for i, (chunk, meta) in enumerate(zip(chunks, metadata_list)): source = meta.get("filename", "unknown") summary = meta.get("content_summary", "") + page_num = meta.get("page_number") + citation_label = f"{source}, page {page_num}" if page_num else source context_parts.append( - f"[{i + 1}] Source: {source}\n" + f"[{citation_label}] Source: {source}\n" f"Summary: {summary}\n" f"Content: {chunk}\n" ) @@ -108,7 +110,8 @@ class RAGService: f"Answer the question using ONLY these document chunks. " f"Do not use any external knowledge. " f"Format your answer as bullet points. " - f"Cite the source name in [ ] for each point.\n\n" + f"Cite your sources inline using the exact bracket labels provided, " + f"e.g. [filename, page N]. Place the citation at the end of each relevant point.\n\n" f"Document chunks:\n{context}\n\n" f"Answer:" )