AddCollectionFunction()

This operation attaches a function definition to an existing collection, such as a BM25 function over text fields.

Status AddCollectionFunction(const AddCollectionFunctionRequest& request)

Request Syntax

auto request = AddCollectionFunctionRequest()
    .WithCollectionName(collection_name)
    .WithFunction(function_ptr);

AddCollectionFunctionRequest

REQUEST METHODS:

  • WithCollectionName(const std::string& collection_name)

    Sets the collection that will receive the new function.

  • WithDatabaseName(const std::string& db_name)

    Sets the database containing the target collection.

  • WithFunction(const FunctionPtr& function)

    Supplies the function definition to add.

RETURNS:

Status

EXCEPTIONS:

  • StatusCode

    Check status.Code() and status.Message() for duplicate function names, invalid function definitions, or collection state errors.

Example

#include <milvus/MilvusClientV2.h>
auto client = milvus::MilvusClientV2::Create();
milvus::ConnectParam connect_param{"http://localhost:19530", "root:Milvus"};
auto status = client->Connect(connect_param);
if (!status.IsOk()) {
    std::cout << status.Message() << std::endl;
}

auto function = std::make_shared<milvus::Function>();
function->SetName("bm25_fn");

status = client->AddCollectionFunction(
    milvus::AddCollectionFunctionRequest()
        .WithCollectionName("docs")
        .WithFunction(function));
if (!status.IsOk()) {
    std::cout << status.Message() << std::endl;
}

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?