googleapis / googleapis/python-aiplatform

google.api_core.exceptions.InvalidArgument: 400 Query Value must be of type vector.

Abierto
#4,979 0 comentarios 0 reacciones 0 asignados Ver en GitHub
api: vertex-ai
Lenguaje dominante
Python
Estrellas
905
Forks
465
Merge medio
1 d 13 h
PR fusionados (30 d)
44

Descripción

I'm trying to use the find_nearest function to get a vector query

My main.py is as follows
```
embeddings = embed_text([body])
print(f"Type of embeddings before find_nearest: {type(embeddings)}")
if isinstance(embeddings, list):
if len(embeddings) > 0:
print(f"Type of first element in embeddings: {type(embeddings[0])}")
else:
print("Embeddings list is empty")
print(f"Length of embeddings before find_nearest: {len(embeddings)}")
print(f"Value of embeddings before find_nearest: {embeddings}")
else:
print(f"Embeddings is not a list. Value: {embeddings}")
print('embedding type')
print(type(embeddings))
print([type(x) for x in embeddings])

knn = firestore.Client().collection('products').find_nearest(
vector_field="embedding_field",
query_vector=embeddings,
distance_measure=DistanceMeasure.EUCLIDEAN,
limit=5,
distance_threshold=1.0,
distance_result_field="vector_distance",
)
# knn = db.collection('products').order_by_vector("embedding_field", embeddings).limit(5)

# answer = response.choices[0].message.content
print('Knn')
print(knn)
print(type(knn))

docs = knn.get()
print('Docs')
print(docs)
for doc in docs:
print(f"{doc.id}, Distance: {doc.get('vector_distance')}")
```

embed_text.py
```
def embed_text(texts):
"""Embeds texts with a pre-trained, foundational model.

Returns:
A list of lists containing the embedding vectors for each input text
"""

# A list of texts to be embedded.
# texts = ["banana muffins? ", "banana bread? banana muffins?"]
# The dimensionality of the output embeddings.
# dimensionality = 256
# The task type for embedding. Check the available tasks in the model's documentation.
task = "RETRIEVAL_DOCUMENT"

inputs = [TextEmbeddingInput(text, task) for text in texts]
# kwargs = dict(output_dimensionality=dimensionality) if dimensionality else {}
# embeddings = model.get_embeddings(inputs, **kwargs)
embeddings = model.get_embeddings(inputs)

print(embeddings)
# Example response:
# [[0.006135190837085247, -0.01462465338408947, 0.004978656303137541, ...], [0.1234434666, ...]],
# return [embedding.values for embedding in embeddings]
return np.array(embeddings[0].values).tolist()
```

Firestore already has a vector field which is embedding_field, and i already created a vector index

![Image](https://github.com/user-attachments/assets/2e91f99d-3128-47bf-8c1a-acfb2c22bd9e)

![Image](https://github.com/user-attachments/assets/66b98f0c-18e7-421a-955d-983133a2cb7e)

However, my in my python code, which is my client end, i still having this issue
```
Traceback (most recent call last):
File "C:\Python Projects\crm-ai\main.py", line 364, in
docs = knn.get()
^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\cloud\firestore_v1\vector_query.py", line 96, in get
result_list = list(result)
^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\cloud\firestore_v1\stream_generator.py", line 58, in __next__
return self._generator.__next__()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\cloud\firestore_v1\vector_query.py", line 163, in _make_stream
response_iterator, expected_prefix = self._get_stream_iterator(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\cloud\firestore_v1\vector_query.py", line 114, in _get_stream_iterator
response_iterator = self._client._firestore_api.run_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\cloud\firestore_v1\services\firestore\client.py", line 1558, in run_query
response = rpc(
^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\retry\retry_unary.py", line 293, in retry_wrapped_func
return retry_target(
^^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\retry\retry_unary.py", line 153, in retry_target
_retry_error_helper(
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
raise final_exc from source_exc
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\retry\retry_unary.py", line 144, in retry_target
result = target()
^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lian Jiet\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\api_core\grpc_helpers.py", line 174, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Query Value must be of type vector.
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.