Bläddra i källkod

docs: the vector field gap bites manual debugging writes, not pipelines

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

+ 1 - 0
CLAUDE.md

@@ -157,6 +157,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **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.
 - **Database failures keep their classification** (`db_errors.hpp`, client 2.11.4). `Client::Error::code()` on the throwing calls and the `Failure&` overloads on `update`/`patch`/`remove` feed one `translate()`: AlreadyExists → 409 `duplicate_values`, or `duplicate_id` when `reason` says so (database 2.12.1: a taken document id and a taken unique field value are the same code but different remedies), FailedPrecondition → 422 `relation_violation`, NotFound → 404, Unavailable/DeadlineExceeded/Unknown → 503, everything else → 500. **`ErrorCode::Ok` on a call that returned false means "did not apply", not an error** - map it to 404, or a plain missing document becomes a 500 with an empty message.
 - **`nlohmann::json` STORES invalid UTF-8 and throws only when you serialise it.** A binary `/fn` request body therefore reached the run request intact and blew up at `dump()` with `type_error.316`, which surfaced as a **500 with nothing pointing at the body** while the function never ran. `triggerBodyFields()` (`functions/trigger_body.hpp`, pure) now offers unserialisable bytes as base64 under their OWN keys - `body` stays `null`, `bodyBase64` carries them, `bodyEncoding` is `"base64"` - because base64 placed in `body` would hand an unprepared function a plausible-looking string that is not what was sent, and silent corruption is worse than a visible `null`. `bodyEncoding` is absent for a text body, so an existing function's trigger shape is unchanged. **`isValidUtf8()` (`utf8_text.hpp`) must agree with nlohmann's own decoder, not with a reading of RFC 3629** - a sequence it accepted and nlohmann rejected would only move the 500 - so it refuses overlongs, the surrogate range and anything past U+10FFFF, and the tests cross-check it against a real `dump()` over every single byte and all 65536 two-byte sequences rather than trusting either side alone.
+- **"DOES YOUR CODE SEND THAT?" IS THE WRONG COMPATIBILITY QUESTION FOR A HAND-WRITTEN API.** Asked whether they were exposed to the `vector`/`_vector` hole, a consumer verified their pipeline could not hit it - one definition, one call site, the embedding route, no vector field - and then corrected my reassurance: **their original junk row came from a MANUAL PROBE**, a query body posted to the documents route by hand during an investigation. So the gap sits on debugging activity, not on deployed code, and it is WORSE there: a hand-written write is read back by id, the row is present, and the operator concludes success. One character between `vector` and `_vector`, a 201, and a row findable by nothing, forever. The question to ask a consumer about this class of defect is not what their code sends but **what their operators type while debugging** - and hand-writing a document into a vector collection is something people do precisely when something is already wrong. Their mitigation until the guard reaches prod is the right one and applies to us: **read back a manual vector write BY SEARCH, never by id.**
 - **A VECTOR COLLECTION'S INSERT GUARD USED TO COMMIT THE EXACT BUG IT EXISTS TO PREVENT.** `vector_missing` accepted a body carrying either `_vector` OR `vector`, while the documents route stores the body verbatim and a search reads `_vector`. So a row written with `vector` got a 201 and was then findable by NO search - the unsearchable junk row the guard was written for, admitted by the guard. Measured with two rows inserted under the two spellings from the same vector: only the underscored one came back. Now refused, with a message that also says to REWRITE any row already stored that way, because a caller who hit this has unfindable rows behind them and silently fixing only their next write would leave those while looking solved. Found by a consumer asking which field a RESTORE should write - the question exposed it, not a test.
 - **AN ERROR'S WORST READING IS THE ONE IT WILL GET UNDER PRESSURE.** Feeding an export's `vector_b64` back into the documents route used to answer "a document must carry `_vector`" - accurate, and read by someone restoring a 294 MB file at 3am as **"my backup has no vectors"**, which is indistinguishable from real data loss and will be believed. A consumer named that misreading after doing the restore. The message now names the export's own field, states that the backup is FINE, and says to expand the base64 - and a test asserts the ORDINARY missing-vector case does NOT mention a backup, so the reassurance cannot be given where it would be a lie. The general rule: when an error can be read as "your data is gone", say explicitly that it is not.
 - **The export writes base64 and no insert route reads it.** `vector_format=base64` emits `vector_b64`; `POST .../documents` wants `_vector` as a number array and `POST .../vectors` wants `vector` as a number array. So the one path a backup exists for does not round-trip without expanding the base64 first, and the 422 a caller gets names what is MISSING rather than the good vector sitting in the field the exporter wrote. Documented in `api/llms.txt`; whether to accept a base64 write form is open.