11"""SVS-VAMANA compression configuration utilities."""
22
3- from typing import Literal , Optional , TypedDict , cast
3+ from typing import Literal , Optional
44
5+ from pydantic import BaseModel , Field
56
6- class SVSConfig (TypedDict , total = False ):
7- """SVS-VAMANA configuration dictionary.
7+
8+ class SVSConfig (BaseModel ):
9+ """SVS-VAMANA configuration model.
810
911 Attributes:
1012 algorithm: Always "svs-vamana"
@@ -16,13 +18,15 @@ class SVSConfig(TypedDict, total=False):
1618 search_window_size: Query-time candidates
1719 """
1820
19- algorithm : Literal ["svs-vamana" ]
20- datatype : str
21- compression : str
22- reduce : int # only for LeanVec
23- graph_max_degree : int
24- construction_window_size : int
25- search_window_size : int
21+ algorithm : Literal ["svs-vamana" ] = "svs-vamana"
22+ datatype : Optional [str ] = None
23+ compression : Optional [str ] = None
24+ reduce : Optional [int ] = Field (
25+ default = None , description = "Reduced dimensionality (only for LeanVec)"
26+ )
27+ graph_max_degree : Optional [int ] = None
28+ construction_window_size : Optional [int ] = None
29+ search_window_size : Optional [int ] = None
2630
2731
2832class CompressionAdvisor :
@@ -35,9 +39,9 @@ class CompressionAdvisor:
3539 Examples:
3640 >>> # Get recommendations for high-dimensional vectors
3741 >>> config = CompressionAdvisor.recommend(dims=1536, priority="balanced")
38- >>> config[" compression"]
42+ >>> config. compression
3943 'LeanVec4x8'
40- >>> config[" reduce"]
44+ >>> config. reduce
4145 768
4246
4347 >>> # Estimate memory savings
@@ -95,14 +99,14 @@ def recommend(
9599 Examples:
96100 >>> # High-dimensional embeddings (e.g., OpenAI ada-002)
97101 >>> config = CompressionAdvisor.recommend(dims=1536, priority="memory")
98- >>> config[" compression"]
102+ >>> config. compression
99103 'LeanVec4x8'
100- >>> config[" reduce"]
104+ >>> config. reduce
101105 768
102106
103107 >>> # Lower-dimensional embeddings
104108 >>> config = CompressionAdvisor.recommend(dims=384, priority="speed")
105- >>> config[" compression"]
109+ >>> config. compression
106110 'LVQ4x8'
107111 """
108112 if dims <= 0 :
@@ -118,34 +122,25 @@ def recommend(
118122 }
119123
120124 if priority == "memory" :
121- return cast (
122- SVSConfig ,
123- {
124- ** base ,
125- "compression" : "LeanVec4x8" ,
126- "reduce" : dims // 2 ,
127- "search_window_size" : 20 ,
128- },
125+ return SVSConfig (
126+ ** base ,
127+ compression = "LeanVec4x8" ,
128+ reduce = dims // 2 ,
129+ search_window_size = 20 ,
129130 )
130131 elif priority == "speed" :
131- return cast (
132- SVSConfig ,
133- {
134- ** base ,
135- "compression" : "LeanVec4x8" ,
136- "reduce" : max (256 , dims // 4 ),
137- "search_window_size" : 40 ,
138- },
132+ return SVSConfig (
133+ ** base ,
134+ compression = "LeanVec4x8" ,
135+ reduce = max (256 , dims // 4 ),
136+ search_window_size = 40 ,
139137 )
140138 else : # balanced
141- return cast (
142- SVSConfig ,
143- {
144- ** base ,
145- "compression" : "LeanVec4x8" ,
146- "reduce" : dims // 2 ,
147- "search_window_size" : 30 ,
148- },
139+ return SVSConfig (
140+ ** base ,
141+ compression = "LeanVec4x8" ,
142+ reduce = dims // 2 ,
143+ search_window_size = 30 ,
149144 )
150145
151146 # Lower-dimensional vectors - use LVQ
@@ -159,11 +154,11 @@ def recommend(
159154 }
160155
161156 if priority == "memory" :
162- return cast ( SVSConfig , { ** base , " compression" : " LVQ4"} )
157+ return SVSConfig ( ** base , compression = " LVQ4" )
163158 elif priority == "speed" :
164- return cast ( SVSConfig , { ** base , " compression" : " LVQ4x8"} )
159+ return SVSConfig ( ** base , compression = " LVQ4x8" )
165160 else : # balanced
166- return cast ( SVSConfig , { ** base , " compression" : " LVQ4x4"} )
161+ return SVSConfig ( ** base , compression = " LVQ4x4" )
167162
168163 @staticmethod
169164 def estimate_memory_savings (
0 commit comments