-
Notifications
You must be signed in to change notification settings - Fork 29
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
A tested demonstration of C# floating vector insertion #14
Comments
Sorry, there is an error here. I released a new version(2.2.1-alpha.4) and created a pr for this.I tested it in notebooks, this is the code based on your code. Create a client.#r "nuget: IO.Milvus, 2.2.1-alpha.4"
#!import config/Settings.cs
using IO.Milvus;
using IO.Milvus.Client;
using IO.Milvus.Client.gRPC;
using IO.Milvus.Client.REST;
using InteractiveKernel = Microsoft.DotNet.Interactive.Kernel;
//Connect to milvus
(string endpoint,int port,string userName,string password) = Settings.LoadFromFile();
IMilvusClient milvusClient = default;
milvusClient = new MilvusGrpcClient(endpoint,port,userName,password);
milvusClient Create a collectionusing System.Diagnostics;
string collectionName = "test";
//Check if this collection exists
var hasCollection = await milvusClient.HasCollectionAsync(collectionName);
if(hasCollection){
await milvusClient.DropCollectionAsync(collectionName);
Console.WriteLine("Drop collection {0}",collectionName);
}
var fieldTypes = new[] {
FieldType.CreateVarchar("Id",40,isPrimaryKey:true),
FieldType.CreateFloatVector("TextVector",512)};
await milvusClient.CreateCollectionAsync(
collectionName,
fieldTypes
); Insert vectorsRandom ran = new Random();
List<string> idArray = new();
List<List<float>> vectorArray = new();
for (int i = 0; i < 2000; ++i)
{
idArray.Add(i.ToString());
List<float> vector = new();
for (int k = 0; k < 512; ++k)
{
vector.Add(ran.Next());
}
vectorArray.Add(vector);
}
MilvusMutationResult result = await milvusClient.InsertAsync(collectionName,
new Field[]
{
Field.Create(fieldTypes[0].Name,idArray),
Field.CreateFloatVector(fieldTypes[1].Name,vectorArray),
});
result ResultSource FileThis is the notebook i used. |
@RockNHawk You can find the notebooks here https://github.com/milvus-io/milvus-sdk-csharp/tree/dev-milvus2.x_muti_client/docs/notebooks |
Chinese ? Milvus 是国产吗,我看到 gitee 上有主页。 |
@RockNHawk 是的 made in china. |
It's so cool !! |
Hi, currently testing the code given above (for the REST client) with this deployment: Milvus Version : 2.2.8 locally deployed using docker compose I am getting the following errors for:
I tested the search directly with Attu visual client and works correctly. I assume it's just because of the version difference, could you state in docs which milvus version this SDK supports or is tested on. Can I assume its correlated, as in I can only use Milvus Version 2.2.1 at the moment? Thanks in advance! |
@FrasWasim There is not a restful api that support GetLoadingProgressAsync method,so 404 throws.I will note it in the next version.About searchasync error, I don not any idea now.Can you give me more information about this error. |
@weianweigan Thanks for the quick response - since I was using custom code to test, I cloned this C# SDK source code, checked out your branch [dev-milvus2.x_muti_client], and ran the unit tests: SearchTest fails for same reason - 400 bad request. The milvus I am using is the standalone: I tried v2.2.1 but no luck either. |
@FrasWasim, I checked the code and found an issue with the JSON converter. The parameters in Milvus use the { key: "key", value: "value" } format, but C# does not. I forgot to add the [JsonConverter] attribute in SearchParameter, which caused a 400 error. This is the error message: {
"error_code": 5,
"reason": "bad request: parse body failed: json: cannot unmarshal object into Go struct field SearchRequest.search_params of type []*commonpb.KeyValuePair"
}
To fix this, I will add a custom JSON converter attribute in SearchRequest.cs: /// <summary>
/// Search parameters
/// </summary>
[JsonPropertyName("search_params")]
[JsonConverter(typeof(MilvusDictionaryConverter))]
public IDictionary<string, string> SearchParams { get; set; } = new Dictionary<string, string>(); There is no relationship between the C# SDK version and Milvus version now. The C# SDK is currently targeting Milvus v2.2.x, and I am also using v2.2.8. You can use MilvusGRPCClient now. The JSON schema that the RESTful API uses is not very clear, so I need to do more testing to ensure the response JSON format. |
The IGrpcRequest, IRestRequest, and IValidatable interfaces don't seem to be serving a purpose. They're implemented but never consumed.
Important .NET version is implemented differently than the Java version, sometimes you can refer to the java version code and sometimes it doesn't work, you may need to check the .NET SDK source code to determine how to use it.
You should use
DataType.FloatVector
in Field Definition, but useBinaryVectorField
when inserting.Field<List<float>>
is not worked.these folling code is not work for float vector:
---- full codes ----
The text was updated successfully, but these errors were encountered: