feat(reranker): support Bearer auth and the score response field in HttpReranker - #92
Open
RobertSigmundsson wants to merge 1 commit into
Conversation
… wire recall to BGE-M3 /rerank) The self-hosted BGE-M3 /rerank service requires Bearer auth and returns a 'score' field; the OpenAI-compatible HttpReranker sent no auth and read 'relevance_score'. Add optional Bearer (SURREAL_MEMORY_RERANKER_API_KEY / BGE_M3_API_KEY) and accept both score fields, so recall can rerank over the BGE-M3 service (llamastash still works). (cherry picked from commit d17a310) (cherry picked from commit 1d29f67) (cherry picked from commit a9b40be)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
HttpRerankersendsContent-Typeonly, and parses the response withfloat(r["relevance_score"]). Two consequences:localhost)cannot be used at all.
score— including BGE-M3's/rerank— raiseKeyErrorinstead of reranking.
Change
api_keyconstructor argument, falling back toSURREAL_MEMORY_RERANKER_API_KEYthenBGE_M3_API_KEY. An empty key sends noAuthorizationheader, so llamastash / llama.cppdeployments that need none are unaffected.
float(r.get("relevance_score", r.get("score", 0.0)))— OpenAI-compatible field first,scoreas fallback.Why upstream benefits
Two small compatibility gaps that each make a whole class of rerank endpoints unusable. The change is
strictly additive: existing unauthenticated,
relevance_score-returning endpoints behave exactly as before.Evidence
origin/mainimport surreal_memoryruff checkruff format --checkmypy src/ --ignore-missing-importspytest -m "not stress" -n autoRisks / notes for the reviewer
urlopentest covering"no key → no header", "key → header", and both response field names if upstream wants it before merge.
r.get("score", 0.0)defaults a missing score to0.0rather than raising. That is deliberatelylenient — a malformed row sorts last instead of killing the whole rerank — but it is a judgement call
worth a reviewer's opinion.
# noqa: S310comment was retightened from "fixed local llamastash endpoint" to"fixed local rerank endpoint" since the endpoint is no longer llamastash-specific.