Quantcast
Channel: Weaviate Community Forum - Latest posts
Viewing all articles
Browse latest Browse all 3588

Update an object through LangChain

$
0
0

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!


Viewing all articles
Browse latest Browse all 3588

Trending Articles