mem0
mem0 copied to clipboard
Enhancement: Integrate Together AI support in TS sdk and improve test configura…
Add Together AI Embeddings Support to mem0 TypeScript SDK
Description
This PR adds comprehensive Together AI embeddings support to the mem0 TypeScript SDK, bringing feature parity with the Python SDK. The implementation includes a new TogetherEmbedder class that integrates seamlessly with the existing embeddings architecture.
Key Features:
- Full Together AI embeddings API integration using the official
together-ainpm package - Support for all Together AI embedding models (M2-BERT variants, BGE models)
- Consistent API with other embedders in the SDK
- Comprehensive test coverage with conditional execution
- Complete documentation and usage examples
- Proper TypeScript typing and error handling
Models Supported:
togethercomputer/m2-bert-80M-2k-retrieval(768 dims, 2K context)togethercomputer/m2-bert-80M-8k-retrieval(768 dims, 8K context) - Defaulttogethercomputer/m2-bert-80M-32k-retrieval(768 dims, 32K context)BAAI/bge-large-en-v1.5(1024 dims, 512 context)BAAI/bge-base-en-v1.5(768 dims, 512 context)
This addresses the gap where Together AI embeddings were available in the Python SDK but missing from the TypeScript SDK.
Type of change
- [x] New feature (non-breaking change which adds functionality)
- [x] Documentation update
How Has This Been Tested?
- [x] Unit Test
- [x] Test Script (please provide)
Test Coverage:
- Constructor validation tests (API key requirements, model configuration)
- Single text embedding functionality
- Batch text embedding functionality
- Embedding dimension consistency validation
- Conditional test execution (skips when no API key provided)
- Integration with Memory class and EmbedderFactory
Test Results:
npm test
# ✅ Together AI tests: 3 passed
# ✅ Memory tests: 13 skipped (no OpenAI API key)
# ✅ Client tests: 8 skipped (no MEM0 API key)
# ✅ All tests pass when appropriate API keys are provided
Manual Testing:
- Tested with real Together AI API key
- Verified embedding generation for single and batch texts
- Confirmed integration with Memory class for semantic search
- Validated different model configurations and dimensions
Files Added/Modified
New Files:
src/oss/src/embeddings/together.ts- TogetherEmbedder implementationsrc/oss/tests/embeddings/together.test.ts- Comprehensive test suitesrc/oss/examples/embeddings/together-example.ts- Usage examplesREADME-together.md- Complete documentation
Modified Files:
src/oss/src/index.ts- Added TogetherEmbedder exportsrc/oss/src/utils/factory.ts- Added "together" case to EmbedderFactorypackage.json- Addedtogether-ai: ^0.16.0as peerDependencysrc/oss/tests/memory.test.ts- Fixed API usage and added conditional executionsrc/client/tests/memoryClient.test.ts- Added conditional test execution
Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules
- [x] I have checked my code and corrected any misspellings
Maintainer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed