Weird Error When Running index.query

Hello, i am trying to query my ‘gcp-starter’ index like this:


output = index.query(
            # id=None,
            # vector=None,
            filter={"public_identifier": {"$in": public_identifiers}},
            include_metadata=True,
            top_k=len(public_identifiers) * 3,
        )

It throws 400 ‘Bad Request’ with {“code”:3,“message”:“Cannot provide both ‘ID’ and ‘vector’ at the same time”,“details”:}

I am not using id or vector, what could be the problem?

@jhlfrfufyfn I’m unable to reproduce the same error message when I execute a similar operation on one of my indexes. When I don’t provide an ID or a vector, I get: {"code":3,"message":"No query provided","details":[]}.

Could you please check and share what version of the Python SDK you are using? The most recent version is v2.2.4.

Also, please note that the query() request must contain one (and only one) of the id or vector parameters, so the code you’ve provided is expected to result in an error.

It looks like you are attempting to run a query on metadata alone. The query method requires only an id or vector and None is not a valid value for either. And at least one of those two kwargs is required.

To do what you want to accomplish you should pass in a n-dimension list of all 0’s.

So for example, lets say you are searching across an index that is configured for OpenAI’s `text-embedding-ada-002 (1536 dimensions)

output = index.query(
            vector=[0] * 1536, # [0,0,0,0......0]
            filter={"public_identifier": {"$in": public_identifiers}},
            include_metadata=True,
            top_k=len(public_identifiers) * 3,
        )
# Output will give you top `len(public_identifiers) * 3` it can return!
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.