diff --git a/docker/.env.example b/docker/.env.example index e6b4e624e..508b20f40 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -22,6 +22,8 @@ OPEN_MODEL_PREF='gpt-3.5-turbo' # Enable all below if you are using vector database: Chroma. # VECTOR_DB="chroma" # CHROMA_ENDPOINT='http://host.docker.internal:8000' +# CHROMA_API_HEADER="X-Api-Key" +# CHROMA_API_KEY="sk-123abc" # Enable all below if you are using vector database: Pinecone. VECTOR_DB="pinecone" diff --git a/docker/HOW_TO_USE_DOCKER.md b/docker/HOW_TO_USE_DOCKER.md index 0f146776d..7a47811f0 100644 --- a/docker/HOW_TO_USE_DOCKER.md +++ b/docker/HOW_TO_USE_DOCKER.md @@ -44,6 +44,8 @@ Out of the box, all vector databases are supported. Any vector databases requiri VECTOR_DB="chroma" CHROMA_ENDPOINT='http://host.docker.internal:8000' # Allow docker to look on host port, not container. +# CHROMA_API_HEADER="X-Api-Key" // If you have an Auth middleware on your instance. +# CHROMA_API_KEY="sk-123abc" ...other configs diff --git a/frontend/src/components/Modals/Settings/VectorDbs/index.jsx b/frontend/src/components/Modals/Settings/VectorDbs/index.jsx index 9bf86af73..09c60b3a8 100644 --- a/frontend/src/components/Modals/Settings/VectorDbs/index.jsx +++ b/frontend/src/components/Modals/Settings/VectorDbs/index.jsx @@ -182,6 +182,41 @@ export default function VectorDBSelection({ spellCheck={false} /> </div> + + <div className=""> + <div className="mb-2 flex flex-col gap-y-1"> + <label + htmlFor="ChromaAuthTokenHeader" + className="block text-sm font-medium text-gray-800 dark:text-slate-200" + > + API Header & Key + </label> + <p className="text-xs text-gray-800 dark:text-slate-200"> + If your hosted Chroma instance is protected by an API + key - enter the header and api key here. + </p> + </div> + <div className="flex w-full items-center gap-x-4"> + <input + name="ChromaApiHeader" + autoComplete="off" + type="text" + defaultValue={settings?.ChromaApiHeader} + className="w-[20%] bg-gray-50 border border-gray-500 text-gray-900 placeholder-gray-500 text-sm rounded-lg dark:bg-stone-700 focus:border-stone-500 block w-full p-2.5 dark:text-slate-200 dark:placeholder-stone-500 dark:border-slate-200" + placeholder="X-Api-Key" + /> + <input + name="ChromaApiKey" + autoComplete="off" + type="password" + defaultValue={ + settings?.ChromaApiKey ? "*".repeat(20) : "" + } + className="bg-gray-50 border border-gray-500 text-gray-900 placeholder-gray-500 text-sm rounded-lg dark:bg-stone-700 focus:border-stone-500 block w-full p-2.5 dark:text-slate-200 dark:placeholder-stone-500 dark:border-slate-200" + placeholder="sk-myApiKeyToAccessMyChromaInstance" + /> + </div> + </div> </> )} {vectorDB === "lancedb" && ( diff --git a/server/.env.example b/server/.env.example index 489dc2c3a..2f6ef0414 100644 --- a/server/.env.example +++ b/server/.env.example @@ -21,6 +21,8 @@ OPEN_MODEL_PREF='gpt-3.5-turbo' # Enable all below if you are using vector database: Chroma. # VECTOR_DB="chroma" # CHROMA_ENDPOINT='http://localhost:8000' +# CHROMA_API_HEADER="X-Api-Key" +# CHROMA_API_KEY="sk-123abc" # Enable all below if you are using vector database: Pinecone. # VECTOR_DB="pinecone" diff --git a/server/models/systemSettings.js b/server/models/systemSettings.js index f552bd45c..836d5907e 100644 --- a/server/models/systemSettings.js +++ b/server/models/systemSettings.js @@ -34,6 +34,8 @@ const SystemSettings = { ...(vectorDB === "chroma" ? { ChromaEndpoint: process.env.CHROMA_ENDPOINT, + ChromaApiHeader: process.env.CHROMA_API_HEADER, + ChromaApiKey: !!process.env.CHROMA_API_KEY, } : {}), ...(vectorDB === "weaviate" diff --git a/server/utils/helpers/updateENV.js b/server/utils/helpers/updateENV.js index 78561cba9..a7fb92107 100644 --- a/server/utils/helpers/updateENV.js +++ b/server/utils/helpers/updateENV.js @@ -35,10 +35,22 @@ const KEY_MAPPING = { envKey: "VECTOR_DB", checks: [isNotEmpty, supportedVectorDB], }, + + // Chroma Options ChromaEndpoint: { envKey: "CHROMA_ENDPOINT", checks: [isValidURL, validChromaURL], }, + ChromaApiHeader: { + envKey: "CHROMA_API_HEADER", + checks: [], + }, + ChromaApiKey: { + envKey: "CHROMA_API_KEY", + checks: [], + }, + + // Weaviate Options WeaviateEndpoint: { envKey: "WEAVIATE_ENDPOINT", checks: [isValidURL], @@ -47,6 +59,8 @@ const KEY_MAPPING = { envKey: "WEAVIATE_API_KEY", checks: [], }, + + // QDrant Options QdrantEndpoint: { envKey: "QDRANT_ENDPOINT", checks: [isValidURL], diff --git a/server/utils/vectorDbProviders/chroma/CHROMA_SETUP.md b/server/utils/vectorDbProviders/chroma/CHROMA_SETUP.md index 396ee348e..46dac0db0 100644 --- a/server/utils/vectorDbProviders/chroma/CHROMA_SETUP.md +++ b/server/utils/vectorDbProviders/chroma/CHROMA_SETUP.md @@ -16,9 +16,13 @@ - `docker-compose up -d --build` - set the `CHROMA_ENDPOINT=` .env variable in `server` and also set `VECTOR_DB=` to `chroma`. +* If you have an API Gateway or auth middleway be sure to set the `CHROMA_API_HEADER` and `CHROMA_API_KEY` keys. + eg: `server/.env.development` ``` VECTOR_DB="chroma" CHROMA_ENDPOINT='http://localhost:8000' +# CHROMA_API_HEADER="X-Api-Key" // If you have an Auth middleware on your instance. +# CHROMA_API_KEY="sk-123abc" // If you have an Auth middleware on your instance. ``` diff --git a/server/utils/vectorDbProviders/chroma/index.js b/server/utils/vectorDbProviders/chroma/index.js index fd184976b..e0f36f380 100644 --- a/server/utils/vectorDbProviders/chroma/index.js +++ b/server/utils/vectorDbProviders/chroma/index.js @@ -13,6 +13,16 @@ const Chroma = { const client = new ChromaClient({ path: process.env.CHROMA_ENDPOINT, // if not set will fallback to localhost:8000 + ...(!!process.env.CHROMA_API_HEADER && !!process.env.CHROMA_API_KEY + ? { + fetchOptions: { + headers: { + [process.env.CHROMA_API_HEADER || "X-Api-Key"]: + process.env.CHROMA_API_KEY, + }, + }, + } + : {}), }); const isAlive = await client.heartbeat();