Skip to content

Commit f18674d

Browse files
committed
Convert to pydantic and update docs
1 parent f1374e9 commit f18674d

File tree

5 files changed

+121
-125
lines changed

5 files changed

+121
-125
lines changed

docs/api/schema.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ FLAT - Brute-force exact search. **Best for small datasets (<10K vectors) requir
262262
:color: info
263263

264264
**Use FLAT when:**
265-
- Small datasets (<10K vectors) where exact results are required
265+
- Small datasets (<100K vectors) where exact results are required
266266
- Search accuracy is critical and approximate results are not acceptable
267267
- Baseline comparisons when evaluating approximate algorithms
268268
- Simple use cases where setup simplicity is more important than performance
@@ -317,7 +317,7 @@ Algorithm Selection Guide
317317
- Memory Usage
318318
- Trade-offs
319319
* - **FLAT**
320-
- Small datasets (<10K vectors)
320+
- Small datasets (<100K vectors)
321321
- 100% recall, O(n) search
322322
- Minimal overhead
323323
- Exact but slow for large data

docs/user_guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ User guides provide helpful resources for using RedisVL and its different compon
2222
07_message_history
2323
08_semantic_router
2424
09_svs_vamana
25+
10_embeddings_cache
2526
```

redisvl/schema/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- NumericField: Numeric values for range queries and sorting
1010
- GeoField: Geographic coordinates for location-based search
1111
- VectorField: Vector embeddings for semantic similarity search
12-
- FlatVectorField: Brute-force exact search (100% recall)
12+
- FlatVectorField: Exact search (100% recall)
1313
- HNSWVectorField: Approximate nearest neighbor search (fast, high recall)
1414
- SVSVectorField: Compressed vector search with memory savings
1515
@@ -489,7 +489,7 @@ def as_redis_field(self) -> RedisField:
489489

490490

491491
class FlatVectorField(BaseField):
492-
"""Vector field with FLAT (brute-force) indexing for exact nearest neighbor search."""
492+
"""Vector field with FLAT (exact search) indexing for exact nearest neighbor search."""
493493

494494
type: Literal[FieldTypes.VECTOR] = FieldTypes.VECTOR
495495
attrs: FlatVectorFieldAttributes

redisvl/utils/compression.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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

2832
class 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

Comments
 (0)