Skip to content

Commit f7adf0c

Browse files
authored
Safe default for Context.score (#1185)
1 parent ee2137b commit f7adf0c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/paperqa/types.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ class Context(BaseModel):
216216
# or useful excerpts of text
217217
model_config = ConfigDict(extra="allow")
218218

219+
# Value was chosen to be below a 0-10 scale, making the 'unset' nature obvious
220+
UNSET_RELEVANCE: ClassVar[int] = -1
221+
219222
id: str = Field(
220223
default=AUTOPOPULATE_VALUE,
221224
description="Unique identifier for the context. Auto-generated if not provided.",
@@ -224,8 +227,8 @@ class Context(BaseModel):
224227
context: Annotated[str, StringConstraints(strip_whitespace=True)] = Field(
225228
description=(
226229
"Summary of the text with respect to a question."
227-
" Can be an empty string if a summary is not useful"
228-
" (which should accompany a score of 0)."
230+
" Can be an empty string if a summary is not useful/irrelevant"
231+
" (which should be paired with a score of 0)."
229232
)
230233
)
231234
question: str | None = Field(
@@ -236,7 +239,15 @@ class Context(BaseModel):
236239
),
237240
)
238241
text: Text
239-
score: int = 5
242+
score: int = Field(
243+
default=UNSET_RELEVANCE,
244+
description=(
245+
"Relevance score for this context to the question."
246+
" The range used here is 0-10, where 0 is 'irrelevant',"
247+
" 1 is barely relevant, and 10 is most relevant."
248+
" The default is -1 to have a 'sorting safe' default as sub-relevant."
249+
),
250+
)
240251

241252
CONTEXT_ENCODING_LENGTH: ClassVar[int] = 500 # chars
242253
ID_HASH_LENGTH: ClassVar[int] = 8 # chars

0 commit comments

Comments
 (0)