weaviate-python-client icon indicating copy to clipboard operation
weaviate-python-client copied to clipboard

Investigate vector given as string

Open dirkkul opened this issue 1 year ago • 2 comments

From a user report:

I just tried inserting ["0.4", "0.2"...] instead of [0.4, 0.2].. again silly but Weaviate accepted this but was then unable to query the vectors it seemed.

dirkkul avatar Jan 13 '25 09:01 dirkkul

Hey @dirkkul,

I tried to reproduce it, but I Weaviate rejected both of my attempts:

Example 1

qt = client.collections.get("QuickTest")
qt.data.insert(
    properties={
        "title": "Try Array of strings as a vector"
    },
    vector=["0.1", "0.2"]
)

Throws the following error:

UnexpectedStatusCodeError: Object was not added! Unexpected status code: 400, with response body: {'code': 400, 'message': 'parsing body body from "" failed, because json: cannot unmarshal string into Go struct field Object.vector of type float32'}.

Example 2

qt = client.collections.get("QuickTest")
qt.data.insert(
    properties={
        "title": "Try a string with an array text inside"
    },
    vector="[0.1, 0.2]"
)

Throws the following error:

WeaviateInvalidInputError: Invalid input provided: The vector you supplied was malformatted! Vector: [0.1, 0.2].

sebawita avatar Jan 22 '25 17:01 sebawita

Thanks for checking @sebawita - if you have time, could you also try insert_many?

dirkkul avatar Feb 12 '25 07:02 dirkkul

I have investigated the issue on chore/investigate-strings-in-vector and cannot reproduce the exact behaviour quoted in the OP. There is a nuance which is that batching accepts the vector, since it uses pydantic to coerce the list[str] into list[float], but the tests I've added on that branch show that the vector is saved to the DB and is returnable with queries

tsmith023 avatar Apr 23 '25 11:04 tsmith023