Bail early if there's no documents

This commit is contained in:
Trenton Holmes
2026-06-06 06:44:16 -07:00
parent 9b23eddeac
commit 6ee84af8ad
2 changed files with 11 additions and 0 deletions
+4
View File
@@ -85,6 +85,10 @@ def stream_chat_with_documents(query_str: str, documents: list[Document]):
def _stream_chat_with_documents(query_str: str, documents: list[Document]):
if not documents:
yield CHAT_NO_CONTENT_MESSAGE
return
from llama_index.core.prompts import PromptTemplate
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.core.response_synthesizers import get_response_synthesizer
+7
View File
@@ -176,6 +176,13 @@ def test_stream_chat_with_multiple_documents_retrieval(patch_embed_nodes) -> Non
)
def test_stream_chat_empty_document_list() -> None:
with patch("paperless_ai.chat.load_or_build_index") as mock_load_index:
output = list(stream_chat_with_documents("Any info?", []))
mock_load_index.assert_not_called()
assert output == ["Sorry, I couldn't find any content to answer your question."]
def test_stream_chat_no_matching_nodes() -> None:
with (
patch("paperless_ai.chat.AIClient") as mock_client_cls,