Error: Unhandled exception. System.AggregateException: One or more errors occurred. with HTTP status code: BadRequest. Content: {"object":"error","message":"Invalid model: None","type":"invalid_model","param":null,"code":"1500"}).
public class Model
{
private List<ChatMessage> _chatHistory = [];
private const string DocumentPath = "posts.txt";
private const string QdrantCollectionName = "HotDog_Project";
private ISemanticTextMemory _memory;
private MistralClient _client;
public Model(string mistralApiKey,string qdrantApiKey ,string qdrantEndPoint)
{
var mistralApiAuth = new APIAuthentication(mistralApiKey);
_client = new MistralClient(mistralApiAuth);
HttpClient qdrantHttpClient = new HttpClient();
qdrantHttpClient.BaseAddress = new Uri(qdrantEndPoint);
qdrantHttpClient.DefaultRequestHeaders.Add("api-key", qdrantApiKey);
var qdrantClient = new QdrantVectorDbClient(qdrantHttpClient,512);
var embeddingService = _client.Embeddings.AsTextEmbeddingGenerationService();
_memory = new SemanticTextMemory(new QdrantMemoryStore(qdrantClient),
embeddingService);
Task.Run(async () => await LoadAndEmbedDocuments()).Wait();
}
private async Task LoadAndEmbedDocuments()
{
// reading and splitting the text
var documentText = await File.ReadAllTextAsync(DocumentPath);
var chunks = SplitTextIntoChunks(documentText, 300);
// embedding text
foreach (var (chunk, index) in chunks.Select((chunk, index) => (chunk, index)))
{
var chunkId = $"chunk_{index}"; // Example: "chunk_0", "chunk_1"
**await _memory.SaveInformationAsync(QdrantCollectionName, chunk, chunkId);**
}
}
The error originates from the _memory.SaveInformationAsync function that tries to automatically use the registered mistral embedding text embedding service. I get that the reason for the bad request is that the "model" is missing in the request headers but I cannot find a way to customize the request headers to add the model parameter.
I tried creating a separate client for embedding and doing the following:
var embeddingHttpClient = new HttpClient();
embeddingHttpClient.DefaultRequestHeaders.Add("model",ModelDefinitions.MistralEmbed);
var embeddingClient = new MistralClient(mistralApiAuth, embeddingHttpClient);
var embeddingService = embeddingClient.Embeddings.AsTextEmbeddingGenerationService();
_memory = new SemanticTextMemory(new QdrantMemoryStore(qdrantClient),
embeddingService);
This doesn't work either.
I also checked the Mistral.SDK documentation but it does not show an example for integrating with the SemanticTextMemory object.