Skip to content

[Bug]: Using negative indexing to retrieve records results in an empty vector. #3136

@maocatooo

Description

@maocatooo

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

the code:

from pymilvus import connections, Collection

connections.connect("default")

collection = Collection("K_DB")
results = collection.query(
    expr="",
    output_fields=["id", "vector"],
    limit=3,
)
print("results", results[-1])
# out results {'id': 7391398968791437314, 'vector': []}
for i in results:
    print(i)

Expected Behavior

The expected correct vector result:
{'id': 7391398968791437314, 'vector': [-0.03041940927505493, ......]}

I will add logic in pymilvus/client/types.py:1197 within HybridExtraList.__getitem__ to convert negative indices to positive indices, ensuring the correct results are retrieved.

def __getitem__(self, index: Union[int, slice]):
    ...

    self._pre_materialize_float_vector()

    if index < 0:
        index = len(self) + index

    ...
    return row

Steps/Code To Reproduce behavior

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0):
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions