Repository navigation
fix(pinecone): accept tie-level search reordering when qualifying partition copies - #24400
Merged
Merged
Conversation
…tition copies The partition operator compared the old namespace's and the new bucket's top-10 IDs for exact order. Pinecone scores the same record slightly differently in different namespaces (2-4e-4 measured on the dev index), so near-tied neighbours swap and the check rejected complete, verified copies. The chance grows with the owner's vector count, so heavy owners, whose queries cost the most, could not be migrated. Search parity now requires shared IDs to score within 1e-3, allows an ID in only one list solely at the cutoff when tied with the other list's lowest score, and allows opposite ranking only between pairs tied within 1e-3. Exact payload and inventory parity are unchanged. The operator also keeps the fixed reason text of MigrationNotReady/PartitionConflict in receipts and journals; those messages are static strings from our own code. Only the operator scripts import this module; serving code is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
1 issue found across 3 files
Confidence score: 3/5
- A NaN provider score makes the parity comparison evaluate false, so
backend/database/pinecone_partition_migration.pycan accept mismatched or reversed results. Reject non-finite scores before the parity checks.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/database/pinecone_partition_migration.py">
<violation number="1" location="backend/database/pinecone_partition_migration.py:76">
P1: Non-finite provider scores bypass every parity check: `float('nan')` makes `abs(...) > tolerance` false, so a NaN score can qualify even when its counterpart differs or the order is reversed. Reject scores with `math.isfinite` before comparing them.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| the order was exactly identical. | ||
| """ | ||
| try: | ||
| old_scores = {match['id']: float(match['score']) for match in old} |
There was a problem hiding this comment.
P1: Non-finite provider scores bypass every parity check: float('nan') makes abs(...) > tolerance false, so a NaN score can qualify even when its counterpart differs or the order is reversed. Reject scores with math.isfinite before comparing them.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/database/pinecone_partition_migration.py, line 76:
<comment>Non-finite provider scores bypass every parity check: `float('nan')` makes `abs(...) > tolerance` false, so a NaN score can qualify even when its counterpart differs or the order is reversed. Reject scores with `math.isfinite` before comparing them.</comment>
<file context>
@@ -58,6 +58,45 @@ def normalize(value: Any) -> Any:
+ the order was exactly identical.
+ """
+ try:
+ old_scores = {match['id']: float(match['score']) for match in old}
+ new_scores = {match['id']: float(match['score']) for match in new}
+ except (KeyError, TypeError, ValueError) as error:
</file context>
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.
Why
The Pinecone owner-partition operator (#24315) ends each qualification by querying the owner's old
namespace and new bucket with a few of the owner's own vectors, and it required the two top-10 ID lists to
be identical in order. Pinecone scores the same record slightly differently in different namespaces, so
near-tied neighbours swap and the operator refuses copies that are complete and exactly verified.
Measured on
memories-backend-devwith a loopback Firestore emulator and synthetic owners (dense random3072-d vectors), after a complete copy whose payload digests all matched:
The odds of a near-tie in a top-10 rise with an owner's vector count, so the check blocks exactly the
heavy owners whose queries cost the most. Production shows the same signature: the 11-02 rollout journal
recorded 29
bounded_search_convergencemismatches, and those 29 keys are exactly the routes it left inqualification_failed.What changes
search_parity()replaces the exact list comparison. IDs present in both lists must score within 1e-3(2.5x the largest drift measured). An ID may appear in only one list solely at the cutoff, tied with the
other list's lowest score. Two IDs may rank in opposite order only when their scores are within 1e-3.
Anything else still raises
MigrationNotReady.query_checksrecords whether the order was exact.record byte-for-byte. This check only bounds ranking drift.
MigrationNotReady/PartitionConflictin receipts and ownerjournals. These are fixed strings from our own code, never provider text, and without them a failed batch
can't be diagnosed.
tie) with per-namespace score jitter.
Only
scripts/migrate_pinecone_partitions.pyandscripts/qualify_pinecone_partitions.pyimport thismodule. Serving code and every deployed runtime are unchanged, so no deploy is needed.
Verification
backend/test.shwithBACKEND_UNIT_TEST_FILE_LIST=test_pinecone_partition_migration.py: 52 passed,including the new near-tie, drift and
search_paritycases. The existing reversed-order case still failsclosed.
test_migrate_pinecone_partitions.py: 23 passed.test_qualification_script_direct_execution_reaches_safety_gatetimed out locally: the script reaches the expected gate error, but takes about 10s of wall time on a host at
load 60 (about 1s CPU). That script is untouched here.
memories-backend-devwith a loopback Firestoreemulator, all steps passed (2026-11-02 14:59Z):
qualify_pinecone_partitions.py(7 families x 3migrate/update/rollback cycles with a shared-bucket owner, cleanup verified); the operator CLI end to end on
two colliding synthetic owners with 2-230 dense vectors per family (inventory, budget stop then
--resume,apply, serving write after cutover, rollback, re-apply, idempotent rerun, cleanup verified); and the opt-in
action-item user-path test (run with a deterministic local embedding in place of OpenAI, because this lane
holds no OpenAI key; the router, Firestore, owner routing, migration and Pinecone calls were real). Before this change the same CLI run refused 6 of 7 families with
Search result order differs.Product invariants: none (operator-only module).
Failure-Class: none
Rationale: this is a parity-check tolerance in an operator tool, not a recurrence of a catalogued
serving failure class. The nearest entries (FC-split-mutation-authority, FC-test-double-accepts-payload-store-rejects)
do not describe it: the fake's constant score did hide the defect, but it accepted too little, not a payload
production rejects.
🤖 Generated with Claude Code