# Search Vectors

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

Search vectors. (Data, Queries & Vectors) POST `/@:projectSlug/vectors/{collection}/search`.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `collection` | path | yes | The derived collection's name. It starts with `_`. Example: `"_context_chunks"`. |
| `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 |
|---|---|---|---|
| `queryVector` | array of number | yes | The query embedding. Its dimension must match the collection's (400 `K9O_INVALID_VECTOR_DIMENSION` otherwise). |
| `topK` | integer | no | The most results to return. Default 10. |
| `minScore` | number | no | Drop results whose `score` is below this. No threshold when omitted. |
| `metric` | enum ("cosine", "euclidean", "dot") | no | How similarity is measured and scored. Default `cosine`. |
| `filters` | object | no | Equality filters; every one must match. Keys are `id`, `contentHash`, `source.<key>` or `metadata.<key>`, where `<key>` is letters, digits and `_` (any other key is 400 `K9O_INVALID_FIELD_VALUE`). Values are strings, numbers or booleans, compared by their text form (so `2` matches a stored `2` or `"2"`). |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The search results. |
| `data.results` | array of object | yes | The closest chunks, most similar first (ties broken by id), at most `topK`, filtered by `filters` and `minScore` and by the caller's row access. Empty when nothing matches. |
| `data.results.[]id` | string | yes | The chunk's id. |
| `data.results.[]score` | object | yes | Similarity to the query, higher is closer. `cosine`: 1 minus the cosine distance (1 for an identical direction). `euclidean`: 1 / (1 + distance), in (0, 1]. `dot`: the inner product. Null when the similarity is undefined: a `cosine` search with an all-zero query vector, or a stored vector of all zeros. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.results.[]_source` | object | yes | The `_source` object sent on upsert. |
| `data.results.[]_source.handle` | string | yes | The source handle sent on upsert. |
| `data.results.[]_source.chunkIndex` | integer | yes | The chunk's position within its source. |
| `data.results.[]contentHash` | object | yes | A keyed hash of the chunk's `text`, computed by the platform: 64 lowercase hex. It is the same for the same text in the same collection, so a caller can skip re-embedding a chunk whose hash is unchanged, and it can't be compared across collections or projects. Null when the chunk has no `text`, or when the project's keys are held in the customer's own cloud KMS. Filterable as `contentHash`. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.results.[]text` | object | yes | The chunk's source text (decrypted for a per-subject chunk), or null when none was sent. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.results.[]metadata` | object | yes | The chunk's `metadata` object exactly as sent on upsert (`{}` when none was sent): your own keys, with any JSON values. |
| `data.results.[]model` | object | yes | `metadata.model` copied out, or null when the chunk's metadata has no `model` key. Normally the embedding model's name (a string); the gateway returns whatever value was stored. |
| `data.results.[]chunk` | object | yes | `_source.chunkIndex` copied out, or null when it is absent. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.collection` | string | yes | The derived collection searched. |
| `meta` | object | yes | Request metadata: request id, trace id, timing and cost. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 400 | `K9O_INVALID_FIELD_VALUE` | The project identifier in the request path is not valid. |
| 400 | `K9O_INVALID_FIELD_VALUE` | Vector search only targets a '_'-prefixed derived collection; use the query-builder vectorSearch() for a regular collection. |
| 400 | `K9O_INVALID_FIELD_VALUE` | The filters object referenced an unsupported path; only id, contentHash, source.<key>, and metadata.<key> are allowed. |
| 404 | `K9O_COLLECTION_NOT_FOUND` | This derived vector collection has never been upserted into, so there is nothing to search. |
| 400 | `K9O_INVALID_VECTOR_DIMENSION` | The query vector's dimension does not match the dimension stored for this collection. |

## Code samples

### cURL

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

### k9o CLI

```bash
k9o vectors nearest <collection> --vector '<json array>' --vector-file <path|->
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.vectors.nearest('<collection>', {})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.vectors.nearest("<collection>", {})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Vectors.Nearest(ctx, "<collection>", map[string]any{})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.vectors.nearest("<collection>", json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.vectors().nearest("<collection>", Map.of())
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Vectors.NearestAsync("<collection>", new Dictionary<string, object> {  })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.vectors.nearest("<collection>", {  })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->vectors->nearest('<collection>', [])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/search-vectors
