-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Adding the embedding generator interface #46902
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
aayush3011
wants to merge
4
commits into
Azure:main
Choose a base branch
from
aayush3011:users/akataria/EGSInterface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
sdk/cosmos/azure-cosmos/azure/cosmos/_embedding_provider.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # The MIT License (MIT) | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
|
||
| from typing import Any, Protocol, Sequence, runtime_checkable | ||
|
|
||
| from ._embedding_result import EmbeddingResult | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class EmbeddingProvider(Protocol): | ||
| """Protocol for classes that generate text embeddings for Azure Cosmos DB queries. | ||
|
|
||
| Implementations are invoked by the SDK to embed literal text in queries | ||
| that use ``GenerateEmbeddings(...)``. A provider may be attached at the | ||
| client level or overridden at the container level. Implementations must be | ||
| safe to call concurrently. | ||
| """ | ||
|
|
||
| def generate_embeddings( | ||
| self, | ||
| texts: Sequence[str], | ||
| *, | ||
| endpoint: str, | ||
| deployment_name: str, | ||
| dimensions: int, | ||
| **kwargs: Any, | ||
| ) -> EmbeddingResult: | ||
| """Generate one embedding vector per input string. | ||
|
|
||
| :param texts: The input strings to embed. The returned vectors must be | ||
| in the same order as the inputs. | ||
| :type texts: Sequence[str] | ||
| :keyword str endpoint: The embedding service endpoint. | ||
| :keyword str deployment_name: The model deployment name. | ||
| :keyword int dimensions: The expected vector dimensionality. | ||
| :returns: An :class:`EmbeddingResult` containing the generated vectors. | ||
| :rtype: ~azure.cosmos.EmbeddingResult | ||
| """ | ||
| ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # The MIT License (MIT) | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import List, Optional | ||
|
|
||
|
|
||
| @dataclass | ||
| class EmbeddingResult: | ||
| """Represents the result of an embedding generation call. | ||
|
|
||
| :ivar vectors: The generated embedding vectors, one per input string, | ||
| in the same order as the inputs. | ||
| :vartype vectors: List[List[float]] | ||
| :ivar total_tokens: The total number of tokens consumed by the embedding call. | ||
| :vartype total_tokens: Optional[int] | ||
| """ | ||
|
|
||
| vectors: List[List[float]] | ||
| total_tokens: Optional[int] = None | ||
|
aayush3011 marked this conversation as resolved.
aayush3011 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_embedding_provider.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # The MIT License (MIT) | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
|
||
| from typing import Any, Protocol, Sequence, runtime_checkable | ||
|
|
||
| from .._embedding_result import EmbeddingResult | ||
|
|
||
|
|
||
| @runtime_checkable | ||
| class EmbeddingProvider(Protocol): | ||
| """Asynchronous Protocol for classes that generate text embeddings for Azure Cosmos DB queries. | ||
|
|
||
| Asynchronous counterpart of :class:`azure.cosmos.EmbeddingProvider` for use | ||
| with :class:`azure.cosmos.aio.CosmosClient`. | ||
|
aayush3011 marked this conversation as resolved.
aayush3011 marked this conversation as resolved.
|
||
| """ | ||
|
|
||
| async def generate_embeddings( | ||
| self, | ||
| texts: Sequence[str], | ||
| *, | ||
| endpoint: str, | ||
| deployment_name: str, | ||
| dimensions: int, | ||
| **kwargs: Any, | ||
| ) -> EmbeddingResult: | ||
| """Asynchronously generate one embedding vector per input string. | ||
|
|
||
| :param texts: The input strings to embed. The returned vectors must be | ||
| in the same order as the inputs. | ||
| :type texts: Sequence[str] | ||
| :keyword str endpoint: The embedding service endpoint. | ||
| :keyword str deployment_name: The model deployment name. | ||
| :keyword int dimensions: The expected vector dimensionality. | ||
| :returns: An :class:`EmbeddingResult` containing the generated vectors. | ||
| :rtype: ~azure.cosmos.EmbeddingResult | ||
| """ | ||
| ... | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.