Bläddra i källkod

docs: record database 2.15.0 and why a capability check must not gate filtered search

fszontagh 1 månad sedan
förälder
incheckning
dba96b0c12
1 ändrade filer med 1 tillägg och 0 borttagningar
  1. 1 0
      CLAUDE.md

+ 1 - 0
CLAUDE.md

@@ -151,6 +151,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   - **Detection is the server's own `filters_applied` response field, not a version check we have to get right.** A pre-2.14.0 server would silently answer UNFILTERED, so the client throws `FailedPrecondition` / `filters_unsupported` instead - which is the only reason the new path can be tried optimistically. The refusal is LATCHED per process, so a deployment on an older database pays one refused round trip rather than one per search; one-way on purpose, since the emulation is correct and merely capped, and it clears on the restart a database upgrade involves anyway.
   - **`VectorSearchResult::serverFiltered` records which path answered**, because `scanCapped == false` means two different things: false BY CONSTRUCTION here (a sweep of a filtered set is sound) versus "complete this time" on the walk (it is not). A caller cannot infer it from `/api/v1/version`, which reports the CLIENT library version while the path depends on the SERVER - a 2.14 client against a 2.13 server reads as the new path while running the old capped one. Whether to expose it to callers is still open.
   - **The `Depends` floor had to move to `>= 2.14.0`, and that is load-bearing.** Verified rather than assumed, with `nm` on both shipped `.so` files: the 5-argument symbol exists only in 2.14.0, while 2.13.1 carries just the 4-argument form. Since every 2.x client shares one SONAME, leaving the old `>= 2.12.0` floor would have let apt install this binary against a client that cannot resolve the call - the failure that "installs fine and only breaks on the next restart".
+- **DATABASE 2.15.0 EXISTS AND IS NOT ADOPTED. Do not gate filtered search on a capability name.** 2.15.0 adds `GetServerInfo`, `serverInfo()`, `serverSupports(name)` and `Client::Capability` constants, and from it the client and server release independently (2.15.0 is the last lockstep release; the server no longer pins `libsmartbotic-db-client (= VERSION)`). Nothing in it changes our 2.14.0 alignment. **The trap, flagged by the database team: `serverSupports(Capability::kFilteredSimilarity)` is FALSE against a 2.14.0 server, which has no `GetServerInfo` but fully supports filters.** Capability names gate only features introduced in 2.15.0 or later, so a capability check there would silently drop us onto the emulation against the very server we just deployed. Keep what is built: call the filtered overload, and fall back only on `FailedPrecondition` with reason `filters_unsupported`. Adopting 2.15.0 would also make `serverInfo()` a cheaper answer than a `filter_mode` response field, because it finally exposes the SERVER version - which is the thing that decides support, and the gap that made version inference unsound. Note it costs one cached `GetServerInfo` per client per 60 s.
 - **Two database semantics worth knowing, unchanged by 2.14.0 but easy to misread.** `minScore 0.0` DROPS rows whose cosine is negative, so "fewer matches than topK returns all of them" means all that score at or above `minScore` - pass a negative `minScore` to see genuinely every match. And from 2.14.0 rows with EQUAL scores are ordered by id, lower first, including when a tie straddles the cut; that applies to the unfiltered search too and was previously unspecified, so it is observable only on duplicate vectors.
 - **The filtered walk's EMULATION remains, for any server older than 2.14.0, and its cost is ROUND TRIPS.** The client has no filtered `similaritySearch`, so a filtered search fetches the filter's ids with `find()` and then re-runs the WHOLE similarity search with a growing limit, intersecting in our process. Measured on prod with an explicit `query_vector` (no embedding in the path), on 12447 rows at dim 4096: unfiltered `top_k` 500 is **0.26 s**, filtered `top_k` 500 is **3.21 s** having issued three searches (2000, 8000, 10000), and a filter matching nothing is 0.05 s. Time tracks rows fetched almost linearly, ~0.3 ms per candidate - neither the vector arithmetic nor the 1 MB response is the cost. `firstScanDepth()`/`nextScanDepth()` (`vector_search.hpp`, pure, 8 tests) therefore go straight to the cap when the filter matches fewer rows than `topK` (the early exit can never fire, so every step before the cap is certain waste) and otherwise widen by the hit rate the previous pass actually measured. **`scan * 4` stays the FLOOR**, so a mis-estimate can only skip steps and never shrink one - progress stays guaranteed and nothing can get slower. The RESULT is unchanged in every case: each pass is a prefix of the same ranking, so the first `topK` matches within it are the same rows whatever depth the walk stopped at. The real fix is a server-side filtered similarity search, requested and designed for database 2.14.0; this emulation must keep working regardless, as the path for any older server.
 - **A filtered vector search can return FEWER hits than match, and the response now says so.** The walk goes only `kVectorFilterScanCap` (10000) deep into the ranking, so on a larger collection a filter whose matches lie deeper is silently short - measured at 455 returned of 553 true matches on 12448 rows. `VectorSearchResult::scanCapped` is set ONLY when the walk hit the cap while still short of `topK` and the ranking was not exhausted, so a filter that merely matches fewer rows than `top_k` is correctly reported as complete rather than crying wolf. The HTTP route adds `scan_capped`/`scanned`; `ctx...search()` keeps its ARRAY return and warns in the run console instead.