Skip to main content
Version: User Guides (Cloud)

On-Demand DQL Operations
Public Preview

DQL operations in collections for on-demand computing, such as search, query, get, and hybrid search, require attaching compute resources from an on-demand cluster. Zilliz Cloud allows you to create a session to meet your on-demand compute needs.

This article assumes that you have created a collection in a database using the project endpoint. For details, refer to Create an External Collection.

Connect to a project endpoint

A project endpoint is designed to provide your access to on-demand compute resources. You can use it to manage on-demand clusters and databases, as well as manipulate data stored in collections.

The following code example assumes that you have an external collection named my_collection in the default database. And you should always use a valid API key with sufficient permissions to set up the connection.

client = MilvusClient(
uri="https://{project-id}.{region}.vectordb.zillizcloud.com",
token="YOUR_API_KEY"
)

client.has_collection(
collection_name="my_collection"
)

Create a session

Once you set up a connection to the project endpoint, create a session to attach the compute resource from a specified on-demand cluster.

The following example assumes that you have already created an on-demand cluster, whose ID is inxx-xxxxxxxxxxxxxxxxx.

📘Notes

For RESTful requests, instead of creating a session, you should pass the cluster ID as a query parameter to DQL calls.

session = client.session(
cluster_id="inxx-xxxxxxxxxxxxxxxxx"
)

Conduct DQL operations

Once the session is ready, you can conduct searches. The following example uses a basic vector search as an example. This also applies to query, get, and hybrid search.

query_vector = [0.3580376395471989, -0.6023495712049978, 0.18414012509913835, -0.26286205330961354, ..., 0.9029438446296592]
res = session.search(
db_name="my_database",
collection_name="my_collection",
anns_field="vector",
data=[query_vector],
limit=3,
output_fields=["product_id", "title", "main_category", "price", "average_rating", "rating_number"]
)

Close a session

Once your on-demand computing tasks are complete, you can close the session. A closed session cannot be used for further DQL operations.

📘Notes

RESTful calls do not need this.

session.close()