Error when trying to run the code cell

Im getting an error like this when i try to run a cell code that contains embedding,

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File /usr/local/lib/python3.10/site-packages/requests/models.py:971, in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /usr/local/lib/python3.10/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File /usr/local/lib/python3.10/json/decoder.py:340, in JSONDecoder.decode(self, s, _w)
    339 if end != len(s):
--> 340     raise JSONDecodeError("Extra data", s, end)
    341 return obj

JSONDecodeError: Extra data: line 1 column 5 (char 4)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
Cell In[20], line 1
----> 1 embedding = embedding_model.get_embeddings(
      2     ["life"])

File /usr/local/lib/python3.10/site-packages/vertexai/language_models/_language_models.py:508, in TextEmbeddingModel.get_embeddings(self, texts)
    494 def get_embeddings(self, texts: List[str]) -> List["TextEmbedding"]:
    495     # instances = [{"content": str(text)} for text in texts]
    496     #
   (...)
    506     #     for prediction in prediction_response.predictions
    507     # ]
--> 508     prediction_response = self._dlai_custom_api(texts)
    509     return [
    510         TextEmbedding(
    511             values=prediction
    512         )
    513         for prediction in prediction_response
    514     ]

File /usr/local/lib/python3.10/site-packages/vertexai/language_models/_language_models.py:532, in TextEmbeddingModel._dlai_custom_api(self, texts)
    527 headers = {
    528     'Content-Type': 'application/json',
    529     'Authorization': f'Bearer {API_KEY}'
    530 }
    531 response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
--> 532 return response.json()

File /usr/local/lib/python3.10/site-packages/requests/models.py:975, in Response.json(self, **kwargs)
    971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Extra data: line 1 column 5 (char 4)

You should try the suggestion here
L1-Embeddings-api-intro Error - Short Course Q&A / Understanding and Applying Text Embeddings with… - DeepLearning.AI

1 Like