Getting the error "UnexpectedStatusCodeException: batch response! Unexpected status code: 502, with response body: None."

Here is the code I used to create a schema using weaviate.

def create_schema():
schema = {
“classes”: [
“class”: “IngredientVocabulary”,
“properties”: [
“name”: “ingredient”,
“dataType”: [“text”]
“vectorizer”: “text2vec-huggingface”,
“moduleConfig”: {
“text2vec-huggingface”: {
“model”: “sentence-transformers/multi-qa-MiniLM-L6-cos-v1”,
“options”: {
“waitForModel”: True,
“useGPU”: True,
“useCache”: True

if os.path.exists('/content/drive/MyDrive/Colab Notebooks/FYP/used_ingredients.csv'):
    df = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/FYP/used_ingredients.csv', index_col=0)
    add_ingredients(df.head(4500), batch_size=99, debug_mode=True)
    return {"message": "Schema created with embeddings"}
return {"message": "Schema created"}

Here is the add_ingredient() function.

def add_ingredients(data, batch_size=512, debug_mode=False):
“”" upload embeddings to Weaviate

:param data: wine data in panda dataframe object
:type data: panda dataframe object (2 columns: 'Ingredient' and 'Embedding_Content')
:param batch_size: number of data objects to put in one batch, defaults to 512
:type batch_size: int, optional
:param debug_mode: set to True if you want to display upload errors, defaults to False
:type debug_mode: bool, optional

no_items_in_batch = 0

for index, row in data.iterrows():
    ingredient_object = {
        "ingredient": index.replace("_", " "),

    ingredient_uuid = generate_uuid('IngredientVocabulary', index)

    # client.data_object.create(data_object=ingredient_object, class_name="IngredientVocabulary",
    #                           uuid=ingredient_uuid,
    #                           )
    client.batch.add_data_object(ingredient_object, "IngredientVocabulary", ingredient_uuid)
    no_items_in_batch += 1

    if no_items_in_batch >= batch_size:
        results = client.batch.create_objects()

        if debug_mode:
            for result in results:
                if result['result'] != {}:

            message = str(index.replace("_", " ")) + ' / ' + str(data.shape[0]) + ' items imported'

        no_items_in_batch = 0


When I run the above code in weaviate cloud service it generates following error.

UnexpectedStatusCodeException Traceback (most recent call last)

in <cell line: 1>() ----> 1 create_schema()

/usr/local/lib/python3.10/dist-packages/weaviate/ in _decode_json_response_list(response, location) 811 except JSONDecodeError: 812 raise ResponseCannotBeDecodedException(location, response) → 813 raise UnexpectedStatusCodeException(location, response)

UnexpectedStatusCodeException: batch response! Unexpected status code: 502, with response body: None.

Can you help me reagrding this matter. Thank you.


Welcome to our community :hugs:

This error will happen because Weaviate is under heavy workload due to the huge ammount of data being ingested in a short period of time.

To avoid that, you need to increase the resources of the Server and/or reduce the batch size (I see you are using 512) and add a import throttle, so it let Weaviate have enough resources to both ingest the data and create the vector index.

We usually suggest a batch size of 100. It will depend on the ammount of properties your object has, but 100 is a good number. Then you can increase the workers to increase the import rate.

Also consider doing a proper error handling and using deterministic id so you can have a better control of imported x not imported objects.

Let me know if that helps :slight_smile:

Thank you very much for your fast reply sir.

I reduce the batch size and tried again. But the same error occurs again. Is there any other solution for this?

Thank you.

Does it happen to all objects or only a few?

This is probably due to the ammount of objects being imported in a short period of time.

So you will need to throttle the import. Is this running in WCS?