Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions src/paperqa/contrib/openreview_paper_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ async def fetch_relevant_papers(self, question: str) -> dict[str, Any]:
submissions = self.get_submissions()
submission_string = self.create_submission_string(submissions)

if len(submission_string) > self.settings.parsing.chunk_size:
chunk_size = self.settings.parsing.reader_config["chunk_chars"]
if len(submission_string) > chunk_size:
chunks = [
submission_string[i : i + self.settings.parsing.chunk_size]
for i in range(
0, len(submission_string), self.settings.parsing.chunk_size
)
submission_string[i : i + chunk_size]
for i in range(0, len(submission_string), chunk_size)
]
else:
chunks = [submission_string]
Expand Down
17 changes: 12 additions & 5 deletions src/paperqa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ParsingSettings(BaseModel):
default=250, description="Number of characters to overlap chunks."
)
reader_config: dict[str, Any] = Field(
default_factory=dict,
default_factory=lambda: {"chunk_chars": 5000, "overlap": 250},
description="Optional keyword arguments for the document reader.",
examples=[{"dpi": 300}],
)
Expand Down Expand Up @@ -349,6 +349,9 @@ class ParsingSettings(BaseModel):

@model_validator(mode="after")
def _deprecated_field(self) -> Self:
default_reader_config = (
type(self).model_fields["reader_config"].default_factory() # type: ignore[call-arg,misc]
)
if (
self.pdfs_use_block_parsing
!= type(self).model_fields["pdfs_use_block_parsing"].default
Expand All @@ -370,7 +373,9 @@ def _deprecated_field(self) -> Self:
category=DeprecationWarning,
stacklevel=2,
)
if "chunk_chars" not in self.reader_config:
if "chunk_chars" not in self.reader_config or self.reader_config[
"chunk_chars"
] == default_reader_config.get("chunk_chars"):
self.reader_config["chunk_chars"] = self.chunk_size
if self.overlap != type(self).model_fields["overlap"].default:
warnings.warn(
Expand All @@ -380,7 +385,9 @@ def _deprecated_field(self) -> Self:
category=DeprecationWarning,
stacklevel=2,
)
if "overlap" not in self.reader_config:
if "overlap" not in self.reader_config or self.reader_config[
"overlap"
] == default_reader_config.get("overlap"):
self.reader_config["overlap"] = self.overlap
return self

Expand Down Expand Up @@ -972,8 +979,8 @@ def get_index_name(self) -> str:
str(self.agent.index.use_absolute_paper_directory),
self.embedding,
str(self.parsing.parse_pdf), # Don't use __name__ as lambda wouldn't differ
str(self.parsing.chunk_size),
str(self.parsing.overlap),
str(self.parsing.reader_config["chunk_chars"]),
str(self.parsing.reader_config["overlap"]),
self.parsing.chunking_algorithm,
str(self.parsing.multimodal),
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ async def test_propagate_options(agent_test_settings: Settings) -> None:
assert len(result.contexts) >= 2, "Test expects a few contexts"
# Subtract 2 to allow tolerance for chunks with leading/trailing whitespace
num_contexts_sufficient_length = sum(
len(c.context) >= agent_test_settings.parsing.chunk_size - 2
len(c.context) >= agent_test_settings.parsing.reader_config["chunk_chars"] - 2
for c in result.contexts
)
# Check most contexts have the expected length
Expand Down