Laurent Claessens
Laurent Claessens

Reputation: 695

milvus query returns only one result

Milvus 2.1.2

I create one collection of entities made of one vector (vector) and one string (im_id).

In other words, I associate one image id to each vector. I'm able to make research over the vector. I'm trying to make a query on the image id.

Here is the code:

#!venv/bin/python3

from pymilvus import (
    connections,
    utility,
    FieldSchema,
    CollectionSchema,
    DataType,
    Collection,
)

port = 30100
connections.connect("default", host="localhost", port=port)
utility.drop_collection("hello_milvus")
fields = [
    FieldSchema(name="im_id", dtype=DataType.VARCHAR,
                is_primary=True, auto_id=False,
                max_length=200),
    FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=2)
]
schema = CollectionSchema(fields)
hello_milvus = Collection("hello_milvus", schema)
hello_milvus.load()

vect1 = [10, 20]
vect2 = [3, 4]
vect3 = [5, 6]
im_id1 = "foo"
im_id2 = "bar"
im_id3 = "foo"

hello_milvus.insert([[im_id1], [vect1]]) # this is a foo
hello_milvus.insert([[im_id2], [vect2]]) # this is a bar
hello_milvus.insert([[im_id3], [vect3]]) # this is a foo

print(hello_milvus.num_entities)  # 3 entities, ok

results = hello_milvus.query(expr='im_id == "foo"',
                             output_fields=["vector"])

print("results", results)

This prints : [{'im_id': 'foo', 'vector': [10.0, 20.0]}].

I've tried some variations, but I always get only one result.

Any ideas ? What am I doing wrong ?

Upvotes: 0

Views: 1347

Answers (1)

Jack
Jack

Reputation: 85

results = hello_milvus.query(expr='im_id like "foo%"', output_fields=["vector"])

Maybe you can try this way to get all the qualified results.

Upvotes: 0

Related Questions