Skip to content

Commit 43982c1

Browse files
authored
Merge pull request #276 from asg017/pr/rescore
Add a new `rescore` ANN index for `vec0` tables
2 parents 69ccb24 + 45d1375 commit 43982c1

19 files changed

+3381
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ test-loadable-watch:
204204
watchexec --exts c,py,Makefile --clear -- make test-loadable
205205

206206
test-unit:
207-
$(CC) -DSQLITE_CORE -DSQLITE_VEC_TEST tests/test-unit.c sqlite-vec.c vendor/sqlite3.c -I./ -Ivendor -o $(prefix)/test-unit && $(prefix)/test-unit
207+
$(CC) -DSQLITE_CORE -DSQLITE_VEC_TEST -DSQLITE_VEC_ENABLE_RESCORE tests/test-unit.c sqlite-vec.c vendor/sqlite3.c -I./ -Ivendor -o $(prefix)/test-unit && $(prefix)/test-unit
208208

209209
fuzz-build:
210210
$(MAKE) -C tests/fuzz all

benchmarks-ann/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ BASELINES = \
2121
# ANNOY_CONFIGS = \
2222
# "annoy-t50:type=annoy,n_trees=50"
2323

24-
ALL_CONFIGS = $(BASELINES)
24+
RESCORE_CONFIGS = \
25+
"rescore-bit-os8:type=rescore,quantizer=bit,oversample=8" \
26+
"rescore-bit-os16:type=rescore,quantizer=bit,oversample=16" \
27+
"rescore-int8-os8:type=rescore,quantizer=int8,oversample=8"
2528

26-
.PHONY: seed ground-truth bench-smoke bench-10k bench-50k bench-100k bench-all \
29+
ALL_CONFIGS = $(BASELINES) $(RESCORE_CONFIGS)
30+
31+
.PHONY: seed ground-truth bench-smoke bench-rescore bench-10k bench-50k bench-100k bench-all \
2732
report clean
2833

2934
# --- Data preparation ---
@@ -40,6 +45,11 @@ bench-smoke: seed
4045
$(BENCH) --subset-size 5000 -k 10 -n 20 -o runs/smoke \
4146
$(BASELINES)
4247

48+
bench-rescore: seed
49+
$(BENCH) --subset-size 10000 -k 10 -o runs/rescore \
50+
$(RESCORE_CONFIGS)
51+
52+
4353
# --- Standard sizes ---
4454
bench-10k: seed
4555
$(BENCH) --subset-size 10000 -k 10 -o runs/10k $(ALL_CONFIGS)

benchmarks-ann/bench.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,39 @@ def _baseline_describe(params):
140140
}
141141

142142

143+
# ============================================================================
144+
# Rescore implementation
145+
# ============================================================================
146+
147+
148+
def _rescore_create_table_sql(params):
149+
quantizer = params.get("quantizer", "bit")
150+
oversample = params.get("oversample", 8)
151+
return (
152+
f"CREATE VIRTUAL TABLE vec_items USING vec0("
153+
f" chunk_size=256,"
154+
f" id integer primary key,"
155+
f" embedding float[768] distance_metric=cosine"
156+
f" indexed by rescore(quantizer={quantizer}, oversample={oversample}))"
157+
)
158+
159+
160+
def _rescore_describe(params):
161+
q = params.get("quantizer", "bit")
162+
os = params.get("oversample", 8)
163+
return f"rescore {q} (os={os})"
164+
165+
166+
INDEX_REGISTRY["rescore"] = {
167+
"defaults": {"quantizer": "bit", "oversample": 8},
168+
"create_table_sql": _rescore_create_table_sql,
169+
"insert_sql": None,
170+
"post_insert_hook": None,
171+
"run_query": None, # default MATCH query works — rescore is automatic
172+
"describe": _rescore_describe,
173+
}
174+
175+
143176
# ============================================================================
144177
# Config parsing
145178
# ============================================================================

0 commit comments

Comments
 (0)