Skip to content

Commit 2ca6b8f

Browse files
authored
Expose answer evidence score cutoff as config (#1031)
1 parent 70d1411 commit 2ca6b8f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ will return much faster than the first query and we'll be certain the authors ma
885885
| `answer.max_concurrent_requests` | `4` | Max concurrent requests to LLMs. |
886886
| `answer.answer_filter_extra_background` | `False` | Whether to cite background info from model. |
887887
| `answer.get_evidence_if_no_contexts` | `True` | Allow lazy evidence gathering. |
888+
| `answer.evidence_relevance_score_cutoff` | `1` | Cutoff evidence relevance score to include in the answer context (inclusive) |
888889
| `parsing.chunk_size` | `5000` | Characters per chunk (0 for no chunking). |
889890
| `parsing.page_size_limit` | `1,280,000` | Character limit per page. |
890891
| `parsing.pdfs_use_block_parsing` | `False` | Opt-in flag for block-based PDF parsing over text-based PDF parsing. |

src/paperqa/docs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,12 @@ async def aquery( # noqa: PLR0912
768768
contexts,
769769
key=lambda x: (-x.score, x.text.name),
770770
)[: answer_config.answer_max_sources]
771-
# remove any contexts with a score of 0
772-
filtered_contexts = [c for c in filtered_contexts if c.score > 0]
771+
# remove any contexts with a score below the cutoff
772+
filtered_contexts = [
773+
c
774+
for c in filtered_contexts
775+
if c.score >= answer_config.evidence_relevance_score_cutoff
776+
]
773777

774778
# shim deprecated flag
775779
# TODO: remove in v6

src/paperqa/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ class AnswerSettings(BaseModel):
7777
default=True,
7878
description="Whether to use retrieval instead of processing all docs.",
7979
)
80+
# no validator because you can set the range in a prompt
81+
evidence_relevance_score_cutoff: int = Field(
82+
default=1,
83+
ge=0,
84+
description=(
85+
"Relevance score cutoff for evidence retrieval, default is 1, meaning"
86+
" only evidence with relevance score >= 1 will be used."
87+
),
88+
)
8089
evidence_summary_length: str = Field(
8190
default="about 100 words", description="Length of evidence summary."
8291
)

0 commit comments

Comments
 (0)