Skip to content

fix(rerank): exact-pin flashrank + pin PALACE_RERANK_MODEL — freeze deployed ranking - #204

Merged
jphein merged 1 commit into
mainfrom
fix/rerank-determinism-pin
May 31, 2026
Merged

fix(rerank): exact-pin flashrank + pin PALACE_RERANK_MODEL — freeze deployed ranking#204
jphein merged 1 commit into
mainfrom
fix/rerank-determinism-pin

Conversation

@jphein

@jphein jphein commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes the latent risk flagged by the determinism probe (#203). That probe proved the /search rerank stage is deterministic for a fixed model — but the model wasn't fully frozen:

  • requirements.txt pinned flashrank>=0.2.10 (a floor), so a fresh deploy could pull a newer flashrank with different bundled ONNX weights / tokenizer.
  • PALACE_RERANK_MODEL was unset (relying on the code default).

Either could silently reorder /search top-5 across a deploy — a real reorder, not a nondeterministic one. This freezes the model.

Changes

  • requirements.txt: flashrank>=0.2.10flashrank==0.2.10. Pinned to the version currently deployed on familiar (verified read-only) — no behavior change, just frozen. Comment documents the why + "bump deliberately, re-run the determinism test."
  • palace-daemon.service: add Environment=PALACE_RERANK_MODEL=ms-marco-TinyBERT-L-2-v2 (the existing code default, now explicit) so deployed ranking is byte-stable across deploys.
  • tests/test_rerank.py::TestRerankPinHardening: 2 guard tests asserting the exact pin (==, not >=) and the systemd model env stay in place — a future floor-pin regression fails CI.

Safety

No production code touched. Both pins point at what's already running, so deployed behavior is unchanged — this only prevents a future deploy from drifting. flashrank version confirmed 0.2.10 on familiar (read-only check); no prod restart, no writes.

Tests

tests/test_rerank.py 19/19 pass (17 prior incl. TestRerankDeterminism, + 2 new pin guards). Additive.

References docs/evals/2026-05-30-retrieval-determinism.md (the #203 finding).

🤖 Generated with Claude Code

…eployed ranking

The determinism probe (#203) proved the /search rerank stage is deterministic
for a FIXED model, but flagged a latent risk: requirements.txt pinned
`flashrank>=0.2.10` (a floor) and PALACE_RERANK_MODEL was unset, so a fresh
deploy could pull a newer flashrank with different bundled ONNX weights /
tokenizer — which WOULD silently reorder /search top-5 across that deploy.

Freeze the model:
- requirements.txt: flashrank>=0.2.10 → flashrank==0.2.10 (the currently
  deployed version on familiar — no behavior change, just frozen).
- palace-daemon.service: add Environment=PALACE_RERANK_MODEL=ms-marco-TinyBERT-L-2-v2
  (the code default, now explicit so deployed ranking is byte-stable).
- tests/test_rerank.py::TestRerankPinHardening: assert the exact pin + the
  systemd model env stay in place, so a future floor-pin regression fails CI.

No production code touched; deployed behavior unchanged (pins to what's
already running). See docs/evals/2026-05-30-retrieval-determinism.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 30, 2026 22:36
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements hardening measures to ensure the determinism of the /search reranking stage. By strictly pinning the flashrank dependency and explicitly defining the rerank model in the service configuration, the changes eliminate the risk of silent ranking reorders caused by environment drift during new deployments.

Highlights

  • Dependency Pinning: Updated requirements.txt to use an exact version pin (flashrank==0.2.10) instead of a floor version to prevent unexpected model or tokenizer changes during deployment.
  • Environment Configuration: Explicitly set the PALACE_RERANK_MODEL environment variable in palace-daemon.service to ensure the reranking model remains consistent across all deployments.
  • Regression Testing: Added TestRerankPinHardening to the test suite to programmatically verify that the dependency and environment pins remain in place, preventing future regressions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request ensures retrieval determinism across deployments by pinning the flashrank dependency to an exact version (==0.2.10) in requirements.txt and explicitly setting the PALACE_RERANK_MODEL environment variable in palace-daemon.service. It also introduces unit tests to enforce these pins. The feedback suggests specifying encoding="utf-8" when opening these files in the new tests to prevent potential UnicodeDecodeError on systems where the default encoding is not UTF-8.

Comment thread tests/test_rerank.py
"""

def test_flashrank_is_exact_pinned(self):
with open(os.path.join(_ROOT, "requirements.txt")) as fh:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Both requirements.txt and palace-daemon.service contain non-ASCII characters (such as the em-dash ). Opening these files without specifying an explicit encoding can lead to a UnicodeDecodeError on platforms where the default system encoding is not UTF-8 (e.g., Windows or environments with a restricted locale like LANG=C). Specifying encoding="utf-8" ensures the tests are portable and robust across different environments.

Suggested change
with open(os.path.join(_ROOT, "requirements.txt")) as fh:
with open(os.path.join(_ROOT, "requirements.txt"), encoding="utf-8") as fh:

Comment thread tests/test_rerank.py
self.assertNotIn(">=", lines[0])

def test_systemd_unit_pins_rerank_model(self):
with open(os.path.join(_ROOT, "palace-daemon.service")) as fh:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Specify encoding="utf-8" when opening palace-daemon.service to prevent potential UnicodeDecodeError on systems where the default encoding is not UTF-8, especially since the file contains non-ASCII characters like the em-dash .

Suggested change
with open(os.path.join(_ROOT, "palace-daemon.service")) as fh:
with open(os.path.join(_ROOT, "palace-daemon.service"), encoding="utf-8") as fh:

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@jphein
jphein merged commit 86b4347 into main May 31, 2026
1 check failed
@jphein
jphein deleted the fix/rerank-determinism-pin branch May 31, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants