Skip to content

Commit 012fd8b

Browse files
authored
updates for first package release (#15)
1 parent dfc3638 commit 012fd8b

File tree

4 files changed

+1252
-151
lines changed

4 files changed

+1252
-151
lines changed

README.md

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ The **Retrieval Optimizer** from Redis is designed to bring focus back to what m
1515

1616
Beyond accuracy alone, it also supports evaluating critical tradeoffs between **cost, speed, and latency**, helping you understand how different embedding models, retrieval strategies, and index configurations impact overall system performance. The ultimate goal is to enable **metrics-driven development** for your search application—ensuring that decisions are grounded in data, not assumptions.
1717

18+
# Example notebooks
19+
20+
For complete code examples see the following notebooks:
21+
22+
| Topic | Notebook |
23+
| ------ | ------- |
24+
| Basic grid study | [00_grid_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/dfc36382efd7e5e06903482a8a23a32bc047f1e9/docs/examples/grid_study/00_grid_study.ipynb) |
25+
| Custom grid study | [01_custom_grid_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/dfc36382efd7e5e06903482a8a23a32bc047f1e9/docs/examples/grid_study/01_custom_grid_study.ipynb) |
26+
| Bayesian Optimization | [00_bayes_study.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/dfc36382efd7e5e06903482a8a23a32bc047f1e9/docs/examples/bayesian_optimization/00_bayes_study.ipynb) |
27+
| Embedding model comparison | [00_comparison.ipynb](https://github.com/redis-applied-ai/redis-retrieval-optimizer/blob/main/docs/examples/comparison/00_comparison.ipynb) |
28+
1829
# Quick Start
1930

2031
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.
@@ -33,13 +44,15 @@ Once you've identified a solid starting point, use Bayesian optimization to **fi
3344
#### Define study config
3445
```yaml
3546
# paths to necessary data files
36-
corpus: "data/nfcorpus_corpus.json" # optional if from_existing
47+
corpus: "data/nfcorpus_corpus.json"
3748
queries: "data/nfcorpus_queries.json"
3849
qrels: "data/nfcorpus_qrels.json"
3950

4051
# vector field names
4152
index_settings:
4253
name: "optimize"
54+
vector_field_name: "vector" # name of the vector field to search on
55+
text_field_name: "text" # name of the text field for lexical search
4356
from_existing: false
4457
additional_fields:
4558
- name: "title"
@@ -77,7 +90,14 @@ metrics = run_grid_study(
7790
```
7891

7992
#### Example output
80-
![grid study output](/reference/grid_output.png)
93+
| search_method | model | avg_query_time | recall@k | precision | ndcg@k |
94+
|----------------|---------------------------------------------|----------------|-----------|-----------|----------|
95+
| weighted_rrf | sentence-transformers/all-MiniLM-L6-v2 | 0.006608 | 0.156129 | 0.261056 | 0.204241 |
96+
| rerank | sentence-transformers/all-MiniLM-L6-v2 | 0.127574 | 0.156039 | 0.260437 | 0.190298 |
97+
| lin_combo | sentence-transformers/all-MiniLM-L6-v2 | 0.003678 | 0.119653 | 0.302993 | 0.173768 |
98+
| bm25 | sentence-transformers/all-MiniLM-L6-v2 | 0.000922 | 0.115798 | 0.323891 | 0.168909 |
99+
| vector | sentence-transformers/all-MiniLM-L6-v2 | 0.003378 | 0.119653 | 0.302993 | 0.165573 |
100+
81101

82102
## Running a bayesian optimization
83103
Selects the next best configuration to try based on a heuristic. This is good when it would take a very long time to test all possible configurations.
@@ -91,36 +111,41 @@ qrels: "data/nfcorpus_qrels.json"
91111

92112
index_settings:
93113
name: "optimize"
114+
vector_field_name: "vector" # name of the vector field to search on
115+
text_field_name: "text" # name of the text field for lexical search
94116
from_existing: false
95117
vector_dim: 384 # should match first embedding model or from_existing
96118
additional_fields:
97119
- name: "title"
98120
type: "text"
99121

122+
# section for bayesian optimization
100123
optimization_settings:
101-
# defines the options optimization can take
124+
# defines weight of each metric in optimization function
102125
metric_weights:
103126
f1_at_k: 1
104-
embedding_latency: 1
105127
total_indexing_time: 1
106-
algorithms: ["hnsw"]
107-
vector_data_types: ["float16", "float32"]
108-
distance_metrics: ["cosine"]
109-
n_trials: 10
128+
algorithms: ["hnsw"] # indexing algorithm to be included in the study
129+
vector_data_types: ["float16", "float32"] # data types to be included in the study
130+
distance_metrics: ["cosine"] # distance metrics to be included in the study
131+
n_trials: 10 # total number of trials to run
110132
n_jobs: 1
111133
ret_k: [1, 10] # potential range of value to be sampled during study
112-
ef_runtime: [10, 20, 30, 50]
113-
ef_construction: [100, 150, 200, 250, 300]
114-
m: [8, 16, 64]
115-
134+
ef_runtime: [10, 20, 30, 50] # potential values for ef_runtime to take
135+
ef_construction: [100, 150, 200, 250, 300] # potential values for ef_construction to take
136+
m: [8, 16, 64] # potential values for m to take
116137

138+
# potential values for search method
117139
search_methods: ["vector", "hybrid"]
140+
141+
# potential values for embedding models
118142
embedding_models:
119143
- type: "hf"
120144
model: "sentence-transformers/all-MiniLM-L6-v2"
121145
dim: 384
122146
embedding_cache_name: "vec-cache" # avoid names with including 'ret-opt' as this can cause collisions
123147
dtype: "float32"
148+
124149
```
125150

126151
#### Code
@@ -143,7 +168,29 @@ metrics = run_bayes_study(
143168
```
144169

145170
#### Example output
146-
![bayes study output](/reference/bayes_output.png)
171+
| search_method | algorithm | vector_data_type | ef_construction | ef_runtime | m | avg_query_time | total_indexing_time | f1@k |
172+
|---------------|-----------|------------------|------------------|------------|----|----------------|----------------------|---------|
173+
| hybrid | hnsw | float16 | 200 | 50 | 8 | 0.004628 | 3.559 | 0.130712|
174+
| hybrid | hnsw | float16 | 200 | 50 | 64 | 0.004498 | 4.804 | 0.130712|
175+
| hybrid | hnsw | float16 | 150 | 50 | 64 | 0.004520 | 3.870 | 0.130712|
176+
| hybrid | hnsw | float32 | 100 | 50 | 64 | 0.003387 | 1.929 | 0.130712|
177+
| hybrid | hnsw | float16 | 150 | 50 | 8 | 0.004771 | 2.496 | 0.130712|
178+
| hybrid | hnsw | float32 | 300 | 50 | 16 | 0.003461 | 3.622 | 0.130712|
179+
| hybrid | hnsw | float16 | 100 | 50 | 16 | 0.004402 | 3.120 | 0.130712|
180+
| hybrid | hnsw | float16 | 100 | 50 | 64 | 0.004615 | 3.361 | 0.130712|
181+
| hybrid | hnsw | float16 | 250 | 50 | 16 | 0.005002 | 3.627 | 0.130712|
182+
| hybrid | hnsw | float32 | 150 | 50 | 8 | 0.003246 | 2.471 | 0.130712|
183+
| hybrid | hnsw | float32 | 300 | 50 | 8 | 0.002921 | 3.443 | 0.130712|
184+
| hybrid | hnsw | float16 | 250 | 50 | 8 | 0.004366 | 3.094 | 0.130712|
185+
| hybrid | hnsw | float32 | 250 | 50 | 8 | 0.003318 | 3.126 | 0.130712|
186+
| vector | hnsw | float32 | 200 | 50 | 64 | 0.001116 | 2.790 | 0.130712|
187+
| vector | hnsw | float16 | 200 | 50 | 64 | 0.001965 | 4.808 | 0.129692|
188+
| vector | hnsw | float32 | 200 | 50 | 16 | 0.001359 | 2.773 | 0.129692|
189+
| vector | hnsw | float16 | 150 | 50 | 8 | 0.001405 | 3.907 | 0.128089|
190+
| vector | hnsw | float32 | 300 | 50 | 8 | 0.003236 | 2.742 | 0.127207|
191+
| vector | hnsw | float32 | 100 | 50 | 8 | 0.002346 | 3.088 | 0.126233|
192+
| vector | hnsw | float32 | 100 | 50 | 16 | 0.001478 | 1.896 | 0.116203|
193+
147194

148195

149196
# Search Methods
@@ -198,39 +245,43 @@ This example defines a study where we compare two vector-based methods—one usi
198245

199246
#### Study config
200247
```yaml
248+
# paths to necessary data files
201249
corpus: "data/car_corpus.json"
202250
queries: "data/car_queries.json"
203251
qrels: "data/car_qrels.json"
204252

253+
# vector field names
205254
index_settings:
206255
name: "car"
207-
prefix: "car"
208-
vector_field_name: "vector"
209-
text_field_name: "text"
256+
prefix: "car" # prefix for index name
257+
vector_field_name: "vector" # name of the vector field to search on
258+
text_field_name: "text" # name of the text field for lexical search
210259
from_existing: false
211260
additional_fields:
212261
- name: "make"
213262
type: "tag"
214263
- name: "model"
215264
type: "tag"
216-
vector_dim: 384
265+
vector_dim: 384 # should match first embedding model or from_existing
217266

218-
embedding_models:
267+
# will run all search methods for each embedding model and then iterate
268+
embedding_models: # embedding cache would be awesome here.
269+
# if from_existing is true, first record is assumed to be the one used to create the index
219270
- type: "hf"
220271
model: "sentence-transformers/all-MiniLM-L6-v2"
221272
dim: 384
222-
embedding_cache_name: "vec-cache"
273+
embedding_cache_name: "vec-cache" # avoid names with including 'ret-opt' as this can cause collisions
223274

224-
search_methods: ["basic_vector", "pre_filter_vector"]
275+
search_methods: ["basic_vector", "pre_filter_vector"] # must match what is passed in search_method_map
225276
```
226277
227278
---
228279
229280
### Writing Custom Search Methods
230281
231-
Search methods can be anything you wantas long as they accept a `SearchMethodInput` and return a `SearchMethodOutput`. This allows you to test new retrieval strategies, add filters, or layer on post-processing logic.
282+
Search methods can be anything you want as long as the function accepts a `SearchMethodInput` and returns a `SearchMethodOutput`. This allows you to test new retrieval strategies, add filters, or layer on post-processing logic.
232283

233-
#### code
284+
#### Code
234285
```python
235286
def gather_vector_results(search_method_input: SearchMethodInput) -> SearchMethodOutput:
236287
redis_res_vector = {}
@@ -304,10 +355,13 @@ metrics = run_grid_study(
304355
)
305356
```
306357

358+
### Example output
307359

308-
Here's a polished and clearer version of your **Data Requirements** section, matching the tone and structure of the rest of the content. It emphasizes flexibility while giving users a concrete foundation to build from:
360+
| search_method | model | avg_query_time | recall@k | precision | ndcg@k |
361+
|-------------------|---------------------------------------------|----------------|-----------|-----------|----------|
362+
| pre_filter_vector | sentence-transformers/all-MiniLM-L6-v2 | 0.001177 | 1.0 | 0.25 | 0.914903 |
363+
| basic_vector | sentence-transformers/all-MiniLM-L6-v2 | 0.002605 | 0.9 | 0.23 | 0.717676 |
309364

310-
---
311365

312366
## Data Requirements
313367

@@ -404,11 +458,6 @@ Qrels define the relevance of documents to each query. They are required for eva
404458

405459
> 🔍 Note: Relevance scores can be binary (`1` or `0`) for classification metrics or ranked (`2`, `1`, etc.) for ranking metrics like NDCG.
406460

407-
---
408-
409-
Let me know if you'd like to include downloadable examples or a link to a starter dataset like BEIR for people to clone and try out.
410-
411-
412461
# Contributing
413462
We love contributors if you have an addition follow this process:
414463
- Fork the repo
File renamed without changes.

0 commit comments

Comments
 (0)