瀏覽代碼

docs: a filtered search may now return MORE rows, and that is the fix

An upgrade note I had not thought to write, raised by a consumer as the
mirror image of their own warning.

They warned me that 426 becoming 500 would look like a filter that
stopped filtering when it is a filter that stopped truncating. The
inverse risk is a caller who built against the capped behaviour: `top_k`
now bounds a COMPLETE set rather than a truncated one, so a page size, a
display limit, a loop termination or a count treated as a ceiling that
was tuned around the smaller number will see the larger one. Neither
current consumer is exposed - one asks for 10, one uses no vector search
- but it belongs in the documentation rather than in a message.

Also records that this file's own wrong sentence about the `search`
operator PROPAGATED. One consumer had copied "use `search` for
substrings" from our docs into their own CLAUDE.md and had not called it
yet; another followed it and shipped a live bug where a keyword fallback
matched a chat id and a category instead of the field it named. A wrong
sentence in a doc is a defect with a blast radius, and it reaches people
who never read the code.

And keeps the better control. Mine was `nosuchfield:search:X`, which
only proves the operator tolerates an unknown field name. Theirs is
`status:search:webber` where `status` only ever holds draft or approved,
which proves it read a value out of a DIFFERENT field. They re-verified
our correction instead of accepting it, on the principle that if the
upstream source of an error is also the source of its correction, the
correction needs its own evidence - which is right, and is the reason
their control is in here rather than mine alone.
fszontagh 1 月之前
父節點
當前提交
e24a273eb2
共有 2 個文件被更改,包括 3 次插入 和 2 次删除
  1. 0 1
      CLAUDE.md
  2. 3 1
      api/llms.txt

文件差異過大導致無法顯示
+ 0 - 1
CLAUDE.md


+ 3 - 1
api/llms.txt

@@ -137,7 +137,9 @@ Relation names are per-project and **unqualified**: requests and responses alway
 Requires a `kind=vector` collection. Vectors are stored with cosine-similarity indexing.
 
 - `POST /api/v1/projects/{project}/collections/{name}/vectors` `{id?, text?, vector?, metadata?}` - Store a vector. Supply either `text` (the server embeds it, resolving the model as: the collection's `embedding_model` pin, else the project's embedding override, else the global default) or a pre-computed `vector` array. `vector` dimension must match the collection's `vector_dimension`. `metadata` is an arbitrary JSON object stored alongside the vector.
-- `POST /api/v1/projects/{project}/collections/{name}/search` `{query_text?, query_vector?, top_k?, min_score?, filters?}` - Cosine-similarity search. Supply either `query_text` or `query_vector`; neither is **422**. `top_k` caps the results, **default 5**. `min_score` (0-1) drops low-confidence matches, default 0. `filters` is an array of `field:op:value` strings applied to the vector's metadata, using the grammar and operators above - metadata is stored at the top level of the document, so a vector written with `metadata:{"colour":"red"}` is filtered as `colour:eq:red`. The response also carries **`scan_capped`** and `scanned` (plus `scan_cap` when capped). **Against database 2.14.0 or newer a filtered search is a single server-side call: the filter selects candidates BEFORE ranking, so the answer is the exact top-K among matching rows, there is no scan cap, `scan_capped` is always `false` and `scanned` is `0`** - and it is FASTER than the same search unfiltered, because only matching rows are scored. Against an older server the service falls back to walking the ranking `scan_cap` deep, and there a filter whose matches lie deeper than the walk returns FEWER hits than match, which is what `scan_capped: true` reports. `scan_capped: false` always means the answer is complete; on 2.14.0+ it is complete by construction, on the fallback it means complete this time. **On the fallback, check it before treating a filtered result set as exhaustive.** Note `min_score` defaults to 0, which drops rows whose cosine is NEGATIVE - pass a negative `min_score` to see every match. Rows with equal scores are ordered by id, lowest first. Inside a function the return stays an array and a truncation warning goes to the run's console instead.
+- `POST /api/v1/projects/{project}/collections/{name}/search` `{query_text?, query_vector?, top_k?, min_score?, filters?}` - Cosine-similarity search. Supply either `query_text` or `query_vector`; neither is **422**. `top_k` caps the results, **default 5**. `min_score` (0-1) drops low-confidence matches, default 0. `filters` is an array of `field:op:value` strings applied to the vector's metadata, using the grammar and operators above - metadata is stored at the top level of the document, so a vector written with `metadata:{"colour":"red"}` is filtered as `colour:eq:red`. The response also carries **`scan_capped`** and `scanned` (plus `scan_cap` when capped). **UPGRADE NOTE: a filtered search may now return MORE rows than it did before, and that is the fix rather than a break.** On the old capped path a filter whose matches lay deeper than the walk returned fewer hits than matched - one collection measured 426 rows for a filter with ~553 true matches at `top_k: 500`. On 2.14.0 the same query returns the full 500. So `top_k` now bounds a COMPLETE set rather than a truncated one, and code that was tuned around the smaller number - a page size, a display limit, a loop termination, a count treated as a ceiling - will see the larger one. If you built against the capped behaviour, check those before concluding a filter stopped filtering.
+
+**Against database 2.14.0 or newer a filtered search is a single server-side call: the filter selects candidates BEFORE ranking, so the answer is the exact top-K among matching rows, there is no scan cap, `scan_capped` is always `false` and `scanned` is `0`** - and it is FASTER than the same search unfiltered, because only matching rows are scored. Against an older server the service falls back to walking the ranking `scan_cap` deep, and there a filter whose matches lie deeper than the walk returns FEWER hits than match, which is what `scan_capped: true` reports. `scan_capped: false` always means the answer is complete; on 2.14.0+ it is complete by construction, on the fallback it means complete this time. **On the fallback, check it before treating a filtered result set as exhaustive.** Note `min_score` defaults to 0, which drops rows whose cosine is NEGATIVE - pass a negative `min_score` to see every match. Rows with equal scores are ordered by id, lowest first. Inside a function the return stays an array and a truncation warning goes to the run's console instead.
 
   Filtering is evaluated by the database, then intersected with the similarity ranking, so scores are identical with and without a filter and `min_score` means the same thing either way. The scan is bounded at 10000 candidates: within a collection of that size a filtered search returns exactly the true top-k, and beyond it a filter matching only very low-ranked vectors may return fewer.
 

部分文件因文件數量過多而無法顯示