Skip to content
Merged
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
10 changes: 7 additions & 3 deletions redisvl/extensions/llmcache/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def __init__(
prefix: Optional[str] = None,
distance_threshold: float = 0.1,
ttl: Optional[int] = None,
vectorizer: BaseVectorizer = HFTextVectorizer(
model="sentence-transformers/all-mpnet-base-v2"
),
vectorizer: Optional[BaseVectorizer] = None,
redis_client: Optional[Redis] = None,
redis_url: str = "redis://localhost:6379",
connection_args: Dict[str, Any] = {},
Expand Down Expand Up @@ -66,6 +64,12 @@ def __init__(
if prefix is None:
prefix = name

# Set vectorizer default
if vectorizer is None:
vectorizer = HFTextVectorizer(
model="sentence-transformers/all-mpnet-base-v2"
)

# build cache index schema
schema = IndexSchema.from_dict({"index": {"name": name, "prefix": prefix}})
# add fields
Expand Down
31 changes: 10 additions & 21 deletions redisvl/utils/vectorize/text/vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class VertexAITextVectorizer(BaseVectorizer):

Utilizing this vectorizer requires an active GCP project and location
(region), along with appropriate application credentials. These can be
provided through the `api_config` dictionary or by setting the corresponding
environment variables. Additionally, the vertexai python client must be
provided through the `api_config` dictionary or set the GOOGLE_APPLICATION_CREDENTIALS
env var. Additionally, the vertexai python client must be
installed with `pip install google-cloud-aiplatform>=1.26`.

.. code-block:: python
Expand All @@ -29,8 +29,6 @@ class VertexAITextVectorizer(BaseVectorizer):
api_config={
"project_id": "your_gcp_project_id", # OR set GCP_PROJECT_ID
"location": "your_gcp_location", # OR set GCP_LOCATION
"google_application_credentials": "path_to_your_creds"
# OR set GOOGLE_APPLICATION_CREDENTIALS
})
embedding = vectorizer.embed("Hello, world!")

Expand All @@ -51,7 +49,7 @@ def __init__(
model (str): Model to use for embedding. Defaults to
'textembedding-gecko'.
api_config (Optional[Dict], optional): Dictionary containing the
API key. Defaults to None.
API config details. Defaults to None.

Raises:
ImportError: If the google-cloud-aiplatform library is not installed.
Expand Down Expand Up @@ -79,25 +77,16 @@ def __init__(
"or set the GCP_LOCATION environment variable."
)

# Check for Google Application Credentials
if "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ:
creds_path = (
api_config.get("google_application_credentials") if api_config else None
)
if creds_path:
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = creds_path
else:
raise ValueError(
"Missing Google Application Credentials. "
"Provide the path to the credentials JSON file in the api_config with\
key 'google_application_credentials' or set the \
GOOGLE_APPLICATION_CREDENTIALS environment variable."
)
# Check for credentials
credentials = api_config.get("credentials") if api_config else None

try:
import vertexai
from vertexai.preview.language_models import TextEmbeddingModel
from vertexai.language_models import TextEmbeddingModel

vertexai.init(project=project_id, location=location)
vertexai.init(
project=project_id, location=location, credentials=credentials
)
except ImportError:
raise ImportError(
"VertexAI vectorizer requires the google-cloud-aiplatform library. "
Expand Down