# Search Records by Vector

`POST /data/{collection}/search` · Core · Data, Queries & Vectors

The record list read with its query in the body, for a vector too long for a URL. The body is:

```
{ vectorSearch: { column, vector, metric?, limit? }, filter?, select?, order?, limit?, cursor?, count?, or? }
```

Runs exactly what `GET /data/{collection}` runs for the same parameters (the same read access, row policies and field reveal), so the rows and their order are the same, nearest first. A `vectorSearch.column` the collection does not have answers `K9O_INVALID_FIELD_VALUE` (400). Exempt from read-only suspension, like the GET.

The same filter bounds, time limit (`K9O_QUERY_TIMEOUT`, 504) and protected-column equality rule apply.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `collection` | path | yes | The collection's name. Example: `"products"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `vectorSearch` | object | yes | The nearest-neighbour search to run. |
| `vectorSearch.column` | string | yes | The vector column to search, as named in the collection. It must be a vector column of the collection. |
| `vectorSearch.vector` | array of number | yes | The query vector: finite numbers. Its length must equal the column's dimension. |
| `vectorSearch.metric` | enum ("cosine", "euclidean", "dot") | no | How similarity is measured. Default `cosine`. |
| `vectorSearch.limit` | integer | no | The most nearest records to return, 1 to 1000. |
| `filter` | object | no | Narrows the records searched. Each key is a column name and each value is the same `<operator>.<value>` expression the list endpoint takes in its query string. A key that is a list parameter name, or `deleted`, is refused. |
| `select` | string | no | The columns to return, as in the list endpoint's `select` parameter. |
| `order` | string | no | The sort order, as in the list endpoint's `order` parameter. |
| `limit` | object | no | The page size, as in the list endpoint's `limit` parameter. A number or a numeric string. |
| _one of_ | | |  |
| _or_ | | |  |
| `cursor` | string | no | A `meta.cursor.next` value from an earlier answer, to fetch the next page. |
| `count` | enum ("none", "exact", "estimated") | no | Whether to count the matching records, as in the list endpoint's `count` parameter. Default `none`. |
| `or` | string | no | An OR group of filters, as in the list endpoint's `or` parameter. |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A page of records; a single record with `single=true` (an error when no record or more than one record matches); or the aggregate values with `aggregate`. |
| _one of_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| `meta` | object | yes | Request metadata (cost, timing, request and trace ids), plus the pagination cursor on a list answer. |
| `meta.cursor` | object | no | Pagination. Present on a list answer; absent with `single` or `aggregate`. |
| `meta.cursor.next` | object | yes | Opaque cursor for the next page; pass it back as `cursor`. Null on the last page, and always null with `range`. |
| _one of_ | | |  |
| _or_ | | |  |
| `meta.cursor.totalCount` | object | no | The filtered row count when `count` is `exact` or `estimated` (from the planner's statistics); null when `count` is `none` (the default). Absent with `deleted=true`. |
| _one of_ | | |  |
| _or_ | | |  |
| `meta.cursor.countMethod` | enum ("none", "exact", "estimated") | no | The `count` mode the read ran with. Absent with `deleted=true`. |
| `meta.warnings` | array of object | no | Present only when a warning applies. |
| `meta.warnings.[]code` | string | yes | A warning code. This read adds `K9O_ORG_CLAIM_UNBOUND` (the token has no org claim, so org-scoped row policies may hide every row) and `OFFSET_PAGINATION_INEFFICIENT` (a `range` starting past row 1000). |
| `meta.warnings.[]message` | string | yes | A readable explanation. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_SESSION_EXPIRED` | The caller's session has expired. |
| 401 | `K9O_INVALID_CREDENTIALS` | The caller is not authenticated. |
| 400 | `K9O_INVALID_FIELD_VALUE` | The body is not `{ vectorSearch: { column, vector, metric?, limit? }, filter?, select?, order?, limit?, cursor?, count?, or? }`. Any of these cases applies:

- An unknown field, a non-numeric vector, an invalid column, metric or limit, or a filter key that is not a column.
- A filter, select or order expression is invalid.
- The vectorSearch column does not exist on the collection.
- The vectorSearch column is not a vector column (reason not_a_vector_column).
- The vectorSearch column holds a different dimension than the query vector (reason dimension_mismatch). |
| 403 | `K9O_ACCESS_DENIED` | The caller has no read access to this collection, the same as GET /data/{collection}. |
| 403 | `K9O_EXTENSION_PERMISSION_DENIED` | An extension caller lacks (documents, read, <collection>), the grant GET /data/{collection} requires. |
| 404 | `K9O_COLLECTION_NOT_FOUND` | No such collection in this project. |
| 400 | `K9O_INVALID_FILTER` | A filter operand is past its cap: a `match`, `like` or `ilike` pattern over 256 characters or a `jsonPath` over 512 (`context.reason: "operand_too_long"`), or an `in` / `notIn` list over 1,000 items (`too_many_items`). `context.column`, `context.op` and `context.max` say which. |
| 400 | `K9O_ENCRYPTED_COLUMN_OPERATION_UNSUPPORTED` | The operation is not supported on a protected column: only `eq` and `in` on a searchable one, and on one that needs a reveal purpose only in a read that reveals it (`context.reason: "reveal_required"`). |
| 504 | `K9O_QUERY_TIMEOUT` | The read ran past its time limit and returned nothing. `context.timeoutSeconds` gives the limit; narrow the filter or simplify a pattern. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/data/products/search' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/data/products/search', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({}),
});
const { data, meta } = await res.json();
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/search-records-by-vector
