googleapis / googleapis/python-aiplatform
google.api_core.exceptions.InvalidArgument: 400 Query Value must be of type vector.
- 主要言語
- Python
- スター
- 905
- フォーク
- 465
- 平均マージ
- 1日 13時間
- マージ済み PR(30日)
- 44
説明
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


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.
```
コントリビューションガイド
評価
この issue はまだ評価されていません。