Skip to content

feat(sdk/retrieval/scoring): public CosineSim + RRF helpers [skip-tag:sdk]#80

Merged
lIang70 merged 1 commit into
mainfrom
feat/sdk-retrieval-scoring
May 8, 2026
Merged

feat(sdk/retrieval/scoring): public CosineSim + RRF helpers [skip-tag:sdk]#80
lIang70 merged 1 commit into
mainfrom
feat/sdk-retrieval-scoring

Conversation

@lIang70

@lIang70 lIang70 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Prep for P4 — sdkx/retrieval/fs.

Lift the small scoring kernel (cosine similarity + RRF/WeightedFusion algorithm cores) out of two package-private hideouts so the upcoming fs-backed retrieval Index — and any future sdkx backend or tool — can import them directly instead of vendoring duplicates or constructing a pipeline.Stage just to invoke the algorithm.

New helper Replaces
`scoring.CosineSim` / `DotProduct` / `EuclideanDist` private `sdk/retrieval/memory.cosineSim`
`scoring.RRF(rankedLists, k)` algorithm core inside `pipeline.RRFFusion.Run`
`scoring.WeightedFusion(lanes, weights)` algorithm core inside `pipeline.WeightedFusion.Run`

Existing call sites delegate; behaviour is identical. `sdk/retrieval/memory.cosineSim` shrinks to a 1-line wrapper; `pipeline.RRFFusion.Run` and `pipeline.WeightedFusion.Run` forward the lane map.

Test plan

  • `go vet ./...` (sdk module) clean
  • `go test ./retrieval/... ./recall/... ./knowledge/... -count=1` all green — no behaviour drift in any consumer
  • New `sdk/retrieval/scoring` package has table-driven tests for cosine (identical/orthogonal/opposite/zero/length-mismatch), dot product, euclidean, RRF basic order, RRF default k, RRF empty, weighted fusion basic + degenerate lanes + missing weight default

Notes

  • Pure additive in sdk — no symbol removed, no public surface deprecated.
  • `[skip-tag:sdk]` because this is the first PR of an accumulation chain leading into `sdkx/retrieval/fs`. Tag will be cut once the prep + sdkx fs work lands.

Made with Cursor

…lpers

Lift the kernel of the retrieval-stack scoring math out of two
package-private hideouts (sdk/retrieval/memory.cosineSim and the
algorithm bodies inside pipeline.RRFFusion / pipeline.WeightedFusion)
into a small, dependency-light scoring package other backends and
tools can import without forcing them through a pipeline.Stage.

- CosineSim, DotProduct, EuclideanDist for vector similarity.
- RRF (with DefaultRRFK = 60) and WeightedFusion as pure functions
  over [][]retrieval.Hit and map[string][]retrieval.Hit respectively.
- Existing call sites delegate, preserving identical behaviour:
  * sdk/retrieval/memory.cosineSim is a 1-line wrapper.
  * pipeline.{RRFFusion,WeightedFusion}.Run forward to scoring.

Pure additive in sdk; no symbol removed and no public surface
deprecated. Prep PR for sdkx/retrieval/fs (P4) so the upcoming
fs-backed Index doesn't have to vendor or duplicate this math.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lIang70
lIang70 merged commit 7e61d73 into main May 8, 2026
17 checks passed
@lIang70
lIang70 deleted the feat/sdk-retrieval-scoring branch May 8, 2026 09:35
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.

1 participant