-
Notifications
You must be signed in to change notification settings - Fork 537
[Internal] VectorEmbeddingPolicy: Adds EmbeddingSource block to Embedding model #5848
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49b3000
Adds EmbeddingSource block to Embedding mode
aavasthy 17d785b
using object.Equals comparison now
aavasthy a29cd9c
Merge branch 'main' into users/aavasthy/vectorembedding
aavasthy 17e7bd4
Add integration test for policy change
aavasthy 4556bfd
Adds GetHashCode
aavasthy 6556999
Resolve merge conflicts with main.
aavasthy 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
38 changes: 38 additions & 0 deletions
38
Microsoft.Azure.Cosmos/src/Resource/Settings/EmbeddingAuthType.cs
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,38 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos | ||
| { | ||
| using System.Runtime.Serialization; | ||
|
|
||
| /// <summary> | ||
| /// Defines the authentication type used by the Azure Cosmos DB service to call the | ||
| /// embedding service referenced from a <see cref="EmbeddingSource"/>. | ||
| /// </summary> | ||
| #if PREVIEW | ||
| public | ||
| #else | ||
| internal | ||
| #endif | ||
| enum EmbeddingAuthType | ||
| { | ||
| /// <summary> | ||
| /// Default sentinel — indicates no authentication type has been configured. | ||
| /// </summary> | ||
| [EnumMember(Value = "Unknown")] | ||
| Unknown = 0, | ||
|
|
||
| /// <summary> | ||
| /// Authenticate to the embedding service using Microsoft Entra ID (managed identity / token credential). | ||
| /// </summary> | ||
| [EnumMember(Value = "Entra")] | ||
| Entra, | ||
|
|
||
| /// <summary> | ||
| /// Authenticate to the embedding service using an API key. | ||
| /// </summary> | ||
| [EnumMember(Value = "ApiKey")] | ||
| ApiKey, | ||
| } | ||
| } | ||
118 changes: 118 additions & 0 deletions
118
Microsoft.Azure.Cosmos/src/Resource/Settings/EmbeddingSource.cs
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,118 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.Linq; | ||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Converters; | ||
| using Newtonsoft.Json.Linq; | ||
|
|
||
| /// <summary> | ||
| /// Describes the source document paths and the embedding service that the Azure Cosmos DB | ||
| /// service should use to generate the vector value for an <see cref="Embedding"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// When present on an <see cref="Embedding"/>, this block tells the SDK (and the Cosmos | ||
| /// DB embedding provider) where and how to call the embedding service for the vector | ||
| /// path in question. | ||
| /// </remarks> | ||
| #if PREVIEW | ||
| public | ||
| #else | ||
| internal | ||
| #endif | ||
| sealed class EmbeddingSource : IEquatable<EmbeddingSource> | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the list of document paths whose values are concatenated and sent to | ||
| /// the embedding service to generate the vector. | ||
| /// </summary> | ||
| [JsonProperty(PropertyName = "sourcePaths")] | ||
| public Collection<string> SourcePaths { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the deployment name of the embedding model on the embedding service. | ||
| /// </summary> | ||
| [JsonProperty(PropertyName = "deploymentName")] | ||
| public string DeploymentName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the name of the embedding model. | ||
| /// </summary> | ||
| [JsonProperty(PropertyName = "modelName")] | ||
| public string ModelName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the endpoint of the embedding service. | ||
| /// </summary> | ||
| [JsonProperty(PropertyName = "endpoint")] | ||
| public string Endpoint { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the <see cref="Cosmos.EmbeddingAuthType"/> used to authenticate to the | ||
| /// embedding service. | ||
| /// </summary> | ||
| [JsonProperty(PropertyName = "authType")] | ||
| [JsonConverter(typeof(StringEnumConverter))] | ||
| public EmbeddingAuthType AuthType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// This contains additional values for scenarios where the SDK is not aware of new fields. | ||
| /// This ensures that if resource is read and updated none of the fields will be lost in the process. | ||
| /// </summary> | ||
| [JsonExtensionData] | ||
| internal IDictionary<string, JToken> AdditionalProperties { get; private set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool Equals(EmbeddingSource that) | ||
| { | ||
| if (that is null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (object.ReferenceEquals(this, that)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return ((this.SourcePaths == null && that.SourcePaths == null) || | ||
| (this.SourcePaths != null && that.SourcePaths != null && Enumerable.SequenceEqual(this.SourcePaths, that.SourcePaths))) | ||
| && this.AuthType == that.AuthType | ||
| && this.DeploymentName == that.DeploymentName | ||
| && this.Endpoint == that.Endpoint | ||
| && this.ModelName == that.ModelName; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override bool Equals(object obj) | ||
| { | ||
| return this.Equals(obj as EmbeddingSource); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override int GetHashCode() | ||
| { | ||
| int hashCode = 1265339359; | ||
|
|
||
| if (this.SourcePaths != null) | ||
| { | ||
| foreach (string sourcePath in this.SourcePaths) | ||
| { | ||
| hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(sourcePath); | ||
| } | ||
| } | ||
|
|
||
| hashCode = (hashCode * -1521134295) + this.AuthType.GetHashCode(); | ||
| hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(this.DeploymentName); | ||
| hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(this.Endpoint); | ||
| hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(this.ModelName); | ||
| return hashCode; | ||
| } | ||
| } | ||
| } |
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
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.