Skip to content

Commit

Permalink
add tostring() methods and fix some typo
Browse files Browse the repository at this point in the history
  • Loading branch information
weianweigan committed Jun 4, 2023
1 parent 6a70686 commit 4875a23
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 89 deletions.
16 changes: 0 additions & 16 deletions src/IO.Milvus/ApiSchema/ShowCollectionsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@

namespace IO.Milvus.ApiSchema;

/// <summary>
/// Show type
/// </summary>
public enum ShowType
{
/// <summary>
/// Will return all collections
/// </summary>
All = 0,

/// <summary>
/// Will return loaded collections with their inMemory_percentages
/// </summary>
InMemory = 1,
}

/// <summary>
/// ShowCollections
/// </summary>
Expand Down
12 changes: 8 additions & 4 deletions src/IO.Milvus/Client/IMilvusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ Task<MilvusMutationResult> InsertAsync(
/// Delete rows of data entities from a collection by given expression.
/// </summary>
/// <param name="collectionName">Collection name.</param>
/// <param name="expr">Expression.</param>
/// <param name="expr">A predicate expression outputs a boolean value. <see href="https://milvus.io/docs/boolean.md"/></param>
/// <param name="partitionName">Partition name.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns></returns>
Expand Down Expand Up @@ -384,12 +384,16 @@ Task<MilvusSearchResult> SearchAsync(
/// <param name="leftVectors">Vectors on the left side of the operator</param>
/// <param name="rightVectors">Vectors on the right side of the operator</param>
/// <param name="milvusMetricType"><see cref="MilvusMetricType"/>
/// For floating-point vectors:
/// <para>
/// <term>For floating-point vectors:</term>
/// </para>
/// <list type="bullet">
/// <item>L2 (Euclidean distance)</item>
/// <item>IP (Inner product)</item>
/// </list>
/// For binary vectors:
/// <para>
/// <term>For binary vectors:</term>
/// </para>
/// <list type="bullet">
/// <item>JACCARD (Jaccard distance)</item>
/// <item>TANIMOTO (Tanimoto distance)</item>
Expand All @@ -406,7 +410,7 @@ Task<MilvusCalDistanceResult> CalDistanceAsync(
CancellationToken cancellationToken = default);

/// <summary>
/// Flush a collection's data to disk. Milvus's data will be auto flushed.
/// Flush a collection's data to disk. Milvus data will be auto flushed.
/// Flush is only required when you want to get up to date entities numbers in statistics due to some internal mechanism.
/// It will be removed in the future.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/IO.Milvus/Client/REST/MilvusRestClient.Partition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task LoadPartitionsAsync(
int replicaNumber = 1,
CancellationToken cancellationToken = default)
{
this._log.LogDebug("Create partition {0}", collectionName);
this._log.LogDebug("Load partition {0}", collectionName);

using HttpRequestMessage request = LoadPartitionsRequest
.Create(collectionName)
Expand All @@ -129,7 +129,7 @@ public async Task LoadPartitionsAsync(
}
catch (HttpRequestException e)
{
this._log.LogError(e, "Create partition failed: {0}, {1}", e.Message, responseContent);
this._log.LogError(e, "Load partition failed: {0}, {1}", e.Message, responseContent);
throw;
}

Expand Down
11 changes: 10 additions & 1 deletion src/IO.Milvus/CollectionSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ public sealed class CollectionSchema
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
}

/// <summary>
/// Return string value of <see cref="CollectionSchema"/>
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"CollectionSchema: {{{nameof(AutoId)}: {AutoId}, {nameof(Description)}, {Description}, {nameof(Fields)}: {Fields?.Count}}}";
}
}
10 changes: 10 additions & 0 deletions src/IO.Milvus/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text.Json.Serialization;
using IO.Milvus.Diagnostics;
using System.Collections.Specialized;

namespace IO.Milvus;

Expand Down Expand Up @@ -500,6 +501,15 @@ public override Grpc.FieldData ToGrpcFieldData()
return fieldData;
}

/// <summary>
/// Return string value of <see cref="Field{TData}"/>
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"Field: {{{nameof(FieldName)}: {FieldName}, {nameof(DataType)}: {DataType}, {nameof(Data)}: {Data?.Count}, {nameof(RowCount)}: {RowCount}}}";
}

internal void Check()
{
Verify.ArgNotNullOrEmpty(FieldName, $"FieldName cannot be null or empty");
Expand Down
3 changes: 1 addition & 2 deletions src/IO.Milvus/FieldType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using IO.Milvus.Grpc;
using System;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

Expand Down
5 changes: 2 additions & 3 deletions src/IO.Milvus/FloatVectorField.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using IO.Milvus.Grpc;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;

namespace IO.Milvus;
Expand Down Expand Up @@ -31,7 +30,7 @@ public FloatVectorField(
/// </summary>
/// <returns>Field data</returns>
/// <exception cref="Diagnostics.MilvusException"></exception>
public override FieldData ToGrpcFieldData()
public override Grpc.FieldData ToGrpcFieldData()
{
var floatArray = new Grpc.FloatArray();

Expand Down
2 changes: 1 addition & 1 deletion src/IO.Milvus/MilvusClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace IO.Milvus;
public static class MilvusClientExtensions
{
/// <summary>
/// Use showCollection() to check loading percentages of the collection.
/// Use <see cref="IMilvusClient.ShowCollectionsAsync(IList{string}, ShowType, CancellationToken)"/> to check loading percentages of the collection.
/// </summary>
/// <remarks>
/// If the inMemory percentage is 100, that means the collection has finished loading.
Expand Down
8 changes: 8 additions & 0 deletions src/IO.Milvus/MilvusCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ internal MilvusCollection(
/// Load percentage on query node when type is InMemory.
/// </summary>
public long InMemoryPercentage { get; }

/// <summary>
/// Return string value of <see cref="MilvusCollection"/>.
/// </summary>
public override string ToString()
{
return $"MilvusCollection: {{{nameof(CollectionName)}: {CollectionName}, {nameof(CollectionId)}: {CollectionId}, {nameof(CreatedUtcTime)}:{CreatedUtcTime}, {nameof(InMemoryPercentage)}: {InMemoryPercentage}}}";
}
}
5 changes: 4 additions & 1 deletion src/IO.Milvus/MilvusDslType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public enum MilvusDslType
Dsl = 0,

/// <summary>
///
/// A predicate expression outputs a boolean value.
/// </summary>
/// <remarks>
/// <see href="https://milvus.io/docs/boolean.md"/>
/// </remarks>
BoolExprV1 = 1,
}
File renamed without changes.
9 changes: 9 additions & 0 deletions src/IO.Milvus/MilvusIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ public MilvusIndex(
/// Contains index_type, metric_type, params.
/// </summary>
public IDictionary<string, string> Params { get; }

/// <summary>
/// Get string data of <see cref="MilvusIndex"/>
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"MilvusIndex: {{{nameof(FieldName)}: {FieldName}, {nameof(IndexName)}: {IndexName}, {nameof(IndexId)}: {IndexId}}}";
}
}
20 changes: 14 additions & 6 deletions src/IO.Milvus/MilvusPartition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public MilvusPartition(
{
PartitionId = partitionId;
PartitionName = partitionName;
CreatedUtcTimestamp = createdUtcTimestamp;
CreatedUtcTime = createdUtcTimestamp;
InMemoryPercentage = inMemoryPercentage;
}

/// <summary>
/// Partition id
/// Partition id.
/// </summary>
public long PartitionId { get; }

/// <summary>
/// Partition name
/// Partition name.
/// </summary>
public string PartitionName { get; }

Expand All @@ -46,10 +46,18 @@ public MilvusPartition(
public long InMemoryPercentage { get; }

/// <summary>
/// Create utc time
/// Create utc time.
/// </summary>
/// <remarks>
/// If you want to get a local time, you can use <see cref="DateTime.ToLocalTime"/>
/// If you want to get a local time, you can use <see cref="DateTime.ToLocalTime"/>.
/// </remarks>
public DateTime CreatedUtcTimestamp { get; }
public DateTime CreatedUtcTime { get; }

/// <summary>
/// Return string value of <see cref="MilvusPartition"/>.
/// </summary>
public override string ToString()
{
return $"MilvusPartition: {{{nameof(PartitionName)}: {PartitionName}, {nameof(PartitionId)}: {PartitionId}, {nameof(CreatedUtcTime)}:{CreatedUtcTime}, {nameof(InMemoryPercentage)}: {InMemoryPercentage}}}";
}
}
8 changes: 8 additions & 0 deletions src/IO.Milvus/MilvusPersistentSegmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public MilvusPersistentSegmentInfo(){}
/// </summary>
public MilvusSegmentState State { get; }

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
public override string ToString()
{
return $"MilvusPersistentSegmentInfo {{{nameof(State)}: {State}, {nameof(SegmentId)}: {SegmentId}, {nameof(CollectionId)}: {CollectionId}, {nameof(PartitionId)}: {PartitionId}, {nameof(NumRows)}: {NumRows}}}";
}

internal static IEnumerable<MilvusPersistentSegmentInfo> From(
IEnumerable<PersistentSegmentInfo> infos)
{
Expand Down
45 changes: 0 additions & 45 deletions src/IO.Milvus/MilvusSearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using IO.Milvus.ApiSchema;
using IO.Milvus.Grpc;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

namespace IO.Milvus;

Expand Down Expand Up @@ -51,47 +49,4 @@ private MilvusSearchResult(string collectionName, MilvusSearchResultData results
this.CollectionName = collectionName;
this.Results = results;
}
}

/// <summary>
/// Milvus search result data
/// </summary>
public class MilvusSearchResultData
{
/// <summary>
/// Fields data
/// </summary>
[JsonPropertyName("fields_data")]
[JsonConverter(typeof(MilvusFieldConverter))]
public IList<Field> FieldsData { get; set; }

/// <summary>
/// Ids
/// </summary>
[JsonPropertyName("ids")]
public MilvusIds Ids { get; set; }

/// <summary>
/// Number of queries
/// </summary>
[JsonPropertyName("num_queries")]
public long NumQueries { get; set; }

/// <summary>
/// Scores
/// </summary>
[JsonPropertyName("scores")]
public IList<float> Scores { get; set; }

/// <summary>
/// TopK
/// </summary>
[JsonPropertyName("top_k")]
public long TopK { get; set; }

/// <summary>
/// TopKs
/// </summary>
[JsonPropertyName("topks")]
public IList<long> TopKs { get; set; }
}
47 changes: 47 additions & 0 deletions src/IO.Milvus/MilvusSearchResultData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace IO.Milvus;

/// <summary>
/// Milvus search result data
/// </summary>
public class MilvusSearchResultData
{
/// <summary>
/// Fields data
/// </summary>
[JsonPropertyName("fields_data")]
[JsonConverter(typeof(MilvusFieldConverter))]
public IList<Field> FieldsData { get; set; }

/// <summary>
/// Ids
/// </summary>
[JsonPropertyName("ids")]
public MilvusIds Ids { get; set; }

/// <summary>
/// Number of queries
/// </summary>
[JsonPropertyName("num_queries")]
public long NumQueries { get; set; }

/// <summary>
/// Scores
/// </summary>
[JsonPropertyName("scores")]
public IList<float> Scores { get; set; }

/// <summary>
/// TopK
/// </summary>
[JsonPropertyName("top_k")]
public long TopK { get; set; }

/// <summary>
/// TopKs
/// </summary>
[JsonPropertyName("topks")]
public IList<long> TopKs { get; set; }
}
17 changes: 17 additions & 0 deletions src/IO.Milvus/ShowType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace IO.Milvus;

/// <summary>
/// Show type
/// </summary>
public enum ShowType
{
/// <summary>
/// Will return all collections
/// </summary>
All = 0,

/// <summary>
/// Will return loaded collections with their inMemory_percentages
/// </summary>
InMemory = 1,
}
8 changes: 1 addition & 7 deletions src/IO.MilvusTests/Client/MilvusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
using IO.Milvus.Client;
using IO.Milvus.Diagnostics;
using IO.MilvusTests.Utils;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace IO.MilvusTests.Client;
Expand All @@ -17,7 +11,7 @@ public partial class MilvusClientTests
{
[Theory]
[ClassData(typeof(TestClients))]
public async Task WithMilvusTest(IMilvusClient milvusClient)
public async Task SampleTest(IMilvusClient milvusClient)
{
string collectionName = milvusClient.GetType().Name;

Expand Down
Loading

0 comments on commit 4875a23

Please sign in to comment.