tmandyai
tmandyai

Reputation: 85

ParamError: Invalid Input for Sparse Float Vector When Inserting Vectors

I am using pymilvus version 2.4.7 and Python 3.11. I encountered an error while trying to insert both dense and sparse vectors into Milvus simultaneously. The error states:

arduino

Copy code

ParamError: (code=1, message=invalid input for sparse float vector: expect 1 row)

Can anyone help me understand what might be causing this issue?

Here is a minimal reproducible example of my code:

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

# Connect to Milvus
connections.connect()

# Define collection schema
fields = [
    FieldSchema(name="id", dtype=DataType.INT64, is_primary=True, auto_id=True),
    FieldSchema(name="dense_vector", dtype=DataType.FLOAT_VECTOR, dim=3),
    FieldSchema(name="sparse_vector", dtype=DataType.SPARSE_FLOAT_VECTOR),
]
schema = CollectionSchema(fields, description="Demo collection with dense and sparse vectors")

# Create collection
collection_name = "test_collection"
collection = Collection(name=collection_name, schema=schema)

# Data to insert
dense_vectors = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]
sparse_vectors = [[(0, 0.1), (2, 0.3)], [(1, 0.2), (2, 0.6)]]

data = [
    [None, None],  # Auto-ID
    dense_vectors,
    sparse_vectors,
]

# Insert data into the collection
try:
    collection.insert(data)
except Exception as e:
    print(f"Error: {e}")

Error Details

When I run this code, I encounter the following error:

ParamError: (code=1, message=invalid input for sparse float vector: expect 1 row)

Expected Behavior

I expect both dense and sparse vectors to be inserted into the collection successfully.

Actual Behavior

The insertion fails with the error above.

Additional Information

How can I fix this issue and correctly insert both dense and sparse vectors? Is there something wrong with my schema or the way I format the data?

Upvotes: 0

Views: 117

Answers (0)

Related Questions