Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0269f52
Adding changes for vectorIndex and vectorEmbeddingPolicy
aayush3011 Mar 22, 2024
29ad391
Adding some necessary comments
aayush3011 Mar 27, 2024
cd4d8cf
Adding test case
aayush3011 Mar 28, 2024
a2f6a83
updating enum values
aayush3011 Mar 28, 2024
c4bc283
Updating test case
aayush3011 Mar 28, 2024
af99d7b
Updating test case
aayush3011 Mar 29, 2024
6d8fc9b
Updating test case
aayush3011 Mar 29, 2024
2f7112d
updating changelog
aayush3011 Mar 29, 2024
158880f
Merge branch 'main' into users/akataria/vectorindexing
aayush3011 Mar 29, 2024
bb85dd3
Updating test case
aayush3011 Mar 29, 2024
a7185d7
Merge branch 'users/akataria/vectorindexing' of https://github.com/aa…
aayush3011 Mar 29, 2024
f4c4012
Merge branch 'Azure:main' into users/akataria/vectorindexing
aayush3011 Apr 2, 2024
72a4bcd
Resolving comments
aayush3011 Apr 2, 2024
dfb3575
Resolving comments
aayush3011 Apr 2, 2024
67f51cb
Fixing test case
aayush3011 Apr 2, 2024
730f8c2
Resolving comments
aayush3011 Apr 23, 2024
ad3ac89
Resolving Comments
aayush3011 Apr 27, 2024
940c6af
Merge branch 'main' into users/akataria/vectorindexing
aayush3011 Apr 27, 2024
3eb77ea
Fixing build issues
aayush3011 Apr 27, 2024
44f4e07
Merge branch 'main' into users/akataria/vectorindexing
aayush3011 Apr 29, 2024
460f681
Resolving comments
aayush3011 Apr 30, 2024
5579dd1
Resolving Comments
aayush3011 May 1, 2024
54a2ce3
Merge branch 'users/akataria/vectorindexing' of https://github.com/aa…
aayush3011 May 1, 2024
528a0eb
[Cosmos][VectorIndex]Adding changes for vectorIndex and vectorEmbeddi…
aayush3011 May 2, 2024
148cba5
[Cosmos][VectorSearch] Non Streaming Order By Query (#40085)
aayush3011 May 8, 2024
df7e838
[Cosmos][VectorSearch] Non Streaming Order By Query (#40096)
aayush3011 May 9, 2024
c8de52f
[Cosmos][VectorSearch] Non Streaming Order By Query (#40098)
aayush3011 May 9, 2024
425b78f
Merge branch 'Azure:main' into users/akataria/vectorindexing
aayush3011 May 10, 2024
55efb81
Resolving comments
aayush3011 May 10, 2024
9a3b003
Resolving comments
aayush3011 May 10, 2024
52917f9
[Cosmos][VectorSearch] Non Streaming Order By Query (#40115)
aayush3011 May 10, 2024
72a7145
Merge branch 'feature/vector_search' into users/akataria/vectorindexing
aayush3011 May 10, 2024
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
Prev Previous commit
Next Next commit
Resolving comments
  • Loading branch information
aayush3011 committed Apr 23, 2024
commit 730f8c2d8a13eb3f4efa0f3ed208c3eb9f26b33e

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### 4.58.0-beta.1 (Unreleased)

#### Features Added
* Added `vectorEmbeddingPolicy` in `cosmosContainerProperties` and `vectorIndexes` in `indexPolicy` to support vector search in CosmosDB - See[39379](https://github.com/Azure/azure-sdk-for-java/pull/39379)
* Added `cosmosVectorEmbeddingPolicy` in `cosmosContainerProperties` and `vectorIndexes` in `indexPolicy` to support vector search in CosmosDB - See[39379](https://github.com/Azure/azure-sdk-for-java/pull/39379)

#### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import com.azure.cosmos.models.ChangeFeedPolicy;
import com.azure.cosmos.models.ComputedProperty;
import com.azure.cosmos.models.ConflictResolutionPolicy;
import com.azure.cosmos.models.CosmosVectorEmbeddingPolicy;
import com.azure.cosmos.models.IndexingPolicy;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.PartitionKeyDefinition;
import com.azure.cosmos.models.UniqueKeyPolicy;
import com.azure.cosmos.models.VectorEmbeddingPolicy;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
Expand Down Expand Up @@ -42,7 +42,7 @@ public final class DocumentCollection extends Resource {
private UniqueKeyPolicy uniqueKeyPolicy;
private PartitionKeyDefinition partitionKeyDefinition;
private ClientEncryptionPolicy clientEncryptionPolicyInternal;
private VectorEmbeddingPolicy vectorEmbeddingPolicy;
private CosmosVectorEmbeddingPolicy cosmosVectorEmbeddingPolicy;

/**
* Constructor.
Expand Down Expand Up @@ -419,14 +419,14 @@ public void setClientEncryptionPolicy(ClientEncryptionPolicy value) {
*
* @return the Vector Embedding Policy.
*/
public VectorEmbeddingPolicy getVectorEmbeddingPolicy() {
if (this.vectorEmbeddingPolicy == null) {
public CosmosVectorEmbeddingPolicy getVectorEmbeddingPolicy() {
if (this.cosmosVectorEmbeddingPolicy == null) {
if (super.has(Constants.Properties.VECTOR_EMBEDDING_POLICY)) {
this.vectorEmbeddingPolicy = super.getObject(Constants.Properties.VECTOR_EMBEDDING_POLICY,
VectorEmbeddingPolicy.class);
this.cosmosVectorEmbeddingPolicy = super.getObject(Constants.Properties.VECTOR_EMBEDDING_POLICY,
CosmosVectorEmbeddingPolicy.class);
}
}
return this.vectorEmbeddingPolicy;
return this.cosmosVectorEmbeddingPolicy;
}

/**
Expand All @@ -435,11 +435,11 @@ public VectorEmbeddingPolicy getVectorEmbeddingPolicy() {
*
* @param value the Vector Embedding Policy.
*/
public void setVectorEmbeddingPolicy(VectorEmbeddingPolicy value) {
public void setVectorEmbeddingPolicy(CosmosVectorEmbeddingPolicy value) {
if (value == null) {
throw new IllegalArgumentException("VectorEmbeddingPolicy cannot be null.");
throw new NullPointerException("VectorEmbeddingPolicy cannot be null.");
}
this.vectorEmbeddingPolicy = value;
this.cosmosVectorEmbeddingPolicy = value;
setProperty(this, Constants.Properties.VECTOR_EMBEDDING_POLICY, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public CosmosContainerProperties setClientEncryptionPolicy(ClientEncryptionPolic
*
* @return the Vector Embedding Policy.
*/
public VectorEmbeddingPolicy getVectorEmbeddingPolicy() {
public CosmosVectorEmbeddingPolicy getVectorEmbeddingPolicy() {
return this.documentCollection.getVectorEmbeddingPolicy();
}

Expand All @@ -364,7 +364,7 @@ public VectorEmbeddingPolicy getVectorEmbeddingPolicy() {
* @param value the Vector Embedding Policy.
* @return the CosmosContainerProperties.
*/
public CosmosContainerProperties setVectorEmbeddingPolicy(VectorEmbeddingPolicy value) {
public CosmosContainerProperties setVectorEmbeddingPolicy(CosmosVectorEmbeddingPolicy value) {
this.documentCollection.setVectorEmbeddingPolicy(value);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Embedding settings within {@link VectorEmbeddingPolicy}
* Embedding settings within {@link CosmosVectorEmbeddingPolicy}
*/
public final class CosmosVectorEmbedding {
@JsonProperty(Constants.Properties.PATH)
Expand All @@ -21,21 +21,6 @@ public final class CosmosVectorEmbedding {
private String cosmosVectorDistanceFunction;
private JsonSerializable jsonSerializable;

/**
* Constructor
*
* @param path path for the cosmosVectorEmbedding
* @param vectorDataType data type for the embedding
* @param dimensions dimensions for the embedding
* @param distanceFunction distanceFunction for the embedding
*/
public CosmosVectorEmbedding(String path, String vectorDataType, Long dimensions, String distanceFunction) {
this.path = path;
this.cosmosVectorDataType = vectorDataType;
this.dimensions = dimensions;
this.cosmosVectorDistanceFunction = distanceFunction;
}

/**
* Constructor
*/
Expand Down Expand Up @@ -68,8 +53,8 @@ public CosmosVectorEmbedding setPath(String path) {
*
* @return cosmosVectorDataType
*/
public String getCosmosVectorDataType() {
return cosmosVectorDataType;
public CosmosVectorDataType getVectorDataType() {
return CosmosVectorDataType.valueOf(cosmosVectorDataType);
}

/**
Expand All @@ -78,8 +63,8 @@ public String getCosmosVectorDataType() {
* @param cosmosVectorDataType the data type for the cosmosVectorEmbedding
* @return CosmosVectorEmbedding
*/
public CosmosVectorEmbedding setCosmosVectorDataType(String cosmosVectorDataType) {
this.cosmosVectorDataType = cosmosVectorDataType;
public CosmosVectorEmbedding setVectorDataType(CosmosVectorDataType cosmosVectorDataType) {
this.cosmosVectorDataType = cosmosVectorDataType.toString();
return this;
}

Expand Down Expand Up @@ -108,8 +93,8 @@ public CosmosVectorEmbedding setDimensions(Long dimensions) {
*
* @return cosmosVectorDistanceFunction
*/
public String getCosmosVectorDistanceFunction() {
return cosmosVectorDistanceFunction;
public CosmosVectorDistanceFunction getVectorDistanceFunction() {
return CosmosVectorDistanceFunction.valueOf(cosmosVectorDistanceFunction);
}

/**
Expand All @@ -118,8 +103,8 @@ public String getCosmosVectorDistanceFunction() {
* @param cosmosVectorDistanceFunction the distanceFunction for the cosmosVectorEmbedding
* @return CosmosVectorEmbedding
*/
public CosmosVectorEmbedding setCosmosVectorDistanceFunction(String cosmosVectorDistanceFunction) {
this.cosmosVectorDistanceFunction = cosmosVectorDistanceFunction;
public CosmosVectorEmbedding setVectorDistanceFunction(CosmosVectorDistanceFunction cosmosVectorDistanceFunction) {
this.cosmosVectorDistanceFunction = cosmosVectorDistanceFunction.toString();
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
/**
* Vector Embedding Policy
*/
public final class VectorEmbeddingPolicy {
public final class CosmosVectorEmbeddingPolicy {

private JsonSerializable jsonSerializable;

/**
* Paths for embeddings along with path-specific settings for the item.
*/
Expand All @@ -29,16 +28,10 @@ public final class VectorEmbeddingPolicy {
*
* @param cosmosVectorEmbeddings list of path for embeddings along with path-specific settings for the item.
*/
public VectorEmbeddingPolicy(List<CosmosVectorEmbedding> cosmosVectorEmbeddings) {
public CosmosVectorEmbeddingPolicy(List<CosmosVectorEmbedding> cosmosVectorEmbeddings) {
validateEmbeddings(cosmosVectorEmbeddings);
this.cosmosVectorEmbeddings = cosmosVectorEmbeddings;
}

/**
* Constructor.
*/
public VectorEmbeddingPolicy() {
this.jsonSerializable = new JsonSerializable();
this.setCosmosVectorEmbeddings(cosmosVectorEmbeddings);
}

private static void validateEmbeddings(List<CosmosVectorEmbedding> cosmosVectorEmbeddings) {
Expand All @@ -48,14 +41,14 @@ private static void validateEmbeddings(List<CosmosVectorEmbedding> cosmosVectorE
}
validateEmbeddingPath(embedding.getPath());
validateEmbeddingDimensions(embedding.getDimensions());
validateEmbeddingVectorDataType(embedding.getCosmosVectorDataType());
validateEmbeddingDistanceFunction(embedding.getCosmosVectorDistanceFunction());
validateEmbeddingVectorDataType(embedding.getVectorDataType());
validateEmbeddingDistanceFunction(embedding.getVectorDistanceFunction());
});
}

private static void validateEmbeddingPath(String path) {
if (StringUtils.isEmpty(path)) {
throw new IllegalArgumentException("embedding path is empty");
throw new NullPointerException("embedding path is empty");
}

if (path.charAt(0) != '/' || path.lastIndexOf('/') != 0) {
Expand All @@ -65,7 +58,7 @@ private static void validateEmbeddingPath(String path) {

private static void validateEmbeddingDimensions(Long dimensions) {
if (dimensions == null) {
throw new IllegalArgumentException("Dimensions for the embedding cannot be null " +
throw new NullPointerException("Dimensions for the embedding cannot be null " +
"for the vector embedding policy");
}
if (dimensions < 1) {
Expand All @@ -74,16 +67,16 @@ private static void validateEmbeddingDimensions(Long dimensions) {
}
}

private static void validateEmbeddingVectorDataType(String value) {
private static void validateEmbeddingVectorDataType(CosmosVectorDataType value) {
if (Arrays.stream(CosmosVectorDataType.values()).noneMatch(vectorDataType ->
vectorDataType.toString().equals(value))) {
vectorDataType.equals(value))) {
throw new IllegalArgumentException("Invalid vector data type for the vector embedding policy.");
}
}

private static void validateEmbeddingDistanceFunction(String value) {
private static void validateEmbeddingDistanceFunction(CosmosVectorDistanceFunction value) {
if (Arrays.stream(CosmosVectorDistanceFunction.values()).noneMatch(distanceFunction ->
distanceFunction.toString().equals(value))) {
distanceFunction.equals(value))) {
throw new IllegalArgumentException("Invalid distance function for the vector embedding policy.");
}
}
Expand All @@ -93,7 +86,17 @@ private static void validateEmbeddingDistanceFunction(String value) {
*
* @return the paths for embeddings along with path-specific settings for the item.
*/
public List<CosmosVectorEmbedding> getCosmosVectorEmbeddings() {
public List<CosmosVectorEmbedding> getVectorEmbeddings() {
return this.cosmosVectorEmbeddings;
}

/**
* Sets the paths for embeddings along with path-specific settings for the item.
*
* @param cosmosVectorEmbeddings paths for embeddings along with path-specific settings for the item.
*/
public void setCosmosVectorEmbeddings(List<CosmosVectorEmbedding> cosmosVectorEmbeddings) {
this.cosmosVectorEmbeddings = cosmosVectorEmbeddings;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Vector Indexes spec for Azure CosmosDB service.
*/
public final class VectorIndexSpec {
public final class CosmosVectorIndexSpec {

private final JsonSerializable jsonSerializable;
private String type;
Expand All @@ -20,24 +20,17 @@ public final class VectorIndexSpec {
*
* @param path the path.
*/
public VectorIndexSpec(String path) {
public CosmosVectorIndexSpec(String path) {
this.jsonSerializable = new JsonSerializable();
this.setPath(path);
}

/**
* Constructor.
*/
public VectorIndexSpec() {
this.jsonSerializable = new JsonSerializable();
}

/**
* Constructor.
*
* @param objectNode the object node that represents the included path.
*/
public VectorIndexSpec(ObjectNode objectNode) { this.jsonSerializable = new JsonSerializable(objectNode); }
private CosmosVectorIndexSpec(ObjectNode objectNode) { this.jsonSerializable = new JsonSerializable(objectNode); }

/**
* Gets path.
Expand All @@ -54,7 +47,7 @@ public String getPath() {
* @param path the path.
* @return the SpatialSpec.
*/
public VectorIndexSpec setPath(String path) {
public CosmosVectorIndexSpec setPath(String path) {
this.jsonSerializable.set(Constants.Properties.PATH, path);
return this;
}
Expand All @@ -81,7 +74,7 @@ public String getType() {
* @param type the vector index type
* @return the VectorIndexSpec
*/
public VectorIndexSpec setType(String type) {
public CosmosVectorIndexSpec setType(String type) {
this.type = type;
this.jsonSerializable.set(Constants.Properties.VECTOR_INDEX_TYPE, this.type);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Defines the index type of vector index specification in the Azure Cosmos DB service.
*/
public enum VectorIndexType {
public enum CosmosVectorIndexType {
/**
* Represents a flat vector index type.
*/
Expand All @@ -25,7 +25,7 @@ public enum VectorIndexType {

private final String overWireValue;

VectorIndexType(String overWireValue) {
CosmosVectorIndexType(String overWireValue) {
this.overWireValue = overWireValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class IndexingPolicy {
private List<ExcludedPath> excludedPaths;
private List<List<CompositePath>> compositeIndexes;
private List<SpatialSpec> spatialIndexes;
private List<VectorIndexSpec> vectorIndexes;
private List<CosmosVectorIndexSpec> vectorIndexes;

/**
* Constructor.
Expand Down Expand Up @@ -266,12 +266,12 @@ public IndexingPolicy setSpatialIndexes(List<SpatialSpec> spatialIndexes) {
*
* @return the vector indexes
*/
public List<VectorIndexSpec> getVectorIndexes() {
public List<CosmosVectorIndexSpec> getVectorIndexes() {
if (this.vectorIndexes == null) {
this.vectorIndexes = this.jsonSerializable.getList(Constants.Properties.VECTOR_INDEXES, VectorIndexSpec.class);
this.vectorIndexes = this.jsonSerializable.getList(Constants.Properties.VECTOR_INDEXES, CosmosVectorIndexSpec.class);

if (this.vectorIndexes == null) {
this.vectorIndexes = new ArrayList<VectorIndexSpec>();
this.vectorIndexes = new ArrayList<CosmosVectorIndexSpec>();
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ public List<VectorIndexSpec> getVectorIndexes() {
* @param vectorIndexes the vector indexes
* @return the Indexing Policy.
*/
public IndexingPolicy setVectorIndexes(List<VectorIndexSpec> vectorIndexes) {
public IndexingPolicy setVectorIndexes(List<CosmosVectorIndexSpec> vectorIndexes) {
this.vectorIndexes = vectorIndexes;
this.jsonSerializable.set(Constants.Properties.VECTOR_INDEXES,this.vectorIndexes);
return this;
Expand Down