Skip to content

Commit 4a0c4de

Browse files
authored
Feat/search method study (#24)
Add simple search method functionality to package.
1 parent ed99a49 commit 4a0c4de

18 files changed

+3861
-1386
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ For complete code examples, see the following notebooks:
6969
| Basic grid study | [00_grid_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/main/docs/examples/grid_study/00_grid_study.ipynb) |
7070
| Custom grid study | [01_custom_grid_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/main/docs/examples/grid_study/01_custom_grid_study.ipynb) |
7171
| Bayesian Optimization | [00_bayes_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/main/docs/examples/bayesian_optimization/00_bayes_study.ipynb) |
72+
| Search study | [00_search_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/main/docs/examples/search_study/00_search_study.ipynb) |
7273
| Embedding model comparison | [00_comparison.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/main/docs/examples/comparison/00_comparison.ipynb) |
7374

7475
---
7576

7677
## 🚀 Quick Start
7778

78-
The Retrieval Optimizer supports two *study* types: **Grid** and **Bayesian Optimization**. Each is suited to a different stage of building a high-quality search system.
79+
The Retrieval Optimizer supports three *study* types: **Grid**, **Bayesian Optimization**, and **Search Study**. Each is suited to a different stage of building a high-quality search system.
7980

8081
### Grid
8182

@@ -85,6 +86,10 @@ Use a grid study to explore the impact of different **embedding models** and **r
8586

8687
Once you've identified a solid starting point, use Bayesian optimization to **fine-tune your index configuration**. This mode intelligently selects the most promising combinations to test, in place of exhaustive testing (which is time-consuming). Bayesian optimization mode is especially useful for balancing **cost, speed, and latency** as you work toward a production-ready solution.
8788

89+
### Search Study
90+
91+
Use a search study when you have an **existing Redis index** and want to quickly test different search methods against it without recreating the index or data. This is ideal for A/B testing search strategies or evaluating custom search methods on production data.
92+
8893
## Running a Grid study
8994

9095
#### Study config
@@ -242,6 +247,68 @@ metrics = run_bayes_study(
242247

243248
---
244249

250+
## Running a Search study
251+
252+
Use a search study when you have an **existing Redis index** and want to quickly test different search methods against it without recreating the index or data. This is ideal for A/B testing search strategies or evaluating custom search methods on production data.
253+
254+
### Search study config
255+
```yaml
256+
embedding_model:
257+
dim: 768
258+
dtype: float32
259+
embedding_cache_name: vec-cache
260+
model: sentence-transformers/all-mpnet-base-v2
261+
type: hf
262+
index_name: cars
263+
queries: "../resources/cars/car_queries.json"
264+
qrels: "../resources/cars/car_qrels.json"
265+
ret_k: 6
266+
search_methods:
267+
- base_vector
268+
- pre_filter_vector
269+
study_id: test-search-study
270+
```
271+
272+
### Code
273+
```python
274+
import os
275+
from redis_retrieval_optimizer.search_study import run_search_study
276+
from dotenv import load_dotenv
277+
278+
# load environment variables containing necessary credentials
279+
load_dotenv()
280+
281+
redis_url = os.environ.get("REDIS_URL", "redis://localhost:6379/0")
282+
283+
# Define custom search methods
284+
def gather_vector_results(search_method_input):
285+
# Your vector search implementation
286+
pass
287+
288+
def gather_pre_filter_results(search_method_input):
289+
# Your pre-filtered search implementation
290+
pass
291+
292+
CUSTOM_SEARCH_METHOD_MAP = {
293+
"base_vector": gather_vector_results,
294+
"pre_filter_vector": gather_pre_filter_results
295+
}
296+
297+
metrics = run_search_study(
298+
config_path="search_study_config.yaml",
299+
redis_url=redis_url,
300+
search_method_map=CUSTOM_SEARCH_METHOD_MAP
301+
)
302+
```
303+
304+
### Example output
305+
| search_method | avg_query_time | recall | precision | ndcg |
306+
|-------------------|----------------|--------|-----------|---------|
307+
| base_vector | 0.002605 | 0.9 | 0.23 | 0.717676|
308+
| pre_filter_vector | 0.001177 | 1.0 | 0.25 | 0.914903|
309+
310+
---
311+
245312
## 🔍 Search Methods
246313

247314
Below is a comprehensive table documenting the built-in search methods available in the Retrieval Optimizer:

RELEASE_NOTES_0.3.0.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Redis Retrieval Optimizer v0.3.0 Release Notes
2+
3+
## 🎉 What's New in v0.3.0
4+
5+
Redis Retrieval Optimizer v0.3.0 introduces several major features that make it easier than ever to build and optimize high-performance search systems with Redis. This release focuses on enhanced optimization capabilities, improved search methods, and better integration with modern embedding models.
6+
7+
## 🚀 Major New Features
8+
9+
### 🎛️ Threshold Optimization
10+
**NEW**: Automatically tune semantic cache and router thresholds for optimal performance.
11+
12+
The new threshold optimization feature helps you maximize the performance of RedisVL's Semantic Cache and Semantic Router by automatically finding the best distance thresholds. This feature supports multiple evaluation metrics including F1 score, precision, and recall.
13+
14+
**Key capabilities:**
15+
- **Cache Threshold Optimization**: Optimize thresholds for semantic caches to improve cache hit rates and relevance
16+
- **Router Threshold Optimization**: Fine-tune route thresholds for semantic routers to improve routing accuracy
17+
- **Multiple Evaluation Metrics**: Support for F1 score, precision, and recall optimization
18+
- **Easy Integration**: Works seamlessly with existing RedisVL SemanticCache and SemanticRouter instances
19+
20+
**Example usage:**
21+
```python
22+
from redis_retrieval_optimizer.threshold_optimization import CacheThresholdOptimizer
23+
24+
# Optimize cache threshold
25+
optimizer = CacheThresholdOptimizer(cache, test_data)
26+
optimizer.optimize()
27+
28+
# Optimize router thresholds
29+
optimizer = RouterThresholdOptimizer(router, test_data)
30+
optimizer.optimize(max_iterations=20, search_step=0.1)
31+
```
32+
33+
### 🔄 Weighted Reciprocal Rank Fusion (Weighted RRF)
34+
**NEW**: Advanced search method that combines multiple retrieval strategies with configurable weighting.
35+
36+
Weighted RRF allows you to intelligently blend BM25 and vector search results with controlled weighting parameters. This method is particularly effective when different search strategies have complementary strengths.
37+
38+
**Features:**
39+
- Configurable weighting between BM25 and vector search
40+
- Parameter k controls how quickly rankings decay
41+
- Handles cases where methods have complementary strengths
42+
- Improved relevance through intelligent result fusion
43+
44+
### 🧠 Enhanced Vector Data Type Support
45+
**NEW**: Support for multiple vector data types including float16 and float32.
46+
47+
You can now test different vector data types to find the optimal balance between memory usage and precision. This is especially useful for production deployments where memory efficiency is crucial.
48+
49+
**Supported data types:**
50+
- `float16`: Reduced memory usage with acceptable precision
51+
- `float32`: Standard precision (default)
52+
53+
**Configuration:**
54+
```yaml
55+
vector_data_types: ["float16", "float32"]
56+
```
57+
58+
### 🤖 OpenAI Embedding Model Support
59+
**NEW**: Native support for OpenAI's text-embedding-3-small model.
60+
61+
The optimizer now supports OpenAI's latest embedding models, allowing you to compare their performance against HuggingFace models in your studies.
62+
63+
**Supported models:**
64+
- `text-embedding-3-small` (1536 dimensions)
65+
- All existing HuggingFace models
66+
67+
**Example configuration:**
68+
```yaml
69+
embedding_models:
70+
- type: "openai"
71+
model: "text-embedding-3-small"
72+
dim: 1536
73+
embedding_cache_name: "openai-small-vec-cache"
74+
```
75+
76+
## 🔧 Improvements & Enhancements
77+
78+
### 📊 Enhanced Search Methods
79+
- **Improved BM25**: Better handling of edge cases and error recovery
80+
- **Enhanced Hybrid Search**: More robust combination of lexical and semantic search
81+
- **Optimized Reranking**: Improved cross-encoder integration with better error handling
82+
- **Better Vector Search**: Enhanced distance metric support and query optimization
83+
84+
### 🛠️ Developer Experience
85+
- **Better Error Handling**: More graceful error recovery across all search methods
86+
- **Improved Logging**: Enhanced logging for debugging and monitoring
87+
- **Type Safety**: Better type hints and validation throughout the codebase
88+
- **Documentation**: Comprehensive examples and API documentation
89+
90+
### 🔌 Extensibility
91+
- **Custom Search Methods**: Easier creation of domain-specific search strategies
92+
- **Flexible Corpus Processors**: Support for custom data formats and processing
93+
- **Modular Architecture**: Better separation of concerns for easier extension
94+
95+
## 📚 New Documentation & Examples
96+
97+
### 📖 Comprehensive Examples
98+
- **Threshold Optimization**: Complete notebook showing cache and router optimization
99+
- **Model Comparison**: Side-by-side comparison of different embedding models
100+
- **Custom Grid Study**: Advanced example with domain-specific search methods
101+
- **Bayesian Optimization**: Detailed guide for fine-tuning index configurations
102+
103+
### 🔍 API Documentation
104+
- Complete API reference for all new features
105+
- Detailed configuration guides
106+
- Best practices and performance tips
107+
108+
## 🐛 Bug Fixes
109+
110+
- Fixed issue with embedding cache name collisions
111+
- Improved handling of empty search results
112+
- Better error messages for configuration issues
113+
- Fixed memory leaks in long-running studies
114+
- Resolved issues with Redis connection handling
115+
116+
## 🔄 Breaking Changes
117+
118+
**None**: This release maintains full backward compatibility with v0.2.x.
119+
120+
## 📦 Installation
121+
122+
```bash
123+
pip install redis-retrieval-optimizer==0.3.0
124+
```
125+
126+
## 🎯 Migration Guide
127+
128+
No migration required! All existing configurations and code will work without changes. New features are opt-in and can be added to your existing studies.
129+
130+
## 🚀 Quick Start with New Features
131+
132+
### Threshold Optimization
133+
```python
134+
from redis_retrieval_optimizer.threshold_optimization import CacheThresholdOptimizer
135+
136+
# Create test data
137+
test_data = [
138+
{"query": "What's the capital of France?", "query_match": "paris_key"},
139+
{"query": "What's the capital of Britain?", "query_match": ""}
140+
]
141+
142+
# Optimize cache threshold
143+
optimizer = CacheThresholdOptimizer(cache, test_data)
144+
optimizer.optimize()
145+
```
146+
147+
### Weighted RRF
148+
```yaml
149+
search_methods: ["bm25", "vector", "hybrid", "rerank", "weighted_rrf"]
150+
```
151+
152+
### Vector Data Types
153+
```yaml
154+
vector_data_types: ["float16", "float32"]
155+
```
156+
157+
### OpenAI Embeddings
158+
```yaml
159+
embedding_models:
160+
- type: "openai"
161+
model: "text-embedding-3-small"
162+
dim: 1536
163+
embedding_cache_name: "openai-cache"
164+
```
165+
166+
## 🙏 Acknowledgments
167+
168+
Thank you to all contributors who helped make this release possible! Special thanks to the Redis community for feedback and testing.
169+
170+
## 📞 Support
171+
172+
- **Documentation**: [GitHub Wiki](https://github.com/redis-applied-ai/redis-retrieval-optimizer)
173+
- **Issues**: [GitHub Issues](https://github.com/redis-applied-ai/redis-retrieval-optimizer/issues)
174+
- **Discussions**: [GitHub Discussions](https://github.com/redis-applied-ai/redis-retrieval-optimizer/discussions)
175+
176+
---
177+
178+
**Stop guessing. Start measuring.** 📊
179+
180+
Transform your retrieval system from *"looks good to me"* to *"proven to perform"* with Redis Retrieval Optimizer v0.3.0!

0 commit comments

Comments
 (0)