Back to Community & Earn Hub
Q&A Questiondatabases +150 pt Bounty

Qdrant vs pgvector 0.8 Binary Quantization: How to avoid >8% recall drop on 1M+ agent memory vectors with asymmetric rescoring?

@siddharth_rao5 hours ago 1460 views

To fit 1.2 million 1536-dimensional embeddings (text-embedding-3-small) inside a 4GB RAM budget, we enabled 1-bit Binary Quantization (BQ).

What Happened

Memory dropped beautifully (1.2M × 1536 bits ≈ 230 MB for the quantized vectors!). However, when querying directly against the Hamming distance of binary vectors:

sql
SELECT id, content
FROM agent_memories
ORDER BY binary_quantize(embedding)::bit(1536) <~> binary_quantize($1)::bit(1536)
LIMIT 10;

Our evaluation suite showed top-10 recall plunged from 97.4% down to 86.1%—missing critical memory chunks during multi-step agent runs.

  1. Why does OpenAI text-embedding-3-small lose ~11% recall under raw 1-bit sign quantization compared to text-embedding-3-large?
  2. What is the exact two-stage oversampling + asymmetric rescoring SQL pattern in pgvector 0.8 (and Qdrant QuantizationSearchParams) to recover 96%+ recall without loading all FP32 vectors into RAM?
1 Answers

Community Answers

@tanvi_kulkarni Accepted Answer5 hours ago

Raw 1-bit binary quantization maps every positive float to 1 and negative float to 0, discarding all magnitude information. For 1536-dimensional vectors (especially when not centered around zero mean), ranking strictly by Hamming distance loses fine-grained ordering among the top ~50 candidates.

The fix in both pgvector 0.8+ and Qdrant is Two-Stage Oversampling + Rescoring:

  1. Stage 1 (In-RAM HNSW on bit(1536)): Fetch 5x to 10x candidates (50–100 rows instead of 10) using fast Hamming distance (<~>).
  2. Stage 2 (On-Disk Rescore on halfvec(1536)): Compute exact cosine distance (<=>) only on those 80 candidate rows! Reading 80 rows from NVMe page cache takes <1.5ms while keeping 95% of your vectors out of hot RAM.

1. Exact SQL Pattern in pgvector 0.8+

Store an expression HNSW index over binary_quantize(embedding)::bit(1536) in RAM, and rescore against halfvec(1536) on disk:

sql
-- Build compact binary HNSW index (~230 MB for 1.2M vectors)
CREATE INDEX memories_bq_hnsw_idx ON agent_memories
USING hnsw ((binary_quantize(embedding)::bit(1536)) bit_hamming_ops)
WITH (m = 16, ef_construction = 64);

-- Query with 8x oversampling + exact halfvec rescoring
WITH candidates AS (
    SELECT id, content, embedding
    FROM agent_memories
    ORDER BY binary_quantize(embedding)::bit(1536) <~> binary_quantize($1::halfvec)::bit(1536)
    LIMIT 80
)
SELECT id, content, (embedding <=> $1::halfvec) AS exact_distance
FROM candidates
ORDER BY exact_distance ASC
LIMIT 10;

2. Equivalent Configuration in Qdrant

In Qdrant, enable always_ram=True for the quantized index and rescore=True with oversampling=4.0 at query time:

python
from qdrant_client.models import SearchParams, QuantizationSearchParams

hits = client.search(
    collection_name="agent_memories",
    query_vector=query_vec,
    limit=10,
    search_params=SearchParams(
        quantization=QuantizationSearchParams(
            rescore=True,
            oversampling=4.0,  # Fetches 40 binary candidates, rescores exact FP16 on disk
        )
    ),
)

Benchmark Results on 1.2M × 1536d Vectors:

  • BQ Only (No Rescore): 230 MB index RAM, 86.1% recall@10.
  • BQ + 8x Oversampling + halfvec Rescore: 230 MB index RAM, 97.1% recall@10, 8.4ms p95 latency.

Have a solution or working configuration?

Sign in or create a free account to answer this question (+10 pts, +25 pts if accepted) and tag helpful AIStoreHub repositories.