# Add function (legacy)

Milvus 3.0.6 rejects this legacy route. Use add_function_field for BM25 or MinHash, or define a text embedding function when creating a collection.

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/schema/add-function/

## Section links

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

`POST /v2/vectordb/collections/add_function`

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/collections/add_function' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer ${MILVUS_TOKEN}" \
  --data-raw '{
  "dbName": "default",
  "collectionName": "books",
  "function": {
    "name": "title_bm25",
    "type": "BM25",
    "inputFieldNames": [
      "title"
    ],
    "outputFieldNames": [
      "title_sparse"
    ]
  }
}'
```

## Default request

```json
{
  "dbName": "default",
  "collectionName": "books",
  "function": {
    "name": "title_bm25",
    "type": "BM25",
    "inputFieldNames": [
      "title"
    ],
    "outputFieldNames": [
      "title_sparse"
    ]
  }
}
```

## Sample response

```json
{
  "code": 1100,
  "message": "AddCollectionFunction RPC is no longer supported; add BM25/MinHash via add_function_field, and define a TextEmbedding function at collection creation: invalid parameter"
}
```

## Request fields

- `dbName` string
  Database name. Operations on collections use default when omitted.
- `collectionName` string (required)
  Name of the collection.
- `function` object (required)
  Function definition with name, type, inputFieldNames and outputFieldNames.

For new SDK code, use [`HttpClient.addFunctionField`](https://milvus-io.github.io/milvus-sdk-node/api-reference/http-client/#addfunctionfield) to manage the function together with its output field and index.
