Skip to content

Commit

Permalink
Capping negative boost at 0.5 (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongsun96 authored Oct 24, 2023
1 parent 0a6c2af commit 890eb79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions backend/danswer/datastores/datastore_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@


DEFAULT_BATCH_SIZE = 30
BOOST_MULTIPLIER = 2 # Try to keep this consistent with Vespa


def translate_boost_count_to_multiplier(boost: int) -> float:
# Sigmoid function, maxed out at BOOST_MULTIPLIER
# 3 here stretches it out so we hit asymptote slower
return BOOST_MULTIPLIER / (1 + math.exp(-1 * boost / 3))
"""Mapping boost integer values to a multiplier according to a sigmoid curve
Piecewise such that at many downvotes, its 0.5x the score and with many upvotes
it is 2x the score. This should be in line with the Vespa calculation."""
# 3 in the equation below stretches it out to hit asymptotes slower
if boost < 0:
# 0.5 + sigmoid -> range of 0.5 to 1
return 0.5 + (1 / (1 + math.exp(-1 * boost / 3)))

# 2 x sigmoid -> range of 1 to 2
return 2 / (1 + math.exp(-1 * boost / 3))


def get_uuid_from_chunk(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ schema danswer_chunk {
}

function inline document_boost() {
# 0 to 2x score following sigmoid function stretched out by factor of 3
# 0.5 to 2x score: piecewise sigmoid function stretched out by factor of 3
# meaning requires 3x the number of feedback votes to have default sigmoid effect
expression: 2 / (1 + exp(-attribute(boost) / 3))
expression: if(attribute(boost) < 0, 0.5 + (1 / (1 + exp(-attribute(boost) / 3))), 2 / (1 + exp(-attribute(boost) / 3)))
}

function inline document_age() {
Expand Down

1 comment on commit 890eb79

@vercel
Copy link

@vercel vercel bot commented on 890eb79 Oct 24, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.