Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,33 @@
namespace Weaviate.Client.Tests.Integration;

/// <summary>
/// Integration tests for deleting vector indices via
/// DELETE /schema/{className}/vectors/{vectorIndexName}/index
/// </summary>
[Collection("TestCollectionVectorIndex")]
public class TestCollectionVectorIndex : IntegrationTests
{
/// <summary>
/// DeleteVectorIndex drops the vector index for a named vector on a 1.37+ server.
/// </summary>
[Fact]
public async Task DeleteVectorIndex_DropsVectorIndex()
{
RequireVersion<CollectionConfigClient>(
nameof(CollectionConfigClient.DeleteVectorIndex)
);

var collection = await CollectionFactory(
vectorConfig:
[
Configure.Vector("myVector", v => v.SelfProvided()),
]
);

// Should not throw on a 1.37+ server
await collection.Config.DeleteVectorIndex(
"myVector",
TestContext.Current.CancellationToken
);
}
}
72 changes: 72 additions & 0 deletions src/Weaviate.Client.Tests/Unit/TestCollectionVectorIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Weaviate.Client.Tests.Unit.Mocks;

namespace Weaviate.Client.Tests.Unit;

/// <summary>
/// Tests for deleting vector indices via
/// DELETE /schema/{className}/vectors/{vectorIndexName}/index
/// </summary>
public class CollectionVectorIndexTests
{
/// <summary>
/// DeleteVectorIndex throws WeaviateVersionMismatchException when server version is below 1.37
/// </summary>
[Fact]
public async Task DeleteVectorIndex_OnServerBelow1_37_ThrowsVersionMismatchException()
{
var (client, _) = MockWeaviateClient.CreateWithMockHandler(serverVersion: "1.36.0");

await Assert.ThrowsAsync<WeaviateVersionMismatchException>(() =>
client
.Collections.Use("Article")
.Config.DeleteVectorIndex(
"myVector",
TestContext.Current.CancellationToken
)
);
}

/// <summary>
/// DeleteVectorIndex sends a DELETE to the correct endpoint path for a named vector
/// </summary>
[Fact]
public async Task DeleteVectorIndex_SendsDeleteToCorrectPath()
{
var (client, handler) = MockWeaviateClient.CreateWithMockHandler();
handler.AddResponse(MockResponses.Ok());

await client
.Collections.Use("Article")
.Config.DeleteVectorIndex(
"myVector",
TestContext.Current.CancellationToken
);

Assert.NotNull(handler.LastRequest);
handler
.LastRequest!.ShouldHaveMethod(HttpMethod.Delete)
.ShouldHavePath("/v1/schema/Article/vectors/myVector/index");
}

/// <summary>
/// DeleteVectorIndex sends a DELETE to the correct endpoint path for the default vector
/// </summary>
[Fact]
public async Task DeleteVectorIndex_DefaultVector_SendsDeleteToCorrectPath()
{
var (client, handler) = MockWeaviateClient.CreateWithMockHandler();
handler.AddResponse(MockResponses.Ok());

await client
.Collections.Use("Article")
.Config.DeleteVectorIndex(
"default",
TestContext.Current.CancellationToken
);

Assert.NotNull(handler.LastRequest);
handler
.LastRequest!.ShouldHaveMethod(HttpMethod.Delete)
.ShouldHavePath("/v1/schema/Article/vectors/default/index");
}
}
24 changes: 24 additions & 0 deletions src/Weaviate.Client/CollectionConfigClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,30 @@ await _client.RestClient.CollectionDeletePropertyIndex(
);
}

/// <summary>
/// Deletes the vector index for a named vector in this collection.
/// Requires Weaviate server version 1.37.0 or later.
/// </summary>
/// <param name="vectorName">The name of the vector whose index should be deleted.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <exception cref="WeaviateVersionMismatchException">
/// Thrown when the connected server version is below 1.37.0.
/// </exception>
[RequiresWeaviateVersion(1, 37, 0)]
public async Task DeleteVectorIndex(
string vectorName,
CancellationToken cancellationToken = default
)
{
await _client.EnsureVersion<CollectionConfigClient>();

await _client.RestClient.CollectionDeleteVectorIndex(
_collectionName,
vectorName,
cancellationToken
);
}

// Add new named vectors
/// <summary>
/// Adds a new named vector to the collection.
Expand Down
1 change: 1 addition & 0 deletions src/Weaviate.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,7 @@ Weaviate.Client.CollectionConfigClient.AddProperty(Weaviate.Client.Models.Proper
Weaviate.Client.CollectionConfigClient.AddReference(Weaviate.Client.Models.Reference! referenceProperty, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
Weaviate.Client.CollectionConfigClient.AddVector(Weaviate.Client.Models.VectorConfig! vector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
Weaviate.Client.CollectionConfigClient.DeletePropertyIndex(string! propertyName, Weaviate.Client.Models.PropertyIndexType indexType, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
Weaviate.Client.CollectionConfigClient.DeleteVectorIndex(string! vectorName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
Weaviate.Client.CollectionConfigClient.Get(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Weaviate.Client.Models.CollectionConfigExport!>!
Weaviate.Client.CollectionConfigClient.GetCachedConfig(Weaviate.Client.Cache.SchemaCache? schemaCache = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Weaviate.Client.Models.CollectionConfig?>!
Weaviate.Client.CollectionConfigClient.GetShard(string! shardName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Weaviate.Client.Models.ShardInfo?>!
Expand Down
26 changes: 26 additions & 0 deletions src/Weaviate.Client/Rest/Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,32 @@ await response.ManageStatusCode(
);
}

/// <summary>
/// Deletes the vector index for a named vector in a collection.
/// </summary>
/// <param name="collectionName">The collection name</param>
/// <param name="vectorIndexName">The vector index name</param>
/// <param name="cancellationToken">The cancellation token</param>
internal async Task CollectionDeleteVectorIndex(
string collectionName,
string vectorIndexName,
CancellationToken cancellationToken = default
)
{
var path = WeaviateEndpoints.CollectionVectorIndex(
collectionName,
vectorIndexName
);

var response = await _httpClient.DeleteAsync(path, cancellationToken);

await response.ManageStatusCode(
[HttpStatusCode.OK],
"collection vector index delete",
ResourceType.Collection
);
}

/// <summary>
/// Collections the exists using the specified collection name
/// </summary>
Expand Down
97 changes: 84 additions & 13 deletions src/Weaviate.Client/Rest/Dto/Models.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ internal partial record ExportStatusResponse

public System.DateTimeOffset? StartedAt { get; set; } = default!;

/// <summary>
/// When the export completed (successfully, with failure, or was canceled)
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("completedAt")]

public System.DateTimeOffset? CompletedAt { get; set; } = default!;

/// <summary>
/// Duration of the export in milliseconds
/// </summary>
Expand Down Expand Up @@ -3046,6 +3054,78 @@ internal partial record DistributedTask

public System.Collections.Generic.IDictionary<string, object>? Payload { get; set; } = default!;

/// <summary>
/// Units of the task. Only present for tasks that use unit tracking.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("units")]

public System.Collections.Generic.IList<DistributedTaskUnit>? Units { get; set; } = default!;

}

/// <summary>
/// A unit of a distributed task.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.1.0 (NJsonSchema v11.5.1.0 (Newtonsoft.Json v13.0.0.0))")]
internal partial record DistributedTaskUnit
{
/// <summary>
/// The ID of the unit.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("id")]

public string? Id { get; set; } = default!;

/// <summary>
/// The node that owns this unit.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("nodeId")]

public string? NodeId { get; set; } = default!;

/// <summary>
/// The status of the unit.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("status")]

public string? Status { get; set; } = default!;

/// <summary>
/// The progress of the unit (0.0 to 1.0).
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("progress")]

public float? Progress { get; set; } = default!;

/// <summary>
/// The error message if the unit failed.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("error")]

public string? Error { get; set; } = default!;

/// <summary>
/// The time when the unit was last updated.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("updatedAt")]

public System.DateTimeOffset? UpdatedAt { get; set; } = default!;

/// <summary>
/// The time when the unit finished.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("finishedAt")]

public System.DateTimeOffset? FinishedAt { get; set; } = default!;

}

/// <summary>
Expand Down Expand Up @@ -4823,32 +4903,23 @@ internal enum ExportStatusResponseStatus
[System.Text.Json.Serialization.JsonStringEnumMemberName(@"CANCELED")]
CANCELED = 4,

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"SKIPPED")]
SKIPPED = 5,

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.1.0 (NJsonSchema v11.5.1.0 (Newtonsoft.Json v13.0.0.0))")]
internal enum ShardProgressStatus
{

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"STARTED")]
STARTED = 0,

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"TRANSFERRING")]
TRANSFERRING = 1,
TRANSFERRING = 0,

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"SUCCESS")]
SUCCESS = 2,
SUCCESS = 1,

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"FAILED")]
FAILED = 3,

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"CANCELED")]
CANCELED = 4,
FAILED = 2,

[System.Text.Json.Serialization.JsonStringEnumMemberName(@"SKIPPED")]
SKIPPED = 5,
SKIPPED = 3,

}

Expand Down
11 changes: 11 additions & 0 deletions src/Weaviate.Client/Rest/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ internal static string CollectionPropertyIndex(
string indexName
) => $"schema/{className}/properties/{propertyName}/index/{indexName}";

/// <summary>
/// Path for deleting the vector index of a named vector in a collection.
/// </summary>
/// <param name="className">The class name</param>
/// <param name="vectorIndexName">The vector index name</param>
/// <returns>The string</returns>
internal static string CollectionVectorIndex(
string className,
string vectorIndexName
) => $"schema/{className}/vectors/{vectorIndexName}/index";

/// <summary>
/// Collections the shard using the specified class name
/// </summary>
Expand Down
Loading
Loading