From 51eb889ae29ef53d649b50c50d0704fa266d898e Mon Sep 17 00:00:00 2001 From: zuberahmed1987 Date: Fri, 27 Dec 2024 20:37:05 +0530 Subject: [PATCH 1/2] Support for OpenAI Compatible API embedding model. --- README.md | 8 ++++++++ backend/utils/openAi/index.js | 13 ++++++++++--- docker/.env.example | 7 ++++++- workers/.env.example | 8 +++++++- workers/functions/newWorkspace/index.js | 2 +- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8131ca27..2f6bc72a 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,14 @@ VectorAdmin by Mintplex Labs Inc contains a telemetry feature that collects anon ### Why? We use this information to help us understand how VectorAdmin is used, to help us prioritize work on new features and bug fixes, and to help us improve VectorAdmin's performance and stability. +### Support for OpenAI Compatible API embedding model. +Use below variables in your server or docker .env settings. +``` +OPENAI_BASE_PATH="https://api.openai.com/v1" +OPENAI_MODEL_NAME="text-embedding-ada-002" +MODEL_DIMENSIONS=1536 +``` + ### Opting out Set `DISABLE_TELEMETRY` in your server or docker .env settings to "true" to opt out of telemetry. diff --git a/backend/utils/openAi/index.js b/backend/utils/openAi/index.js index 9baad98f..7cc73f53 100644 --- a/backend/utils/openAi/index.js +++ b/backend/utils/openAi/index.js @@ -1,16 +1,23 @@ const { Configuration, OpenAIApi } = require("openai"); + class OpenAi { constructor(apiKey = "") { - const config = new Configuration({ apiKey }); + const basePath = process.env.OPENAI_BASE_PATH || "https://api.openai.com/v1"; + const modelName = process.env.OPENAI_MODEL_NAME || "text-embedding-ada-002"; + const config = new Configuration({ + apiKey, + basePath, + }); const openai = new OpenAIApi(config); this.openai = openai; + this.modelName = modelName; } async embedTextChunk(textChunk = "") { const { data: { data }, } = await this.openai.createEmbedding({ - model: "text-embedding-ada-002", + model: this.modelName, input: textChunk, }); return data.length > 0 && data[0].hasOwnProperty("embedding") @@ -22,7 +29,7 @@ class OpenAi { const { data: { data }, } = await this.openai.createEmbedding({ - model: "text-embedding-ada-002", + model: this.modelName, input: chunks, }); return data.length > 0 && diff --git a/docker/.env.example b/docker/.env.example index ff8d11d1..0cb273a9 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -5,4 +5,9 @@ JWT_SECRET="your-random-string-here" INNGEST_EVENT_KEY="background_workers" INNGEST_SIGNING_KEY="random-string-goes-here" INNGEST_LANDING_PAGE="true" -DATABASE_CONNECTION_STRING="postgresql://vectoradmin:password@host.docker.internal:5433/vdbms" \ No newline at end of file +DATABASE_CONNECTION_STRING="postgresql://vectoradmin:password@host.docker.internal:5433/vdbms" + +## Support for OpenAI Compatible API model support. +# OPENAI_BASE_PATH="https://api.openai.com/v1" +# OPENAI_MODEL_NAME="text-embedding-ada-002" +# MODEL_DIMENSIONS=1536 \ No newline at end of file diff --git a/workers/.env.example b/workers/.env.example index 06406f44..bc242115 100644 --- a/workers/.env.example +++ b/workers/.env.example @@ -1,3 +1,9 @@ INNGEST_EVENT_KEY="background_workers" INNGEST_SIGNING_KEY="" -# DISABLE_TELEMETRY="true" # Uncomment to disable telemetry on workers for any ENV. \ No newline at end of file +# DISABLE_TELEMETRY="true" # Uncomment to disable telemetry on workers for any ENV. + +## Support for OpenAI Compatible API model support. + +# OPENAI_BASE_PATH="https://api.openai.com/v1" +# OPENAI_MODEL_NAME="text-embedding-ada-002" +# MODEL_DIMENSIONS=1536 diff --git a/workers/functions/newWorkspace/index.js b/workers/functions/newWorkspace/index.js index 94fcb392..2e858e62 100644 --- a/workers/functions/newWorkspace/index.js +++ b/workers/functions/newWorkspace/index.js @@ -64,7 +64,7 @@ const newWorkspaceCreated = InngestClient.createFunction( workspace.fname, { vectors: { - size: 1536, // TODO: Fixed to OpenAI models - when other embeddings exist make variable. + size: parseInt(process.env.MODEL_DIMENSIONS) || 1536, // TODO: Fixed to OpenAI models - when other embeddings exist make variable. distance: 'Cosine', }, } From a6e329ff89493fbec2698a8edd2ec0c640c43210 Mon Sep 17 00:00:00 2001 From: zuberahmed1987 Date: Fri, 27 Dec 2024 20:39:47 +0530 Subject: [PATCH 2/2] docs updated for OpenAI Compatible API --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2f6bc72a..e844a040 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,15 @@ In separate terminal windows from project root: On first boot and visiting of the homepage, you will be automatically redirected to create your primary admin account, organization, and database connection. + +### Support for OpenAI Compatible API embedding model. +Use below variables in your server or docker .env settings. +``` +OPENAI_BASE_PATH="https://api.openai.com/v1" +OPENAI_MODEL_NAME="text-embedding-ada-002" +MODEL_DIMENSIONS=1536 +``` + ## Contributing - create issue - create PR with branch name format of `-` @@ -98,14 +107,6 @@ VectorAdmin by Mintplex Labs Inc contains a telemetry feature that collects anon ### Why? We use this information to help us understand how VectorAdmin is used, to help us prioritize work on new features and bug fixes, and to help us improve VectorAdmin's performance and stability. -### Support for OpenAI Compatible API embedding model. -Use below variables in your server or docker .env settings. -``` -OPENAI_BASE_PATH="https://api.openai.com/v1" -OPENAI_MODEL_NAME="text-embedding-ada-002" -MODEL_DIMENSIONS=1536 -``` - ### Opting out Set `DISABLE_TELEMETRY` in your server or docker .env settings to "true" to opt out of telemetry.