Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Increased allowable empty context size to remove need for EmptyDocsError
  • Loading branch information
jamesbraza committed Aug 26, 2025
commit e15c52815727745a809e60ff74589182bedbed09
7 changes: 4 additions & 3 deletions src/paperqa/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
NumpyVectorStore,
VectorStore,
)
from paperqa.prompts import CANNOT_ANSWER_PHRASE
from paperqa.prompts import CANNOT_ANSWER_PHRASE, EMPTY_CONTEXTS
from paperqa.readers import read_doc
from paperqa.settings import MaybeSettings, get_settings
from paperqa.types import Doc, DocDetails, DocKey, PQASession, Text
Expand Down Expand Up @@ -774,9 +774,10 @@ async def aquery(
pre_str=pre_str,
)

if len(context_str.strip()) < 10: # noqa: PLR2004
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given empty context_str is 11-chars, we couldn't hit this case actually

if len(context_str.strip()) <= EMPTY_CONTEXTS:
answer_text = (
f"{CANNOT_ANSWER_PHRASE} this question due to insufficient information."
f"{CANNOT_ANSWER_PHRASE} this question due to"
f" {'having no papers' if not self.docs else 'insufficient information.'}."
)
answer_reasoning = None
else:
Expand Down
1 change: 1 addition & 0 deletions src/paperqa/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@
)

CONTEXT_OUTER_PROMPT = "{context_str}\n\nValid Keys: {valid_keys}"
EMPTY_CONTEXTS = len(CONTEXT_OUTER_PROMPT.format(context_str="", valid_keys="").strip())
CONTEXT_INNER_PROMPT_NOT_DETAILED = "{name}: {text}"
CONTEXT_INNER_PROMPT = f"{CONTEXT_INNER_PROMPT_NOT_DETAILED}\nFrom {{citation}}"
2 changes: 1 addition & 1 deletion tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ async def test_timeout(agent_test_settings: Settings, agent_type: str | type) ->
settings=agent_test_settings,
agent_type=agent_type,
)
# ensure that GenerateAnswerTool was called
# Ensure that GenerateAnswerTool was called in truncation's failover
assert response.status == AgentStatus.TRUNCATED, "Agent did not timeout"
assert CANNOT_ANSWER_PHRASE in response.session.answer

Expand Down