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
}
}
}
}
]
}
client.schema.create(schema)
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'] != {}:
log(result['result'])
message = str(index.replace("_", " ")) + ' / ' + str(data.shape[0]) + ' items imported'
log(message)
no_items_in_batch = 0
client.batch.create_objects()
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/util.py 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.