How to enforce a field to be unique?

I want to avoid duplicates. For that reason, I want to enforce one of the fields to be unique. How can I do this?

1 Like

Hi @jpiabrantes -

The only unique field in Weaviate currently is the uuid. So, one way you could do that is to generate your object ID based on your desired unique field.

If you wanted to do that with the title, you can try:

from weaviate.util import generate_uuid5

class_name = "YourClassName"  # Replace with your class name
data_objs = [
    {"title": f"Object {i+1}"} for i in range(5)  # Replace with your actual objects
with client.batch() as batch:
    for data_obj in data_objs:
1 Like