add try catch
This commit is contained in:
parent
f2c1777ea9
commit
a7bc5fca88
|
|
@ -32,20 +32,28 @@ public partial class KnowledgeService
|
|||
|
||||
public async Task<IEnumerable<KnowledgeRetrievalResult>> SearchKnowledge(string collectionName, KnowledgeRetrievalOptions options)
|
||||
{
|
||||
var textEmbedding = GetTextEmbedding();
|
||||
var vector = await textEmbedding.GetVectorAsync(options.Text);
|
||||
|
||||
// Vector search
|
||||
var db = GetVectorDb();
|
||||
var fields = !options.Fields.IsNullOrEmpty() ? options.Fields : new List<string> { KnowledgePayloadName.Text, KnowledgePayloadName.Answer };
|
||||
var found = await db.Search(collectionName, vector, fields, limit: options.Limit ?? 5, confidence: options.Confidence ?? 0.5f, withVector: options.WithVector);
|
||||
|
||||
var results = found.Select(x => new KnowledgeRetrievalResult
|
||||
try
|
||||
{
|
||||
Data = x.Data,
|
||||
Score = x.Score,
|
||||
Vector = x.Vector
|
||||
}).ToList();
|
||||
return results;
|
||||
var textEmbedding = GetTextEmbedding();
|
||||
var vector = await textEmbedding.GetVectorAsync(options.Text);
|
||||
|
||||
// Vector search
|
||||
var db = GetVectorDb();
|
||||
var fields = !options.Fields.IsNullOrEmpty() ? options.Fields : new List<string> { KnowledgePayloadName.Text, KnowledgePayloadName.Answer };
|
||||
var found = await db.Search(collectionName, vector, fields, limit: options.Limit ?? 5, confidence: options.Confidence ?? 0.5f, withVector: options.WithVector);
|
||||
|
||||
var results = found.Select(x => new KnowledgeRetrievalResult
|
||||
{
|
||||
Data = x.Data,
|
||||
Score = x.Score,
|
||||
Vector = x.Vector
|
||||
}).ToList();
|
||||
return results;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning($"Error when searching knowledge ({collectionName}). {ex.Message}\r\n{ex.InnerException}");
|
||||
return new List<KnowledgeRetrievalResult>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue