Habib Ali Machpud
← Architecture decisions

Architecture decision

ADR-019: Start with exact vector search

Measure retrieval correctness on the small corpus before introducing approximate vector indexes.

Context

Ask Habib’s lexical index is small. Semantic retrieval needs a trustworthy baseline for comparing vectors, filtering the active model, and rejecting weak evidence. Approximate nearest-neighbour indexes would add tuning choices before those correctness questions have been evaluated.

Decision

Use pgvector’s exact cosine-distance ordering for the first semantic path. Filter by embedding-space identity and the published document fingerprints. Read index state and both retrieval branches in one repeatable-read snapshot so a concurrent backfill cannot mix spaces within a result.

Introduce nullable 384-dimensional vectors through an additive migration. A pinned local CPU model prepares vectors on the owner’s Mac. An explicit operator backfill validates cached results outside the write transaction, then commits the complete vector space and its corpus marker together. Keep public site search lexical; the first semantic consumer is a private operator command.

Alternatives and consequences

HNSW and IVFFlat can improve large-corpus query latency, but introduce recall, memory, build-time and maintenance trade-offs. Exact search provides a comparison baseline without choosing those parameters now. It scans and sorts matching vectors, which becomes more expensive as the corpus grows.

Measure the actual filtered query with EXPLAIN ANALYZE and evaluate expected-source and no-evidence questions before revisiting an approximate index. Offline contract tests use explicitly synthetic vectors; separate cached real-model fixtures measure retrieval quality without paid API calls. Production semantic activation requires its own approval. Topical similarity does not establish factual support for a generated answer.