Update an object through LangChain

Description

I’m trying to find if it’s possible to update an object through the WeaviateVectorStore module.

U can use WeaviateVectorStore to add documents and initiate a connection to a collection but I can’t find if there’s any way to update some object inside of a collection.

It seems weird that langchain would limit you to just adding objects and then force you to use the native weaviate solution to update an object.

Server Setup Information

  • Weaviate Server Version: 0.4
  • Deployment Method: docker
  • Client Language and Version: Python

hi @Troligen !!

Welcome to our community :hugs:

You need to pass the uuid to that doc as the id parameter

Here is a code example in python:

from weaviate.util import generate_uuid5
from langchain_weaviate.vectorstores import WeaviateVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain.docstore.document import Document


embeddings = OpenAIEmbeddings()
doc =  Document(page_content="text1", metadata={"source": "local"}, id=generate_uuid5("my-id"))
db = WeaviateVectorStore.from_documents([doc], embeddings, client=client, index_name="Test")

now we can check our doc:

client.collections.get("Test").query.fetch_objects().objects[0].properties
# {'text': 'text1', 'source': 'local'}

Let’s update that object

doc =  Document(page_content="text1_changed", metadata={"source": "local"}, id=generate_uuid5("my-id"))
db = WeaviateVectorStore.from_documents([doc], embeddings, 
client=client, index_name="Test")

We have updated!

client.collections.get("Test").query.fetch_objects().objects[0].properties
# {'text': 'text1_changed', 'source': 'local'}

Let me know if this helps!

Thanks!

Thanks you for your warm welcome and thank you for the solution!

I see you’re using the deterministic ID which seems to make the handling of the updates more streamlined as well?

In any case thank you for the help!

Best Regards,
Jesper/Troligen