diff options
| author | Fuwn <[email protected]> | 2026-02-03 21:19:39 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-03 21:21:28 -0800 |
| commit | 38fc408dbbf9462d50a95be4b37ac1d6ea377532 (patch) | |
| tree | 8c528c46d8349e83fa6cd51629501e97b9460603 /packages | |
| parent | feat(sdk): Add local embedding support with transformers.js (diff) | |
| download | archived-imemio-38fc408dbbf9462d50a95be4b37ac1d6ea377532.tar.xz archived-imemio-38fc408dbbf9462d50a95be4b37ac1d6ea377532.zip | |
feat(mcp): Support local embeddings via environment variable
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/mcp/src/index.ts | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts index 5fc6a7e..9102c62 100644 --- a/packages/mcp/src/index.ts +++ b/packages/mcp/src/index.ts @@ -6,8 +6,11 @@ import { z } from "zod"; import { createSupabaseClient, EmbeddingService, + LocalEmbeddingProvider, SupabaseStore, SupabaseProjectStore, + type EmbeddingProvider, + type LocalEmbeddingModel, } from "@imemio/sdk"; function getRequiredEnvironmentVariable(name: string): string { @@ -24,16 +27,32 @@ function getOptionalEnvironmentVariable(name: string): string | undefined { return process.env[name]; } +function createEmbeddingProvider(): EmbeddingProvider | null { + const embeddingType = getOptionalEnvironmentVariable("IMEMIO_EMBEDDING_TYPE"); + const openaiApiKey = getOptionalEnvironmentVariable("OPENAI_API_KEY"); + + if (embeddingType === "local") { + const model = getOptionalEnvironmentVariable( + "IMEMIO_LOCAL_EMBEDDING_MODEL", + ) as LocalEmbeddingModel | undefined; + + return new LocalEmbeddingProvider({ model }); + } + + if (openaiApiKey) { + return new EmbeddingService({ apiKey: openaiApiKey }); + } + + return null; +} + const supabaseUrl = getRequiredEnvironmentVariable("SUPABASE_URL"); const supabaseKey = getRequiredEnvironmentVariable("SUPABASE_ANON_KEY"); const userId = getRequiredEnvironmentVariable("IMEMIO_USER_ID"); -const openaiApiKey = getOptionalEnvironmentVariable("OPENAI_API_KEY"); const client = createSupabaseClient(supabaseUrl, supabaseKey); const memoryStore = new SupabaseStore(client, userId); const projectStore = new SupabaseProjectStore(client, userId); -const embeddingService = openaiApiKey - ? new EmbeddingService({ apiKey: openaiApiKey }) - : null; +const embeddingService = createEmbeddingProvider(); const tagSchema = z.object({ id: z.string(), name: z.string(), @@ -560,7 +579,7 @@ server.tool( content: [ { type: "text" as const, - text: "Embedding service not configured. Set OPENAI_API_KEY environment variable.", + text: "Embedding service not configured. Set OPENAI_API_KEY or IMEMIO_EMBEDDING_TYPE=local.", }, ], isError: true, @@ -595,7 +614,7 @@ server.tool( content: [ { type: "text" as const, - text: "Embedding service not configured. Set OPENAI_API_KEY environment variable.", + text: "Embedding service not configured. Set OPENAI_API_KEY or IMEMIO_EMBEDDING_TYPE=local.", }, ], isError: true, |