forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorSearchIndexConfig.cs
More file actions
81 lines (69 loc) · 2.74 KB
/
Copy pathVectorSearchIndexConfig.cs
File metadata and controls
81 lines (69 loc) · 2.74 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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.SearchIndex;
/// <summary>
/// Vector search index configuration (SQLite with sqlite-vec or PostgreSQL with pgvector)
/// </summary>
public sealed class VectorSearchIndexConfig : SearchIndexConfig
{
/// <summary>
/// Path to SQLite database (for SqliteVector)
/// Mutually exclusive with ConnectionString
/// </summary>
[JsonPropertyName("path")]
public string? Path { get; set; }
/// <summary>
/// PostgreSQL connection string (for PostgresVector)
/// Mutually exclusive with Path
/// </summary>
[JsonPropertyName("connectionString")]
public string? ConnectionString { get; set; }
/// <summary>
/// Vector dimensions (must match embeddings model)
/// Common values: 384 (MiniLM), 768 (BERT), 1536 (OpenAI ada-002), 3072 (OpenAI ada-003)
/// </summary>
[JsonPropertyName("dimensions")]
public int Dimensions { get; set; } = 768;
/// <summary>
/// Distance/similarity metric for vector comparison
/// </summary>
[JsonPropertyName("metric")]
public VectorMetrics Metric { get; set; } = VectorMetrics.Cosine;
/// <inheritdoc />
public override void Validate(string path)
{
this.Embeddings?.Validate($"{path}.Embeddings");
var isSqlite = this.Type == SearchIndexTypes.SqliteVector;
var isPostgres = this.Type == SearchIndexTypes.PostgresVector;
var hasPath = !string.IsNullOrWhiteSpace(this.Path);
var hasConnectionString = !string.IsNullOrWhiteSpace(this.ConnectionString);
if (isSqlite && !hasPath)
{
throw new ConfigException($"{path}.Path", "SQLite vector index requires Path");
}
if (isPostgres && !hasConnectionString)
{
throw new ConfigException($"{path}.ConnectionString",
"PostgreSQL vector index requires ConnectionString");
}
if (hasPath && hasConnectionString)
{
throw new ConfigException(path,
"Vector index: specify either Path (SQLite) or ConnectionString (Postgres), not both");
}
if (this.Dimensions <= 0)
{
throw new ConfigException($"{path}.Dimensions",
$"Vector dimensions must be positive (got {this.Dimensions})");
}
// Common dimensions check (warning, not error)
var commonDimensions = new[] { 384, 768, 1024, 1536, 3072 };
if (!commonDimensions.Contains(this.Dimensions))
{
// Log warning: uncommon dimension size
// This is acceptable, just informational
}
}
}