Skip to content

Add base_url parameter to embedding_factory for custom endpoint support #2019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions src/ragas/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ def __repr__(self) -> str:


def embedding_factory(
model: str = "text-embedding-ada-002", run_config: t.Optional[RunConfig] = None
model: str = "text-embedding-ada-002",
run_config: t.Optional[RunConfig] = None,
base_url: t.Optional[str] = None,
) -> BaseRagasEmbeddings:
"""
Create and return a BaseRagasEmbeddings instance. Used for default embeddings
Expand All @@ -368,13 +370,15 @@ def embedding_factory(
The name of the OpenAI embedding model to use, by default "text-embedding-ada-002".
run_config : RunConfig, optional
Configuration for the run, by default None.
base_url : str, optional
Base URL for the API, by default None.

Returns
-------
BaseRagasEmbeddings
An instance of BaseRagasEmbeddings configured with the specified parameters.
"""
openai_embeddings = OpenAIEmbeddings(model=model)
openai_embeddings = OpenAIEmbeddings(model=model, base_url=base_url)
if run_config is not None:
openai_embeddings.request_timeout = run_config.timeout
else:
Expand Down