Jelajahi Sumber

docs: measured search and embedding timings on small collections

fszontagh 1 bulan lalu
induk
melakukan
a86bad98ab
1 mengubah file dengan 1 tambahan dan 0 penghapusan
  1. 1 0
      CLAUDE.md

+ 1 - 0
CLAUDE.md

@@ -156,6 +156,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **`Client::get` returns nullopt for BOTH "absent" and "transport failed"** - it throws only for PERMISSION_DENIED - so a registry lookup cannot tell them apart from the return value. Unhandled, that reaches a caller as 404 "no such collection" for a collection that exists, and a 404 is unretryable BY DESIGN for a careful client, because adding it to a retry set would retry every genuine absence. A consumer lost a 6-minute ingest of an 8 GB mailbox to exactly this. `CollectionRegistry::get` therefore **retries once** (a transient failure usually succeeds, and logs a warning saying so) and then asks `healthCheck()` before reporting absence, throwing **503** when the database is unreachable. Reported upstream too: the client should distinguish, the way it already does for a permission denial.
 - **A REPRODUCIBLE vector-search baseline needs an explicit `query_vector`. Pinning `query_text` is NOT enough.** `query_text` is embedded server-side through the external provider on *every* call - there is no query-embedding cache (`emb.embed(cfg.model, text)` in `handlers/vectors.cpp`), so the same text can yield a different vector on a different day and every score and row count moves with it. Measured by a consumer across one deploy over a byte-identical collection (12447 rows unchanged): an unfiltered top score went 0.7221 to 0.7175 and a filtered count 424 to 426, while five consecutive calls agreed to six decimals - so it is drift in text→vector, not per-call noise. The isolating test: a fixed explicit `query_vector` returned bit-identical results three times, which proves the RANKING is deterministic given a vector. **So nothing in a release has to change for such a baseline to move, and it is therefore not evidence about the release either way.** Corollary worth stating because it bit us: `scan_capped` is query-dependent too and so is also a measurement, not a property of the collection - it is set only when the walk hit the cap *while still short of `top_k`*, so a query that fills `top_k` reports false where a query that falls short reports true. Read all three of the useful assertions (`scan_capped`/`scanned`/the nested error envelope) as "this query, this filter", never as facts about the data.
 - **A CACHE WOULD MAKE SEARCH LATENCY BIMODAL, so do not derive a timeout from a post-cache p50.** If query embeddings are ever cached, the same endpoint answers in ~3 s or ~12-15 s depending on state nothing outside can see, and a timeout or retry budget tuned against the hit path will fire on every miss. Same family as the startup loop that was bounded by an attempt COUNT: a budget encoding a duration as a count carries a hidden assumption about per-item cost. Note also that **caching would NOT make a search reproducible** - per-process plus a TTL means a restart or the TTL boundary clears it, so results would be stable across an afternoon and silently not across a deploy, which is stable long enough to be trusted and not long enough to be true. An explicit `query_vector` stays the only reproducible baseline.
+- **MEASURED ON PROD, 2026-10-09, small collections (126 and 49 rows, dim 4096), server-side end to end.** The filtered similarity search costs **~25 ms** and the filter costs nothing measurable at that size - filtered and unfiltered are identical within noise. A cold `query_text` is **0.49-0.95 s**, essentially all of it the provider round trip; the SAME text repeated is 0.022 s, because the provider caches it. **That cache is useless to a workload of unique queries** such as a voice assistant, which is therefore permanently on the 0.5-1.0 s path. Eight samples in one window is a MEDIAN, not a tail: a 12-15 s text search was observed earlier the same day and did not reproduce, so the bad tail is real and unexplained rather than bounded at 0.95 s. Quote these as medians and say so.
 - **The embedding call IS essentially the whole vector-search latency.** Measured on prod with the ranking doing identical work both ways: a fixed `query_vector` search returned in 3.4 s against 12-15 s for the same filter and `top_k` via `query_text`. There is no query-embedding cache, so every repeated search pays the provider again.
 - **A FILTERED VECTOR SEARCH IS NOW ONE SERVER-SIDE CALL (database 2.14.0+), exact and UNCAPPED.** The filters select candidates BEFORE ranking, so the answer is the true top-K among matching rows rather than a filtered slice of the unfiltered top-K, and there is no walk, no 10000 cap and nothing to truncate. Measured by the database team on 12447 rows at dim 4096: a filter matching ~430 rows at `topK` 500 took **51 ms indexed** against **187 ms for the same search unfiltered** - the filter makes it CHEAPER, because only matching rows are scored. Our emulation took **3.21 s** for that shape on prod.
   - **`scan_capped` is emitted EXPLICITLY as `false` on this path, never omitted**, and `scanned` is 0 because no walk happened - which here is literally true rather than a sentinel. A consumer maps an absent `scan_capped` to "this server cannot report truncation, so completeness is unknown" and shows that to an operator; on this path that is both false and PERMANENT, and a warning that always fires is one people learn to skip. Absence is also already spoken for by the 0.8.3 agreement, where a missing field means "old server" and nothing else.