Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ The following environment variables are required to run the application:
- google_genai: "gemini-embedding-001"
- `EMBEDDINGS_CHUNK_SIZE`: (Optional) The chunk size used by the OpenAI and Azure embeddings clients to limit the number of inputs per request. Default value is `200`.
- `EMBEDDINGS_DIMENSIONS`: (Optional) Output vector size to request from the embedding model. Only honored by the `openai` and `azure` providers, and only supported by `text-embedding-3-*` models. Leave unset to use the model's native dimensionality (1536 for `text-embedding-3-small`, 3072 for `text-embedding-3-large`). Setting a smaller value (e.g. `512`, `1024`) trades some retrieval quality for lower storage cost and faster similarity search. Note: do not change this on an existing collection — all vectors in a `pgvector` column must share the same dimensionality.
- `EMBEDDINGS_ENCODING_FORMAT`: (Optional) Embedding response format for the `openai` and `azure` providers. Accepted values are `float` and `base64`. Leave unset to preserve the provider SDK default. Set to `float` for OpenAI-compatible APIs that do not support Base64 embedding responses.
- `RAG_AZURE_OPENAI_API_VERSION`: (Optional) Default is `2023-05-15`. The version of the Azure OpenAI API.
- `RAG_AZURE_OPENAI_API_KEY`: (Optional) The API key for Azure OpenAI service.
- Note: `AZURE_OPENAI_API_KEY` will work but `RAG_AZURE_OPENAI_API_KEY` will override it in order to not conflict with LibreChat setting.
Expand Down
15 changes: 15 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ async def dispatch(self, request, call_next):
GOOGLE_APPLICATION_CREDENTIALS = get_env_variable("GOOGLE_APPLICATION_CREDENTIALS", "")
env_value = get_env_variable("RAG_CHECK_EMBEDDING_CTX_LENGTH", "True").lower()
RAG_CHECK_EMBEDDING_CTX_LENGTH = True if env_value == "true" else False
EMBEDDINGS_ENCODING_FORMAT = get_env_variable("EMBEDDINGS_ENCODING_FORMAT", None)
if EMBEDDINGS_ENCODING_FORMAT is not None:
EMBEDDINGS_ENCODING_FORMAT = EMBEDDINGS_ENCODING_FORMAT.lower()
if EMBEDDINGS_ENCODING_FORMAT not in ("float", "base64"):
raise ValueError(
"EMBEDDINGS_ENCODING_FORMAT must be either 'float' or 'base64'"
)

# Only parse RAG_DISTANCE_THRESHOLD when it will actually be applied (pgvector).
# Under atlas-mongo the setting is documented as ignored, so parsing it
Expand Down Expand Up @@ -251,6 +258,10 @@ def init_embeddings(provider, model, dimensions=None):
)
if dimensions is not None:
kwargs["dimensions"] = dimensions
if EMBEDDINGS_ENCODING_FORMAT is not None:
kwargs["model_kwargs"] = {
"encoding_format": EMBEDDINGS_ENCODING_FORMAT
}
return OpenAIEmbeddings(**kwargs)
elif provider == EmbeddingsProvider.AZURE:
from langchain_openai import AzureOpenAIEmbeddings
Expand All @@ -265,6 +276,10 @@ def init_embeddings(provider, model, dimensions=None):
)
if dimensions is not None:
kwargs["dimensions"] = dimensions
if EMBEDDINGS_ENCODING_FORMAT is not None:
kwargs["model_kwargs"] = {
"encoding_format": EMBEDDINGS_ENCODING_FORMAT
}
return AzureOpenAIEmbeddings(**kwargs)
elif provider == EmbeddingsProvider.HUGGINGFACE:
from langchain_huggingface import HuggingFaceEmbeddings
Expand Down