Skip to content

feat(embeddings): first-class embeddings & reranker provider layer (#886) - #923

Closed
DhruvGarg111 wants to merge 6 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-886-embeddings-rerankers
Closed

DhruvGarg111 wants to merge 6 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-886-embeddings-rerankers

Conversation

@DhruvGarg111

Copy link
Copy Markdown
Collaborator

Closes #886

Summary

Adds a first-class embeddings & reranker provider layer: a uniform async embeddings contract implemented by 9 hosted providers, plus a shared Reranker ABC with 3 new hosted rerankers.

Embeddings (BaseEmbeddings contract)

  • embed(texts) -> (N, D) float32, L2-normalized rows (required by every vector-store backend)
  • embed_one(text) -> (D,) float32
  • embed_batch(texts, batch_size) -> chunked, identical semantics
  • dimensions -> static output dim of the default model, no network call
Provider Class Default model Dims Extra
OpenAI OpenAIEmbeddings text-embedding-3-small 1536 openai
Cohere CohereEmbeddings embed-v3 (input-type aware) 1024 cohere
Voyage AI VoyageEmbeddings voyage-3 1024 voyage
Jina AI JinaEmbeddings jina-embeddings-v3 (task LoRA) 1024 jina
Google Gemini GeminiEmbeddings text-embedding-004 768 gemini
Mistral MistralEmbeddings mistral-embed 1024 mistral
Nomic NomicEmbeddings nomic-embed-text 768 nomic
mixedbread MixedbreadEmbeddings mxbai-embed-large 1024 mixedbread
Hugging Face HuggingFaceEmbeddings BAAI/bge-base-en-v1.5 (Inference API / TEI) 768 huggingface

All providers are lazy-imported behind optional extras (pip install synapsekit[<provider>]); the core import guard stays green. SynapsekitEmbeddings and ONNXEmbeddings are unchanged in behavior.

Rerankers (Reranker ABC)

  • retrieve(query, top_k) / retrieve_with_scores(query, top_k) async contract over a wrapped Retriever
  • New: VoyageReranker (rerank-2), JinaReranker (jina-reranker-v2), MixedbreadReranker (mxbai-rerank)
  • CohereReranker / CrossEncoderReranker now subclass Reranker with unchanged constructors/behavior

Tests & CI

  • Generic contract suite (dimensions, lazy-import errors, missing-key ValueErrors) for every provider
  • Per-provider respx HTTP-contract tests (request body/headers, parsing, reordering) — no live keys, no network
  • Reranker request/reorder/empty/missing-key tests
  • CI (ci.yml) needs no changes; respx is already a dev dep

Verification

  • pytest tests/embeddings tests/retrieval/test_rerankers.py — 56 passed, 2 skipped
  • pytest tests/ — passes (pre-existing env-only failures on this machine: shell-tool WinError 2 tests, flaky mesh daemon PID test, nbformat-missing examples collection)
  • ruff check + ruff format --check — clean
  • mypy — clean (521 files)
  • deptry src/ — clean

Introduce a uniform async embeddings contract (BaseEmbeddings) with
embed/embed_one/embed_batch, static per-provider dimensions, and
L2-normalized output, plus 9 hosted providers: OpenAI, Cohere
(input-type aware), Voyage, Jina (task LoRA), Gemini, Mistral, Nomic,
mixedbread, and Hugging Face (Inference API / TEI). OpenAI-compatible
providers share an HTTPEmbeddings transport. SynapsekitEmbeddings now
subclasses BaseEmbeddings with no behavior change.
Introduce a shared Reranker abstract base (async retrieve /
retrieve_with_scores over a wrapped Retriever) and three hosted
rerankers: Voyage rerank-2, Jina reranker-v2, and mixedbread
mxbai-rerank. CohereReranker and CrossEncoderReranker now subclass
Reranker with unchanged constructors and behavior.
Register all 9 hosted embeddings providers in the top-level lazy import
map and the embeddings/retrieval __init__ exports; eager-export the new
rerankers. Add voyage/jina/nomic/mixedbread extras, extend gemini and
huggingface extras for the embeddings SDKs, add httpx to the all extra,
and cover the new modules in mypy overrides and deptry ignores.
Add a generic contract suite (dimensions, lazy import errors, missing
key ValueErrors) and per-provider respx HTTP-contract tests for
OpenAI, Cohere, Voyage, Jina, Gemini, Mistral, Nomic, mixedbread, and
Hugging Face, plus request/reorder/empty/missing-key tests for the
Voyage/Jina/mixedbread rerankers and the Reranker ABC. No live keys or
network access.
…rface)

`client.models.embed_content` is synchronous in google-genai; awaiting it
raises TypeError against the real API. Use `client.aio.models.embed_content`,
matching the async surface used everywhere else in the repo. The provider
test previously made the sync method awaitable with AsyncMock, hiding the
bug; replace it with a hand-written async fake (no mock) that asserts the
`.aio` surface and the coroutine contract.

Fixes SynapseKit#926

Co-authored-by: Dhruv Garg <[email protected]>
@AmitoVrito

Copy link
Copy Markdown
Collaborator

Reviewed — thanks for this, the provider layer is clean and nicely additive. I pushed one fix directly to the branch:

Fixed (blocking):

  • GeminiEmbeddings awaited client.models.embed_content, which is synchronous in google-genai and raises TypeError against the real API — switched to client.aio.models.embed_content (bug(embeddings): GeminiEmbeddings awaits a synchronous google-genai call (TypeError at runtime) #926). The provider test had made the sync method awaitable with AsyncMock, which hid the bug; replaced it with a hand-written async fake (also brings it in line with the no-mock testing rule) that asserts the .aio surface and the coroutine contract.

Non-blocking follow-ups (worth a look before merge):

  • Sync httpx.Client in http.py/huggingface.py/rerankers is never closed (leak) and could just be httpx.AsyncClient + await instead of the to_thread hop.
  • NomicEmbeddings.embed_one mutates self._request_extra and restores in finally — races under concurrent calls on one instance; pass the override through instead.
  • OpenAIEmbeddings hardcodes dimensions=1536, which silently truncates text-embedding-3-large.
  • CohereReranker.retrieve calls the sync client in an async def without to_thread (pre-existing).
  • No EventBus/Live wiring yet — per our "keep Live updated" rule, embedding/rerank activity should publish to the bus. A docs page is also expected at merge.

… Live

The new embeddings/reranker provider layer (SynapseKit#886) published nothing to the
Live EventBus, so embedding and rerank activity was invisible in the glass-box
dashboard. Auto-instrument the layer the same way every other subsystem is
wired: patch BaseEmbeddings.embed (covering all 9 providers and future
subclasses) to publish `embeddings.embed`, and the Reranker hierarchy's
retrieve/retrieve_with_scores to publish `rerank`, with provider/count attrs.
Async contract preserved; no-op when Live is off. Adds a no-mock test with a
real BaseEmbeddings subclass and a real Reranker over an in-memory retriever,
covering the coroutine contract and the error path. Also records the layer and
the Gemini async fix in the changelog.

Co-authored-by: Dhruv Garg <[email protected]>
@AmitoVrito

Copy link
Copy Markdown
Collaborator

Follow-up: wired the provider layer into SynapseKit Live (commit 428a5be) — BaseEmbeddings.embed and every Reranker now publish embeddings.embed / rerank events via the auto-instrumenter, so embedding/rerank activity shows in the dashboard. Added a no-mock test and a CHANGELOG entry (feature + the Gemini fix). This clears the EventBus follow-up from my review above.

AmitoVrito added a commit that referenced this pull request Aug 12, 2026
…ive-shell

Integrate #923 + #924 + #925: embeddings layer, Hive Mode, Agent OS Shell
@AmitoVrito

Copy link
Copy Markdown
Collaborator

✅ Merged into main via the integration PR #932 (commit 428a5be and its ancestors are in main). GitHub labelled this Closed rather than Merged only because it landed through the batch integration branch, not because it was rejected — the full embeddings & reranker layer, the Gemini async fix, and the Live wiring are all shipped. Thank you @DhruvGarg111! 🙌

ayushbhatt1224 pushed a commit to ayushbhatt1224/SynapseKit that referenced this pull request Aug 18, 2026
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.

[Epic] First-class embeddings & reranker provider layer

2 participants