-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Cosmos][VectorIndex]Adding changes for vectorIndex and vectorEmbeddingPolicy #40004
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
aayush3011
merged 23 commits into
Azure:feature/vector_search
from
aayush3011:users/akataria/vectorindexing
May 2, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0269f52
Adding changes for vectorIndex and vectorEmbeddingPolicy
aayush3011 29ad391
Adding some necessary comments
aayush3011 cd4d8cf
Adding test case
aayush3011 a2f6a83
updating enum values
aayush3011 c4bc283
Updating test case
aayush3011 af99d7b
Updating test case
aayush3011 6d8fc9b
Updating test case
aayush3011 2f7112d
updating changelog
aayush3011 158880f
Merge branch 'main' into users/akataria/vectorindexing
aayush3011 bb85dd3
Updating test case
aayush3011 a7185d7
Merge branch 'users/akataria/vectorindexing' of https://github.com/aa…
aayush3011 f4c4012
Merge branch 'Azure:main' into users/akataria/vectorindexing
aayush3011 72a4bcd
Resolving comments
aayush3011 dfb3575
Resolving comments
aayush3011 67f51cb
Fixing test case
aayush3011 730f8c2
Resolving comments
aayush3011 ad3ac89
Resolving Comments
aayush3011 940c6af
Merge branch 'main' into users/akataria/vectorindexing
aayush3011 3eb77ea
Fixing build issues
aayush3011 44f4e07
Merge branch 'main' into users/akataria/vectorindexing
aayush3011 460f681
Resolving comments
aayush3011 5579dd1
Resolving Comments
aayush3011 54a2ce3
Merge branch 'users/akataria/vectorindexing' of https://github.com/aa…
aayush3011 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
345 changes: 345 additions & 0 deletions
345
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/VectorIndexTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
58 changes: 58 additions & 0 deletions
58
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosVectorDataType.java
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,58 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.cosmos.models; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Data types for the embeddings in Cosmos DB database service. | ||
| */ | ||
| public enum CosmosVectorDataType { | ||
| /** | ||
| * Represents a int8 data type. | ||
| */ | ||
| INT8("int8"), | ||
|
|
||
| /** | ||
| * Represents a uint8 data type. | ||
| */ | ||
| UINT8("uint8"), | ||
|
|
||
| /** | ||
| * Represents a float16 data type. | ||
| */ | ||
| FLOAT16("float16"), | ||
|
|
||
| /** | ||
| * Represents a float32 data type. | ||
| */ | ||
| FLOAT32("float32"); | ||
|
|
||
| private final String overWireValue; | ||
|
|
||
| CosmosVectorDataType(String overWireValue) { | ||
| this.overWireValue = overWireValue; | ||
| } | ||
|
|
||
| @JsonValue | ||
| @Override | ||
| public String toString() { | ||
| return this.overWireValue; | ||
| } | ||
|
|
||
| /** | ||
| * Method to retrieve the enum constant by its overWireValue. | ||
| * @param value the overWire value of the enum constant | ||
| * @return the matching CosmosVectorDataType | ||
| * @throws IllegalArgumentException if no matching enum constant is found | ||
| */ | ||
| public static CosmosVectorDataType fromString(String value) { | ||
| return Arrays.stream(CosmosVectorDataType.values()) | ||
| .filter(vectorDataType -> vectorDataType.toString().equalsIgnoreCase(value)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException("Invalid vector data type for the vector embedding policy.")); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
...smos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosVectorDistanceFunction.java
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,53 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.cosmos.models; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Distance Function for the embeddings in the Cosmos DB database service. | ||
| */ | ||
| public enum CosmosVectorDistanceFunction { | ||
| /** | ||
| * Represents the euclidean distance function. | ||
| */ | ||
| EUCLIDEAN("euclidean"), | ||
|
|
||
| /** | ||
| * Represents the cosine distance function. | ||
| */ | ||
| COSINE("cosine"), | ||
|
|
||
| /** | ||
| * Represents the dot product distance function. | ||
| */ | ||
| DOT_PRODUCT("dotproduct"); | ||
|
|
||
| private final String overWireValue; | ||
|
|
||
| CosmosVectorDistanceFunction(String overWireValue) { | ||
| this.overWireValue = overWireValue; | ||
| } | ||
|
|
||
| @JsonValue | ||
| @Override | ||
| public String toString() { | ||
| return this.overWireValue; | ||
| } | ||
|
|
||
| /** | ||
| * Method to retrieve the enum constant by its overWireValue. | ||
| * @param value the overWire value of the enum constant | ||
| * @return the matching CosmosVectorDataType | ||
| * @throws IllegalArgumentException if no matching enum constant is found | ||
| */ | ||
| public static CosmosVectorDistanceFunction fromString(String value) { | ||
| return Arrays.stream(CosmosVectorDistanceFunction.values()) | ||
| .filter(vectorDistanceFunction -> vectorDistanceFunction.toString().equalsIgnoreCase(value)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException("Invalid distance function for the vector embedding policy.")); | ||
| } | ||
| } |
128 changes: 128 additions & 0 deletions
128
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosVectorEmbedding.java
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,128 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.cosmos.models; | ||
|
|
||
| import com.azure.cosmos.implementation.Constants; | ||
| import com.azure.cosmos.implementation.JsonSerializable; | ||
| import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull; | ||
|
|
||
| /** | ||
| * Embedding settings within {@link CosmosVectorEmbeddingPolicy} | ||
| */ | ||
| public final class CosmosVectorEmbedding { | ||
| @JsonProperty(Constants.Properties.PATH) | ||
| private String path; | ||
| @JsonProperty(Constants.Properties.VECTOR_DATA_TYPE) | ||
| private String dataType; | ||
| @JsonProperty(Constants.Properties.VECTOR_DIMENSIONS) | ||
| private Long dimensions; | ||
| @JsonProperty(Constants.Properties.DISTANCE_FUNCTION) | ||
| private String distanceFunction; | ||
| private JsonSerializable jsonSerializable; | ||
|
|
||
| /** | ||
| * Constructor | ||
| */ | ||
| public CosmosVectorEmbedding() { | ||
| this.jsonSerializable = new JsonSerializable(); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the path for the cosmosVectorEmbedding. | ||
| * | ||
| * @return path | ||
| */ | ||
| public String getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the path for the cosmosVectorEmbedding. | ||
| * | ||
| * @param path the path for the cosmosVectorEmbedding | ||
| * @return CosmosVectorEmbedding | ||
| */ | ||
| public CosmosVectorEmbedding setPath(String path) { | ||
| if (StringUtils.isEmpty(path)) { | ||
| throw new NullPointerException("embedding path is empty"); | ||
| } | ||
|
|
||
| if (path.charAt(0) != '/' || path.lastIndexOf('/') != 0) { | ||
| throw new IllegalArgumentException(""); | ||
| } | ||
|
|
||
| this.path = path; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the data type for the cosmosVectorEmbedding. | ||
| * | ||
| * @return dataType | ||
| */ | ||
| public CosmosVectorDataType getDataType() { | ||
| return CosmosVectorDataType.fromString(dataType); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the data type for the cosmosVectorEmbedding. | ||
| * | ||
| * @param dataType the data type for the cosmosVectorEmbedding | ||
| * @return CosmosVectorEmbedding | ||
| */ | ||
| public CosmosVectorEmbedding setDataType(CosmosVectorDataType dataType) { | ||
| checkNotNull(dataType, "cosmosVectorDataType cannot be null"); | ||
| this.dataType = dataType.toString(); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the dimensions for the cosmosVectorEmbedding. | ||
| * | ||
| * @return dimensions | ||
| */ | ||
| public Long getDimensions() { | ||
| return dimensions; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the dimensions for the cosmosVectorEmbedding. | ||
| * | ||
| * @param dimensions the dimensions for the cosmosVectorEmbedding | ||
| * @return CosmosVectorEmbedding | ||
| */ | ||
| public CosmosVectorEmbedding setDimensions(Long dimensions) { | ||
| checkNotNull(dimensions, "dimensions cannot be null"); | ||
| if (dimensions < 1) { | ||
| throw new IllegalArgumentException("Dimensions for the embedding has to be a long value greater than 0 " + | ||
| "for the vector embedding policy"); | ||
| } | ||
|
|
||
| this.dimensions = dimensions; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the distanceFunction for the cosmosVectorEmbedding. | ||
| * | ||
| * @return distanceFunction | ||
| */ | ||
| public CosmosVectorDistanceFunction getDistanceFunction() { | ||
| return CosmosVectorDistanceFunction.fromString(distanceFunction); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the distanceFunction for the cosmosVectorEmbedding. | ||
| * | ||
| * @param distanceFunction the distanceFunction for the cosmosVectorEmbedding | ||
| * @return CosmosVectorEmbedding | ||
| */ | ||
| public CosmosVectorEmbedding setDistanceFunction(CosmosVectorDistanceFunction distanceFunction) { | ||
| checkNotNull(distanceFunction, "cosmosVectorDistanceFunction cannot be empty"); | ||
| this.distanceFunction = distanceFunction.toString(); | ||
| return this; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the PR reference here seems wrong - should be 40004?