Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: create collection through pymilvus, no error raised but collection list is still empty #34134

Closed
1 task done
zydmtaichi opened this issue Jun 25, 2024 · 6 comments
Closed
1 task done
Labels
help wanted Extra attention is needed

Comments

@zydmtaichi
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Environment

- Milvus version:2.4.1
- Deployment mode(standalone or cluster):standalone
- MQ type(rocksmq, pulsar or kafka):    
- SDK version(e.g. pymilvus v2.0.0rc2):2.4.4
- OS(Ubuntu or CentOS): windows
- CPU/Memory: 
- GPU: 
- Others:

Current Behavior

I connect to milvus db using python SDK ,then create db and collection, the db creation is good but collection can't be created.
my example is pasted below:

from pymilvus import connections, MilvusClient, db, FieldSchema, DataType, CollectionSchema, Collection

conn = connections.connect(host="127.0.0.1", port=19530)

#newdatabase = db.create_database("llamatest")

client = MilvusClient(uri="http://127.0.0.1:19530")

db.using_database("llamatest")

res = db.list_database()

print(res)

my_id = FieldSchema(name="id", dtype=DataType.INT64, is_primary=True, description="this is id")
my_vec = FieldSchema(name="vec", dtype=DataType.FLOAT_VECTOR, dim=128, description="embed vec")

fields = [my_id, my_vec]

schema = CollectionSchema(fields=fields, auto_id=False, enable_dynamic_id=True, description="test collection")

my_collection = Collection(name="coll_test", schema=schema, using="default")

res2 = client.list_collections()

print(res2)

This example raise nothing,but the res2 which represents the collections existed is still printed as a empty list.

Expected Behavior

No response

Steps To Reproduce

No response

Milvus Log

No response

Anything else?

No response

@zydmtaichi zydmtaichi added kind/bug Issues or changes related a bug needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 25, 2024
@yanliang567
Copy link
Contributor

@zydmtaichi checking the code above, you are using 2 connections: conn and client. The working database of conn is llamatest as you called using_database, while the working database of client is default. So try to call utility.list_collection(). BTW, I think you don't need the client connection at all.
/assign @zydmtaichi
/unassign

@xiaofan-luan
Copy link
Contributor

you seem to mix use two style of apis

when you create collection
my_collection = Collection(name="coll_test", schema=schema, using="default")

you actaully create a colleciton under default databse, not the database you created.

this is the right API

client.create_collection(
collection_name="customized_setup_1",
schema=schema,
index_params=index_params
)

https://milvus.io/docs/manage-collections.md

@yanliang567 yanliang567 added help wanted Extra attention is needed and removed kind/bug Issues or changes related a bug needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 25, 2024
@zydmtaichi
Copy link
Author

@zydmtaichi checking the code above, you are using 2 connections: conn and client. The working database of conn is llamatest as you called using_database, while the working database of client is default. So try to call utility.list_collection(). BTW, I think you don't need the client connection at all. /assign @zydmtaichi /unassign

yeah,your point is correct,i switch to utility and it shows the collection name as i want

@zydmtaichi
Copy link
Author

you seem to mix use two style of apis

when you create collection my_collection = Collection(name="coll_test", schema=schema, using="default")

you actaully create a colleciton under default databse, not the database you created.

this is the right API

client.create_collection( collection_name="customized_setup_1", schema=schema, index_params=index_params )

https://milvus.io/docs/manage-collections.md

"default" is a aliase of connection(per doc),i just want to create a collection under the db "llamatest", but using="llamatest" is not worked, what should i do

@zydmtaichi zydmtaichi removed their assignment Jun 25, 2024
@yanliang567
Copy link
Contributor

yanliang567 commented Jun 25, 2024

MilvusClient and utility are two different styles of python sdk for milvus. if you want to use MilvusClient, you can call

client.using_database(db_name= llamatest)
client.list_collections()

@yanliang567
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants