# Fix for `update_document` Function in Chroma
## Summary
This pull request addresses an issue with the `update_document` function
in the Chroma class, as described in
[#5031](https://github.com/hwchase17/langchain/issues/5031#issuecomment-1562577947).
The issue was identified as an `AttributeError` raised when calling
`update_document` due to a missing corresponding method in the
`Collection` object. This fix refactors the `update_document` method in
`Chroma` to correctly interact with the `Collection` object.
## Changes
1. Fixed the `update_document` method in the `Chroma` class to correctly
call methods on the `Collection` object.
2. Added the corresponding test `test_chroma_update_document` in
`tests/integration_tests/vectorstores/test_chroma.py` to reflect the
updated method call.
3. Added an example and explanation of how to use the `update_document`
function in the Jupyter notebook tutorial for Chroma.
## Test Plan
All existing tests pass after this change. In addition, the
`test_chroma_update_document` test case now correctly checks the
functionality of `update_document`, ensuring that the function works as
expected and updates the content of documents correctly.
## Reviewers
@dev2049
This fix will ensure that users are able to use the `update_document`
function as expected, without encountering the previous
`AttributeError`. This will enhance the usability and reliability of the
Chroma class for all users.
Thank you for considering this pull request. I look forward to your
feedback and suggestions.
"The `update_document` function allows you to modify the content of a document in the Chroma instance after it has been added. Let's see an example of how to use this function."
"# Initialize a Chroma instance with the original document\n",
"new_db = Chroma.from_documents(\n",
" collection_name=\"test_collection\",\n",
" documents=[original_doc],\n",
" embedding=OpenAIEmbeddings(), # using the same embeddings as before\n",
" ids=[document_id],\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "60a7c273",
"metadata": {},
"source": [
"At this point, we have a new Chroma instance with a single document \"This is an initial document content\" with id \"doc1\". Now, let's update the content of the document."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "55e48056",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the updated document content {'page': '1'}\n"
]
}
],
"source": [
"# Updated document content\n",
"updated_content = \"This is the updated document content\"\n",
"\n",
"# Create a new Document instance with the updated content\n",