# Search vectors

Find nearest neighbors in a loaded collection. Provide query data or existing primary keys and select a vector field when needed.

SDK: `@zilliz/milvus2-sdk-node@3.0.10` · Tested with Milvus 3.0.6

Canonical documentation: https://milvus-io.github.io/milvus-sdk-node/rest-api/entities/search/

## Section links

- [cURL command](https://milvus-io.github.io/milvus-sdk-node/rest-api/entities/search/#curl-command)
- [Default request](https://milvus-io.github.io/milvus-sdk-node/rest-api/entities/search/#default-request)
- [Sample response](https://milvus-io.github.io/milvus-sdk-node/rest-api/entities/search/#sample-response)
- [Request fields](https://milvus-io.github.io/milvus-sdk-node/rest-api/entities/search/#request-fields)

`POST /v2/vectordb/entities/search`

Replace `https://your-cluster.example.com` with your Milvus endpoint. Set `MILVUS_TOKEN` for authentication or omit the Authorization header on an unauthenticated cluster.

## cURL command

```bash
curl --request POST --url 'https://your-cluster.example.com/v2/vectordb/entities/search' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ${MILVUS_TOKEN}" \
  --data-raw '{
  "dbName": "default",
  "collectionName": "books",
  "data": [
    [
      0.1,
      0.2,
      0.3,
      0.4
    ]
  ],
  "annsField": "vector",
  "limit": 5,
  "outputFields": [
    "title"
  ]
}'
```

## Default request

```json
{
  "dbName": "default",
  "collectionName": "books",
  "data": [
    [
      0.1,
      0.2,
      0.3,
      0.4
    ]
  ],
  "annsField": "vector",
  "limit": 5,
  "outputFields": [
    "title"
  ]
}
```

## Sample response

```json
{
  "code": 0,
  "data": [
    {
      "id": 101,
      "title": "Invisible Cities",
      "distance": 0.98
    }
  ],
  "cost": 0,
  "topks": [
    1
  ]
}
```

You can apply a dense vector field from the described schema to fill a sample vector with the correct dimension. Replace the sample with your embedding before sending.

## Request fields

- `dbName` string
  Database name. Operations on collections use default when omitted.
- `collectionName` string (required)
  Name of the collection.
- `data` array of JSON value
  Query inputs, such as an array of vectors. Supply data or ids.
- `ids` array of JSON value
  Stored primary keys to search by, as an alternative to data.
- `annsField` string
  Vector field to search. Specify it when the collection has multiple vector fields.
- `partitionNames` array of string
  Names of the partitions to target.
- `filter` string
  Milvus scalar filter expression.
- `groupingField` string
  Scalar field used to group search hits.
- `groupSize` integer
  Number of hits requested per group.
- `strictGroupSize` boolean
  Require the specified number of hits in each result group.
- `limit` integer
  Maximum number of rows or hits per query input.
- `offset` integer
  Number of matching results to skip.
- `outputFields` array of string
  Field names to include in the returned entities.
- `searchParams` object
  Index-specific search parameters, including metric and search tuning options.
- `consistencyLevel` string
  Read consistency level, such as Strong, Session, or Bounded.
- `exprParams` object
  Values for placeholders in a filter expression.
- `functionScore` object
  Scoring functions and parameters to apply to candidates.
- `functionChains` array of object
  Ordered function chains to apply during search.
- `searchAggregation` object
  Bucket aggregation and metric configuration for search hits.
- `orderByFields` array of string
  Field ordering expressions for sorted results.
- `params` object
  Additional operation parameters.

See [`HttpClient.search`](https://milvus-io.github.io/milvus-sdk-node/api-reference/http-client/#search) for the Node.js SDK method.
