Implemented Vendor agnostic Embeddings support #241
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.
LiteLLM Embeddings Integration - Implementation Summary
Overview
Successfully implemented vendor-agnostic embeddings support for MCP Gateway Registry, integrating LiteLLM to enable multiple embedding provider options while maintaining backward compatibility with existing sentence-transformers implementation.
GitHub Issue: #223 - Integrate LiteLLM for Vendor-Agnostic Embeddings Model Support
What Was Implemented
1. Embeddings Abstraction Layer (
registry/embeddings/)Created a new module with vendor-agnostic embeddings client architecture:
registry/embeddings/client.pyEmbeddingsClient: Abstract base class defining the common interfaceencode(texts: List[str]) -> np.ndarray: Generate embeddingsget_embedding_dimension() -> int: Get embedding dimensionSentenceTransformersClient: Local embeddings implementationLiteLLMClient: Cloud-based embeddings via LiteLLMcreate_embeddings_client(): Factory function for creating clientsregistry/embeddings/__init__.pyregistry/embeddings/README.md2. Configuration Updates
registry/core/config.py(Already existed)Added embeddings configuration settings:
embeddings_provider: Provider selection (sentence-transformers/litellm)embeddings_model_name: Model identifierembeddings_model_dimensions: Expected dimensionembeddings_api_key: API key for cloud providersembeddings_secret_key: Alternative API key fieldembeddings_api_base: Custom API endpointembeddings_aws_region: AWS region for Bedrock.env.exampleAdded comprehensive embeddings configuration section:
3. FAISS Service Integration
registry/search/service.pyUpdated to use embeddings abstraction:
SentenceTransformerimport withEmbeddingsClientFaissService.embedding_modeltype annotation_load_embedding_model()to use factory function4. Dependencies
pyproject.tomlAdded
litellm>=1.50.0to project dependenciesBenefits Achieved
✅ Vendor Agnostic: Easy switching between local and cloud providers
✅ Backward Compatible: Existing deployments continue working without changes
✅ Configuration-Based: Switch providers via environment variables
✅ Cost Flexible: Choose between free local models and paid cloud APIs
✅ Performance Options: Select models based on speed/quality tradeoffs
✅ Privacy Control: Keep data local or use cloud services as needed
✅ Extensible: Easy to add new providers in the future
Supported Providers
Local (Sentence Transformers)
all-MiniLM-L6-v2(384 dim) - Default, fastall-mpnet-base-v2(768 dim) - High qualityCloud (via LiteLLM)
Testing
All integration tests passed:
Usage Examples
Default Configuration (Sentence Transformers)
# .env EMBEDDINGS_PROVIDER=sentence-transformers EMBEDDINGS_MODEL_NAME=all-MiniLM-L6-v2 EMBEDDINGS_MODEL_DIMENSIONS=384OpenAI Configuration
# .env EMBEDDINGS_PROVIDER=litellm EMBEDDINGS_MODEL_NAME=openai/text-embedding-3-small EMBEDDINGS_MODEL_DIMENSIONS=1536 EMBEDDINGS_API_KEY=sk-...Amazon Bedrock Configuration
Migration Path
For Existing Users
No action required! The default configuration maintains existing behavior:
For New Users
.envFiles Modified
registry/embeddings/client.py- New file (378 lines)registry/embeddings/__init__.py- New file (16 lines)registry/embeddings/README.md- New file (comprehensive docs)registry/search/service.py- Updated imports and_load_embedding_model()registry/core/config.py- Already had config (no changes needed).env.example- Added embeddings section (39 lines)pyproject.toml- Added litellm dependency (1 line)Code Quality
Next Steps
Recommended Enhancements
Future Possibilities
Documentation
registry/embeddings/README.md- Complete module documentation.env.example- Configuration examples and commentsdocs/llms.txt- Should be updated to mention vendor-agnostic embeddingsVerification Checklist
Conclusion
The LiteLLM integration has been successfully implemented, providing MCP Gateway Registry users with flexible, vendor-agnostic embeddings generation. The implementation maintains full backward compatibility while opening up new possibilities for cloud-based embeddings providers.
Users can now choose the best embeddings solution for their needs - whether that's free local models for high-volume usage, or high-quality cloud APIs for maximum accuracy.