-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVectorIndexOptions.cs
More file actions
90 lines (73 loc) · 2.42 KB
/
VectorIndexOptions.cs
File metadata and controls
90 lines (73 loc) · 2.42 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
82
83
84
85
86
87
88
89
90
using System;
namespace Mythosia.VectorDb.Postgres;
/// <summary>
/// Base type for vector index settings.
/// </summary>
public abstract class VectorIndexOptions
{
/// <summary>
/// Index algorithm represented by this settings object.
/// </summary>
public abstract IndexType IndexType { get; }
internal abstract void Validate();
}
/// <summary>
/// HNSW index settings.
/// </summary>
public sealed class HnswIndexOptions : VectorIndexOptions
{
public override IndexType IndexType => IndexType.Hnsw;
/// <summary>
/// HNSW: max connections per node. Default: 16.
/// </summary>
public int M { get; set; } = 16;
/// <summary>
/// HNSW: search scope during index build. Default: 64.
/// </summary>
public int EfConstruction { get; set; } = 64;
/// <summary>
/// HNSW runtime ef_search default for search. Default: 40.
/// </summary>
public int EfSearch { get; set; } = 40;
internal override void Validate()
{
if (M <= 0)
throw new ArgumentException("HnswIndexOptions.M must be greater than 0.", nameof(M));
if (EfConstruction <= 0)
throw new ArgumentException("HnswIndexOptions.EfConstruction must be greater than 0.", nameof(EfConstruction));
if (EfSearch <= 0)
throw new ArgumentException("HnswIndexOptions.EfSearch must be greater than 0.", nameof(EfSearch));
}
}
/// <summary>
/// IVFFlat index settings.
/// </summary>
public sealed class IvfFlatIndexOptions : VectorIndexOptions
{
public override IndexType IndexType => IndexType.IvfFlat;
/// <summary>
/// Number of IVF lists for the ivfflat index. Default: 100.
/// </summary>
public int Lists { get; set; } = 100;
/// <summary>
/// IVFFlat runtime probes default for search. Default: 10.
/// </summary>
public int Probes { get; set; } = 10;
internal override void Validate()
{
if (Lists <= 0)
throw new ArgumentException("IvfFlatIndexOptions.Lists must be greater than 0.", nameof(Lists));
if (Probes <= 0)
throw new ArgumentException("IvfFlatIndexOptions.Probes must be greater than 0.", nameof(Probes));
}
}
/// <summary>
/// Disables vector index creation and runtime index tuning.
/// </summary>
public sealed class NoIndexOptions : VectorIndexOptions
{
public override IndexType IndexType => IndexType.None;
internal override void Validate()
{
}
}