diff --git a/libs/langchain/langchain/vectorstores/weaviate.py b/libs/langchain/langchain/vectorstores/weaviate.py index 85b060a54d..341a3a4d56 100644 --- a/libs/langchain/langchain/vectorstores/weaviate.py +++ b/libs/langchain/langchain/vectorstores/weaviate.py @@ -467,6 +467,13 @@ class Weaviate(VectorStore): embeddings = embedding.embed_documents(texts) if embedding else None attributes = list(metadatas[0].keys()) if metadatas else None + # If the UUID of one of the objects already exists + # then the existing object will be replaced by the new object. + if "uuids" in kwargs: + uuids = kwargs.pop("uuids") + else: + uuids = [get_valid_uuid(uuid4()) for _ in range(len(texts))] + with client.batch as batch: for i, text in enumerate(texts): data_properties = { @@ -476,12 +483,7 @@ class Weaviate(VectorStore): for key in metadatas[i].keys(): data_properties[key] = metadatas[i][key] - # If the UUID of one of the objects already exists - # then the existing objectwill be replaced by the new object. - if "uuids" in kwargs: - _id = kwargs["uuids"][i] - else: - _id = get_valid_uuid(uuid4()) + _id = uuids[i] # if an embedding strategy is not provided, we let # weaviate create the embedding. Note that this will only