qdrant / qdrant-client

Python client for Qdrant vector search engine
https://qdrant.tech
Apache License 2.0
786 stars 120 forks source link

Python client type hint error with column-oriented upsert #784

Open affanshahid opened 1 month ago

affanshahid commented 1 month ago

I'm trying to do an upsert without hard-coded data and I get some type hint errors. Everything works fine so I'm assuming its just a typing issue.

image

The error on ids is:

Pyright: Argument of type "list[int]" cannot be assigned to parameter "ids" of type "List[ExtendedPointId]" in function "__init__"
  "list[int]" is not assignable to "List[ExtendedPointId]"
    Type parameter "_T@list" is invariant, but "int" is not the same as "ExtendedPointId"
    Consider switching from "list" to "Sequence" which is covariant

I can fix this one by typing the ids declaration as ids: list[ExtendedPointId]. This may be just a pyright issue since ExtendedPointId is defined as int | str.

The error on vectors is:

Pyright: Argument of type "Iterable[ndarray[Unknown, Unknown]]" cannot be assigned to parameter "vectors" of type "BatchVectorStruct" in function "__init__"
  Type "Iterable[ndarray[Unknown, Unknown]]" is not assignable to type "BatchVectorStruct"
    "Iterable[ndarray[Unknown, Unknown]]" is not assignable to "List[List[StrictFloat]]"
    "Iterable[ndarray[Unknown, Unknown]]" is not assignable to "List[List[List[StrictFloat]]]"
    "Iterable[ndarray[Unknown, Unknown]]" is not assignable to "Dict[StrictStr, List[Vector]]"

Can't seem to get around this one without a cast. Like I said, everything works but the type errors hamper the DX.

joein commented 1 month ago

Hi @affanshahid Thanks for reporting this, we'll look into it Could you please tell us qdrant-client version you're using along with the version of pyright?

affanshahid commented 1 month ago
joein commented 1 month ago

Hey @affanshahid We took a look at the issue, we might need more time to fix the problem with ids However, embeddings type hint issue seems to be correct, since it does not expect numpy arrays

affanshahid commented 1 month ago

I see, i imported TextEmbedding from fastembed in the example, what would be the correct way of doing this? Cast to regular list?