Skip to content
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

address API review comments #36058

Merged
merged 20 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
# Defines stuff related to the resulting created index, like the index type.

from typing import Optional
from azure.ai.ml._utils._experimental import experimental


@experimental
class AzureAISearchConfig:
"""Config class for creating an Azure AI Search index.

:param ai_search_index_name: The name of the Azure AI Search index.
:type ai_search_index_name: Optional[str]
:param ai_search_connection_id: The Azure AI Search connection ID.
:type ai_search_connection_id: Optional[str]
:param index_name: The name of the Azure AI Search index.
:type index_name: Optional[str]
:param connection_id: The Azure AI Search connection ID.
:type connection_id: Optional[str]
"""

def __init__(
self,
*,
ai_search_index_name: Optional[str] = None,
ai_search_connection_id: Optional[str] = None,
index_name: Optional[str] = None,
connection_id: Optional[str] = None,
) -> None:
self.ai_search_index_name = ai_search_index_name
self.ai_search_connection_id = ai_search_connection_id
self.index_name = index_name
self.connection_id = connection_id
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ---------------------------------------------------------

from typing import Optional
from azure.ai.ml._utils._experimental import experimental


class IndexConfig: # pylint: disable=too-many-instance-attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ---------------------------------------------------------
from typing import Union

from azure.ai.ml._utils._experimental import experimental
from azure.ai.ml.entities._inputs_outputs import Input
from azure.ai.ml.constants._common import IndexInputType

Expand All @@ -12,6 +13,7 @@


# Defines stuff related to supplying inputs for an index AKA the base data.
@experimental
class IndexDataSource:
"""Base class for configs that define data that will be processed into an ML index.
This class should not be instantiated directly. Use one of its child classes instead.
Expand All @@ -28,24 +30,26 @@ def __init__(self, *, input_type: Union[str, IndexInputType]):
# Field bundle for creating an index from files located in a Git repo.
# TODO Does git_url need to specifically be an SSH or HTTPS style link?
# TODO What is git connection id?
@experimental
class GitSource(IndexDataSource):
"""Config class for creating an ML index from files located in a git repository.

:param git_url: A link to the repository to use.
:type git_url: str
:param git_branch_name: The name of the branch to use from the target repository.
:type git_branch_name: str
:param git_connection_id: The connection ID for GitHub
:type git_connection_id: str
:param url: A link to the repository to use.
:type url: str
:param branch_name: The name of the branch to use from the target repository.
:type branch_name: str
:param connection_id: The connection ID for GitHub
:type connection_id: str
"""

def __init__(self, *, git_url: str, git_branch_name: str, git_connection_id: str):
self.git_url = git_url
self.git_branch_name = git_branch_name
self.git_connection_id = git_connection_id
def __init__(self, *, url: str, branch_name: str, connection_id: str):
self.url = url
self.branch_name = branch_name
self.connection_id = connection_id
super().__init__(input_type=IndexInputType.GIT)


@experimental
class LocalSource(IndexDataSource):
"""Config class for creating an ML index from a collection of local files.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ---------------------------------------------------------
from dataclasses import dataclass
from typing import Any, Dict, Optional
from azure.ai.ml._utils._experimental import experimental
from azure.ai.ml._utils.utils import camel_to_snake
from azure.ai.ml.entities._workspace.connections.workspace_connection import WorkspaceConnection
from azure.ai.ml.entities._workspace.connections.connection_subtypes import (
Expand All @@ -12,6 +13,7 @@


@dataclass
@experimental
class ModelConfiguration:
"""Configuration for a embedding model.

Expand Down Expand Up @@ -47,7 +49,7 @@ def from_connection(
connection: WorkspaceConnection,
model_name: Optional[str] = None,
deployment_name: Optional[str] = None,
**model_kwargs
**kwargs
) -> "ModelConfiguration":
"""Create an model configuration from a Connection.

Expand All @@ -57,8 +59,8 @@ def from_connection(
:type model_name: Optional[str]
:param deployment_name: The name of the deployment.
:type deployment_name: Optional[str]
:keyword model_kwargs: Additional keyword arguments for the model.
:paramtype model_kwargs: Dict[str, Any]
:keyword kwargs: Additional keyword arguments for the model.
:paramtype kwargs: Dict[str, Any]
:return: The model configuration.
:rtype: ~azure.ai.ml.entities._indexes.entities.ModelConfiguration
:raises TypeError: If the connection is not an AzureOpenAIConnection.
Expand Down Expand Up @@ -97,5 +99,5 @@ def from_connection(
connection_type=connection_type,
model_name=model_name,
deployment_name=deployment_name,
model_kwargs=model_kwargs,
model_kwargs=kwargs,
)
14 changes: 8 additions & 6 deletions sdk/ml/azure-ai-ml/azure/ai/ml/operations/_index_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
from azure.ai.ml._utils._asset_utils import _resolve_label_to_asset
from azure.ai.ml._utils._experimental import experimental
from azure.ai.ml._utils._http_utils import HttpPipeline
from azure.ai.ml._utils._logger_utils import OpsLogger
from azure.ai.ml._utils.utils import _get_base_urls_from_discovery_service
Expand Down Expand Up @@ -252,6 +253,7 @@ def cls(rest_indexes: Iterable[RestIndex]) -> List[Index]:
return self._azure_ai_assets.indexes.list(name, list_view_type=list_view_type, cls=cls, **kwargs)

# pylint: disable=too-many-locals
@experimental
MilesHolland marked this conversation as resolved.
Show resolved Hide resolved
def build_index(
self,
*,
Expand All @@ -270,7 +272,7 @@ def build_index(
######## data source info ########
input_source: Union[IndexDataSource, str],
input_source_credential: Optional[Union[ManagedIdentityConfiguration, UserIdentityConfiguration]] = None,
) -> Union["MLIndex", "Job"]: # type: ignore[name-defined]
) -> Union["Index", "Job"]: # type: ignore[name-defined]
"""Builds an index on the cloud using the Azure AI Resources service.

:keyword name: The name of the index to be created.
Expand Down Expand Up @@ -333,8 +335,8 @@ def build_index(
index=(
IndexStore(
type="acs",
connection=build_connection_id(index_config.ai_search_connection_id, self._operation_scope),
name=index_config.ai_search_index_name,
connection=build_connection_id(index_config.connection_id, self._operation_scope),
name=index_config.index_name,
)
if index_config is not None
else IndexStore(type="faiss")
Expand Down Expand Up @@ -390,9 +392,9 @@ def git_to_index(
return index_job.outputs

git_index_job = git_to_index(
git_url=input_source.git_url,
branch_name=input_source.git_branch_name,
git_connection_id=input_source.git_connection_id,
git_url=input_source.url,
branch_name=input_source.branch_name,
git_connection_id=input_source.connection_id,
)
# Ensure repo cloned each run to get latest, comment out to have first clone reused.
git_index_job.settings.force_rerun = True
Expand Down
Loading