Repository navigation
feat(embeddings): first-class embeddings & reranker provider layer (#886) - #923
DhruvGarg111 wants to merge 6 commits into
Conversation
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]>
|
Reviewed — thanks for this, the provider layer is clean and nicely additive. I pushed one fix directly to the branch: Fixed (blocking):
Non-blocking follow-ups (worth a look before 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]>
|
Follow-up: wired the provider layer into SynapseKit Live (commit |
|
✅ Merged into |
Closes #886
Summary
Adds a first-class embeddings & reranker provider layer: a uniform async embeddings contract implemented by 9 hosted providers, plus a shared
RerankerABC with 3 new hosted rerankers.Embeddings (
BaseEmbeddingscontract)embed(texts)->(N, D)float32, L2-normalized rows (required by every vector-store backend)embed_one(text)->(D,)float32embed_batch(texts, batch_size)-> chunked, identical semanticsdimensions-> static output dim of the default model, no network callOpenAIEmbeddingstext-embedding-3-smallopenaiCohereEmbeddingsembed-v3(input-type aware)cohereVoyageEmbeddingsvoyage-3voyageJinaEmbeddingsjina-embeddings-v3(task LoRA)jinaGeminiEmbeddingstext-embedding-004geminiMistralEmbeddingsmistral-embedmistralNomicEmbeddingsnomic-embed-textnomicMixedbreadEmbeddingsmxbai-embed-largemixedbreadHuggingFaceEmbeddingsBAAI/bge-base-en-v1.5(Inference API / TEI)huggingfaceAll providers are lazy-imported behind optional extras (
pip install synapsekit[<provider>]); the core import guard stays green.SynapsekitEmbeddingsandONNXEmbeddingsare unchanged in behavior.Rerankers (
RerankerABC)retrieve(query, top_k)/retrieve_with_scores(query, top_k)async contract over a wrappedRetrieverVoyageReranker(rerank-2),JinaReranker(jina-reranker-v2),MixedbreadReranker(mxbai-rerank)CohereReranker/CrossEncoderRerankernow subclassRerankerwith unchanged constructors/behaviorTests & CI
ValueErrors) for every providerci.yml) needs no changes;respxis already a dev depVerification
pytest tests/embeddings tests/retrieval/test_rerankers.py— 56 passed, 2 skippedpytest tests/— passes (pre-existing env-only failures on this machine: shell-toolWinError 2tests, flaky mesh daemon PID test,nbformat-missing examples collection)ruff check+ruff format --check— cleanmypy— clean (521 files)deptry src/— clean