Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

fix(ts-oss/together): honor TOGETHER_API_BASE in the embedder (#6572)

Abhay Singhbcca72e3f0e3
diff --git a/mem0-ts/src/oss/src/embeddings/together.ts b/mem0-ts/src/oss/src/embeddings/together.ts
index acd1d17e3..27ff9b6a4 100644
--- a/mem0-ts/src/oss/src/embeddings/together.ts
+++ b/mem0-ts/src/oss/src/embeddings/together.ts
@@ -17,7 +17,14 @@ export class TogetherEmbedder extends OpenAIEmbedder {
super({
...openAICompatibleConfig,
apiKey,
- baseURL: config.baseURL || config.url || DEFAULT_BASE_URL,
+ // Honor TOGETHER_API_BASE like the Together LLM does, so a user behind a
+ // gateway who sets it gets it for embeddings too instead of silently
+ // hitting api.together.ai.
+ baseURL:
+ config.baseURL ||
+ config.url ||
+ process.env.TOGETHER_API_BASE ||
+ DEFAULT_BASE_URL,
model: config.model || DEFAULT_MODEL,
});
}
diff --git a/mem0-ts/src/oss/tests/together-embedder.test.ts b/mem0-ts/src/oss/tests/together-embedder.test.ts
index 6c667ac29..dd65372df 100644
--- a/mem0-ts/src/oss/tests/together-embedder.test.ts
+++ b/mem0-ts/src/oss/tests/together-embedder.test.ts
@@ -20,6 +20,7 @@ describe("TogetherEmbedder (unit)", () => {
jest.resetModules();
process.env = { ...originalEnv };
delete process.env.TOGETHER_API_KEY;
+ delete process.env.TOGETHER_API_BASE;
mockOpenAI.mockClear();
mockEmbeddingsCreate.mockReset();
mockEmbeddingsCreate.mockResolvedValue({
@@ -81,6 +82,35 @@ describe("TogetherEmbedder (unit)", () => {
});
});
+ it("honors TOGETHER_API_BASE when no baseURL is configured", async () => {
+ process.env.TOGETHER_API_BASE = "https://gateway.example/v1";
+
+ const embedder = new TogetherEmbedder({ apiKey: "test-key" });
+
+ await embedder.embed("hello");
+
+ expect(mockOpenAI).toHaveBeenCalledWith({
+ apiKey: "test-key",
+ baseURL: "https://gateway.example/v1",
+ });
+ });
+
+ it("prefers an explicit baseURL over TOGETHER_API_BASE", async () => {
+ process.env.TOGETHER_API_BASE = "https://gateway.example/v1";
+
+ const embedder = new TogetherEmbedder({
+ apiKey: "test-key",
+ baseURL: "https://explicit.example/v1",
+ });
+
+ await embedder.embed("hello");
+
+ expect(mockOpenAI).toHaveBeenCalledWith({
+ apiKey: "test-key",
+ baseURL: "https://explicit.example/v1",
+ });
+ });
+
it("uses url as a baseURL fallback", async () => {
const embedder = new TogetherEmbedder({
apiKey: "test-key",