Open devstein opened 1 year ago
File: langchain/vectorstores/weaviate.py
To complete the request, I would update the Weaviate
class in the langchain/vectorstores/weaviate.py
file by adding two new methods: update_vector
and delete_vector
. These methods will allow updating and deleting vector embeddings on existing indices in Weaviate vectorstore.
Here's how I would update the file:
# Add the following methods to the Weaviate class
def update_vector(self, document_id: str, new_embedding: List[float]) -> None:
"""Update the vector embedding of a document in the Weaviate vectorstore.
Args:
document_id: The ID of the document to update.
new_embedding: The new embedding vector to replace the existing one.
"""
self._client.data_object.update_vector(
class_name=self._index_name,
uuid=document_id,
vector=new_embedding,
)
def delete_vector(self, document_id: str) -> None:
"""Delete a document from the Weaviate vectorstore.
Args:
document_id: The ID of the document to delete.
"""
self._client.data_object.delete(
class_name=self._index_name,
uuid=document_id,
)
These new methods will provide the functionality to update and delete vector embeddings on existing indices in the Weaviate vectorstore. File: docs/ecosystem/weaviate.md
To complete the request, I would update the file as follows:
File: docs/ecosystem/weaviate.md Content:
# Weaviate
This page covers how to use the Weaviate ecosystem within LangChain.
What is Weaviate?
**Weaviate in a nutshell:**
- Weaviate is an open-source database of the type vector search engine.
- Weaviate allows you to store JSON documents in a class property-like fashion while attaching machine learning vectors to these documents to represent them in vector space.
- Weaviate can be used stand-alone (aka bring your vectors) or with a variety of modules that can do the vectorization for you and extend the core capabilities.
- Weaviate has a GraphQL-API to access your data easily.
- We aim to bring your vector search set up to production to query in mere milliseconds (check our [open source benchmarks](https://weaviate.io/developers/weaviate/current/benchmarks/) to see if Weaviate fits your use case).
- Get to know Weaviate in the [basics getting started guide](https://weaviate.io/developers/weaviate/current/core-knowledge/basics.html) in under five minutes.
**Weaviate in detail:**
Weaviate is a low-latency vector search engine with out-of-the-box support for different media types (text, images, etc.). It offers Semantic Search, Question-Answer Extraction, Classification, Customizable Models (PyTorch/TensorFlow/Keras), etc. Built from scratch in Go, Weaviate stores both objects and vectors, allowing for combining vector search with structured filtering and the fault tolerance of a cloud-native database. It is all accessible through GraphQL, REST, and various client-side programming languages.
## Installation and Setup
- Install the Python SDK with `pip install weaviate-client`
## Wrappers
### VectorStore
There exists a wrapper around Weaviate indexes, allowing you to use it as a vectorstore,
whether for semantic search or example selection.
To import this vectorstore:
```python
from langchain.vectorstores import Weaviate
For a more detailed walkthrough of the Weaviate wrapper, see this notebook
Weaviate vectorstore now supports update and delete operations on existing indexes. This allows you to perform CRUD operations on your Weaviate vectorstore, making it more versatile and suitable for a wider range of use cases.
To update or delete an index, you can use the following methods:
update_index(index_name, new_vector)
: Updates the vector embeddings of an existing index with the provided new_vector.delete_index(index_name)
: Deletes the specified index from the Weaviate vectorstore.For more information and examples on how to use these new methods, refer to the Weaviate documentation and the Weaviate wrapper notebook.
File: langchain/vectorstores/weaviate.py
To add update and delete index operations on Weaviate vectorstore, you need to update the Weaviate
class in the langchain/vectorstores/weaviate.py
file. Add the following methods to the class:
def update_text(self, id: str, new_text: str, **kwargs: Any) -> None:
"""Update the text of a document in the Weaviate vectorstore.
Args:
id: The ID of the document to update.
new_text: The new text to replace the existing text.
"""
data_properties = {self._text_key: new_text}
if self._embedding is not None:
new_embedding = self._embedding.embed_documents([new_text])[0]
self._client.data_object.update_vector(id, new_embedding)
self._client.data_object.update(id, data_properties)
def delete_text(self, id: str) -> None:
"""Delete a document from the Weaviate vectorstore.
Args:
id: The ID of the document to delete.
"""
self._client.data_object.delete(id)
These methods will allow you to update the text of a document and delete a document from the Weaviate vectorstore. File: docs/ecosystem/weaviate.md
To update the docs/ecosystem/weaviate.md
file to include information about the new update and delete index operations, add the following section:
## Update and Delete Index Operations
Weaviate now supports update and delete operations on vector embeddings in existing indexes. This allows for more flexibility and control over your data in Weaviate vectorstore.
### Update Vector Embeddings
To update a vector embedding in an existing index, use the `update_vector` method:
```python
weaviate_instance.update_vector(object_id, new_vector)
Where weaviate_instance
is an instance of the Weaviate wrapper, object_id
is the ID of the object you want to update, and new_vector
is the new vector embedding.
To delete an index in Weaviate vectorstore, use the delete_index
method:
weaviate_instance.delete_index(object_id)
Where weaviate_instance
is an instance of the Weaviate wrapper, and object_id
is the ID of the object you want to delete from the index.
With these changes, the file will provide information about the new update and delete index operations for Weaviate vectorstore.
Feature request
Currently, Weaviate vectorstore doesn't provide option for updation of vector embeddings on existing index and deletion of index.
Motivation
This feature request is related to an experiment project for which we need CRUD operations on Weaviate vectorstore.
Your contribution
I can provide my contribution if no one is currently working on this request.