forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOllamaEmbeddingsConfig.cs
More file actions
53 lines (45 loc) · 1.57 KB
/
OllamaEmbeddingsConfig.cs
File metadata and controls
53 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json.Serialization;
using KernelMemory.Core.Config.Enums;
using KernelMemory.Core.Config.Validation;
namespace KernelMemory.Core.Config.Embeddings;
/// <summary>
/// Ollama embeddings provider configuration
/// </summary>
public sealed class OllamaEmbeddingsConfig : EmbeddingsConfig
{
/// <inheritdoc />
[JsonIgnore]
public override EmbeddingsTypes Type => EmbeddingsTypes.Ollama;
/// <summary>
/// Ollama model name (e.g., "nomic-embed-text", "mxbai-embed-large")
/// </summary>
[JsonPropertyName("model")]
public string Model { get; set; } = string.Empty;
/// <summary>
/// Ollama base URL (e.g., "http://localhost:11434")
/// </summary>
[JsonPropertyName("baseUrl")]
public string BaseUrl { get; set; } = "http://localhost:11434";
/// <inheritdoc />
public override void Validate(string path)
{
if (string.IsNullOrWhiteSpace(this.Model))
{
throw new ConfigException($"{path}.Model", "Ollama model name is required");
}
if (string.IsNullOrWhiteSpace(this.BaseUrl))
{
throw new ConfigException($"{path}.BaseUrl", "Ollama base URL is required");
}
if (this.BatchSize < 1)
{
throw new ConfigException($"{path}.BatchSize", "BatchSize must be >= 1");
}
if (!Uri.TryCreate(this.BaseUrl, UriKind.Absolute, out _))
{
throw new ConfigException($"{path}.BaseUrl",
$"Invalid Ollama base URL: {this.BaseUrl}");
}
}
}