Understanding Ranged Search #36313
-
Hi everyone, I'm new to Milvus, vector DBs, most AI related stuff. I'm trying to get up to speed using a toy exercise. My goal is to create a 3-dimensional collection that stores colors, and be able to identify all entries similar to a particular color by using a ranged search. I'm stuck on getting Milvus to search by radius. When I try, it just returns everything in my collection, or up to Since I'm going to make video tutorials on this stuff as I learn it, I've got a nifty Blender setup to illustrate this. I'm trying to do a search with radius 120 from point [0, 255, 0] (green). I'm running Milvus 2.4.5, pulled from Dockerhub a few days ago. Create collectioncurl -s --request POST "http://localhost:19530/v2/vectordb/collections/create" \
--data-raw '{
"collectionName": "colors",
"dimension": 3,
"metricType": "L2",
"autoId": true
}' Add itemscurl --request POST "http://localhost:19530/v2/vectordb/entities/insert" --data-raw '{
"data": [
{"vector": [0.0, 255.0, 0.0]}
],
"collectionName": "colors"
}' And so on until the collection contains:
These are the 6 points shown in the image. Load collectioncurl -s --request POST "http://localhost:19530/v2/vectordb/collections/load" --data-raw '{
"collectionName": "colors"
}' I don't quite get why this is needed, but no problems yet. Perform searchcurl -s --request POST "http://localhost:19530/v2/vectordb/entities/search" --data-raw '{
"collectionName": "colors",
"data": [
[0, 255, 0]
],
"outputFields": ["id", "vector"],
"searchParams": {
"metricType": "L2",
"params": {
"radius": 14400
}
}
}' | jq I'm expecting to get [0, 255, 0], [100, 255, 0], and [0, 255, 55] as in the picture. But it just returns all 6 points. I've also tried the equivalent search in Python: from pymilvus import connections, Collection
connections.connect("default", host="192.168.1.17", port=19530)
colors_collection = Collection("colors")
colors_collection.load()
results = colors_collection.search(
data=[
[0, 255, 0]
],
anns_field="vector",
param={
"radius": 14400
},
limit=1000,
output_fields=["vector"]
)
colors_collection.release()
connections.disconnect("default")
for item in results[0]:
print(item) This gives the same result of all 6 entries coming back. Any help would be appreciated. I'm just a zoomer who copy pastes AI generated code so I don't fully grasp all of this 😇 Relevant docs/discussions for convenience: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Two problems in your script:
This is the correct script:
The expected results:
|
Beta Was this translation helpful? Give feedback.
There is a small bug for restful search api, it cannot accept ""searchParams"".
You can set the rage like this: