Эх сурвалжийг харах

docs: the embedding latency median improved 10x and the tail did not go away

Twelve fresh strings: min 0.48s, median 0.75s, max 4.46s; our own cold
call in the same hour took 8.17s. A four-sample run had been read as
retiring the 12-15s figure, and the same consumer's re-measurement
overturned it - four samples describe a median and say nothing about a
tail.

Design consequence: two sequential query_text searches are two
independent draws from that tail, so embed once and pass one explicit
query_vector to both. Also records that a fast repeat cannot attribute a
slow call across the provider boundary - only a pure DB read with no
embedding in the path can, which is 3-10 ms.
fszontagh 1 сар өмнө
parent
commit
dfac3c11fe
1 өөрчлөгдсөн 4 нэмэгдсэн , 0 устгасан
  1. 4 0
      CLAUDE.md

+ 4 - 0
CLAUDE.md

@@ -343,6 +343,10 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **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 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.
 - **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.
 - **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.
+  **RE-MEASURED 2026-10-19 BY A CONSUMER AND BY US, AND THE DISTRIBUTION IS WHAT MATTERS RATHER THAN EITHER FIGURE: THE MEDIAN IMPROVED BY AN ORDER OF MAGNITUDE AND THE TAIL DID NOT GO AWAY.** Twelve never-before-seen strings against `novitax:kb_facts`: **min 0.48 s, median 0.75 s, max 4.46 s, with 1 of 12 over 2 s**. In the same hour a cold `query_text` of ours took **8.17 s**, so the tail reaches at least that. Both observations are correct and neither alone describes the endpoint.
+  **The consumer had first measured FOUR fresh strings, got 0.57-1.33 s, and written that the 12-15 s figure was retired and two searches now fit inside a phone call's budget.** Their own re-measurement overturned it. **Four samples describe a median and say nothing about a tail, and a caller does not experience the median - they experience the call they are on.** That is the same shape as reading a server version off `db_client`: a true observation supporting a claim strictly wider than it can discriminate.
+  **The design consequence, which is the useful part: TWO SEQUENTIAL `query_text` SEARCHES ARE TWO INDEPENDENT DRAWS FROM THAT TAIL.** Reading two collections that way doubles the chance of meeting it, so the right shape is to embed ONCE and pass the same explicit `query_vector` to both - not because a single search is slow, since usually it is not, but because it halves the draws and lets one `embedTimeoutMs` bound one call instead of two. That also restores the explicit-`query_vector` recommendation on the independent ground already recorded here, that it is the only reproducible baseline.
+  **AND A FAST REPEAT CANNOT ATTRIBUTE A SLOW CALL - ONLY REMOVING THE PROVIDER FROM THE PATH CAN.** When the 8.17 s search was followed by the same text answering in 0.267 s and 0.242 s, that was equally consistent with "the provider cached it and we are fine" and with "the provider cached it while our store is slow under swap". The measurement that decides it is a **pure DB read with no embedding in the path, which answered in 3-10 ms**. Keep that control to hand whenever attributing latency across the provider boundary; without it the reassuring reading and the alarming one produce identical numbers.
 - **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.
 - **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.
 - **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.
   - **`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.