Skip to content
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

使用C# SDK调用SearchAsync方法程序卡住一直不返回 #68

Closed
yaphet266 opened this issue Mar 20, 2024 · 5 comments
Closed

使用C# SDK调用SearchAsync方法程序卡住一直不返回 #68

yaphet266 opened this issue Mar 20, 2024 · 5 comments

Comments

@yaphet266
Copy link

Milvus.Client --version 2.2.2-preview.6
调用InsertAsync方法没有问题,调用Search和Query方法都会卡住不返回,我milvus服务端是用docker-compose启动的单节点版本

@weianweigan
Copy link
Collaborator

不是返回空而是程序卡住了?能贴一下卡住的代码吗?

@yaphet266
Copy link
Author

@weianweigan 这个是我C#的代码,麻烦帮看一下是否有问题

`
public class MilvusRepository
{
private readonly MilvusClient _milvusClient;
public MilvusRepository()
{
_milvusClient = new MilvusClient("localhost", port: 19530);
}

    public async Task<List<TempleteFeature>> SearchTempleteFeatures(float[] vector, List<string> paperCodes)
    {
        try
        {
            var parm = new SearchParameters
            {
                OutputFields = { "Id", "Md5", "ImagePath", "PaperCode" },
                ConsistencyLevel = ConsistencyLevel.Strong,
                Offset = 0,
                ExtraParameters = { ["nprobe"] = "1024" }
            };
            if (paperCodes != null && paperCodes.Count > 0)
            {
                parm.Expression = $"PaperCode in [{string.Join(",", paperCodes)}]";
            }

            var collection = _milvusClient.GetCollection("TempleteFeatures");

            var results = await collection.SearchAsync(
                vectorFieldName: "Vector",
                vectors: new ReadOnlyMemory<float>[] { vector },
                SimilarityMetricType.Ip,
                limit: 5, parm
                );
            List<TempleteFeature> tfs = new List<TempleteFeature>();
            var ids = results.FieldsData.Where(w => w.FieldName == "Id").First() as FieldData<string>;

            var md5s = results.FieldsData.Where(w => w.FieldName == "Md5").First() as FieldData<string>;

            var imagePaths = results.FieldsData.Where(w => w.FieldName == "ImagePath").First() as FieldData<string>;

            var paperCodess = results.FieldsData.Where(w => w.FieldName == "PaperCode").First() as FieldData<string>;

            for (int i = 0; i < results.Scores.Count; i++)
            {
                TempleteFeature temp = new TempleteFeature()
                {
                    Distance = results.Scores[i],
                    Id = ids.Data[i],
                    Md5 = md5s.Data[i],
                    ImagePath = imagePaths.Data[i],
                    PaperCode = paperCodess.Data[i]
                };
                tfs.Add(temp);
            }

            return tfs;
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }
}

`

调用 await collection.LoadAsync();方法也会挂起不返回任何,一直卡住,但是在attu中看是能正常load数据

@yaphet266
Copy link
Author

这个是在attu中看的collection结构
collection

@yaphet266
Copy link
Author

我找到问题的原因了,因为我是在winform中调用Task异步方法,因为写法问题造成死锁了

@weianweigan
Copy link
Collaborator

我找到问题的原因了,因为我是在winform中调用Task异步方法,因为写法问题造成死锁了

可以试试 WPF+CommunityToolkit.Mvvm+IAsyncRelayCommand 来执行异步方法

@weianweigan weianweigan closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants