Skip to content

[lore 5/7] Retriever + hybrid (BM25+vector RRF)#6

Merged
kunallanjewar merged 2 commits into
mainfrom
quest-5-retrieve-hybrid
Apr 28, 2026
Merged

[lore 5/7] Retriever + hybrid (BM25+vector RRF)#6
kunallanjewar merged 2 commits into
mainfrom
quest-5-retrieve-hybrid

Conversation

@kunallanjewar
Copy link
Copy Markdown
Contributor

Summary

  • Adds pkg/lore/retrieve/retrieve.go: the Retriever interface with Search(ctx, query, opts) ([]SearchHit, error).
  • Adds pkg/lore/retrieve/rrf/rrf.go: Reciprocal Rank Fusion (Fuse(rankings [][]int64, k int) []ScoredID), k=60 default, deterministic tie-breaking by ID.
  • Adds pkg/lore/retrieve/bm25/bm25.go: lexical-only Ranker (wraps store.SearchText), OTel span lore.retrieve.bm25.
  • Adds pkg/lore/retrieve/vector/vector.go: semantic-only Searcher (embed query + vstore.Search + store.Get hydration), OTel span lore.retrieve.vector.
  • Adds pkg/lore/retrieve/hybrid/hybrid.go: hybrid.New(store, embedder, vstore, opts...) fuses both arms via RRF; graceful partial-failure fallback (one arm down keeps the other); OTel spans lore.retrieve.search, lore.retrieve.bm25, lore.retrieve.vector, lore.retrieve.fuse.
  • Adds pkg/lore/retrieve/hybrid/hybrid_test.go: 9 tests against a 10-entry fixed corpus with a mock embedder (no ONNX Runtime required in CI).

Design

Both arms run sequentially. When one arm fails, a slog.Warn is emitted and Search falls through to the surviving arm. When both fail, the BM25 error is returned (vector error in message). Entry hydration via store.Get happens after fusion to avoid fetching entries that will be discarded.

Options: WithLogger, WithTracer, WithRRFK(int), WithCandidatePoolSize(int).

Test plan

  • go test -race -count=1 ./... passes locally
  • gofmt -l . no diffs
  • go vet ./... clean
  • go build ./... clean
  • No internal identifiers in public artifacts
  • CI green (in progress)

…ybrid components

- pkg/lore/retrieve/retrieve.go: Retriever interface (Search method)
- pkg/lore/retrieve/rrf/rrf.go: Reciprocal Rank Fusion with k=60 default
- pkg/lore/retrieve/bm25/bm25.go: lexical ranker (store.SearchText)
- pkg/lore/retrieve/vector/vector.go: semantic ranker (embed + vstore.Search)
- pkg/lore/retrieve/hybrid/hybrid.go: hybrid composer (BM25+vector via RRF)
- pkg/lore/retrieve/hybrid/hybrid_test.go: tests with mock embedder

All tests pass with -race; no ONNX Runtime required in CI.
@kunallanjewar kunallanjewar marked this pull request as ready for review April 28, 2026 15:47
@kunallanjewar kunallanjewar merged commit 51503d5 into main Apr 28, 2026
4 checks passed
@kunallanjewar kunallanjewar deleted the quest-5-retrieve-hybrid branch April 28, 2026 15:48
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