mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 11:39:18 +00:00
feat(chroma): Add support for collection forking (#32627)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
"\n",
|
||||
"This notebook covers how to get started with the `Chroma` vector store.\n",
|
||||
"\n",
|
||||
">[Chroma](https://docs.trychroma.com/getting-started) is a AI-native open-source vector database focused on developer productivity and happiness. Chroma is licensed under Apache 2.0. View the full docs of `Chroma` at [this page](https://docs.trychroma.com/reference/py-collection), and find the API reference for the LangChain integration at [this page](https://python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html).\n",
|
||||
">[Chroma](https://docs.trychroma.com/getting-started) is a AI-native open-source vector database focused on developer productivity and happiness. Chroma is licensed under Apache 2.0. View the full docs of `Chroma` at [this page](https://docs.trychroma.com/integrations/frameworks/langchain), and find the API reference for the LangChain integration at [this page](https://python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html).\n",
|
||||
"\n",
|
||||
":::info Chroma Cloud\n",
|
||||
"\n",
|
||||
@@ -522,6 +522,39 @@
|
||||
"vector_store.delete(ids=uuids[-1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "675b3708-b5ef-4298-b950-eac27096b456",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Fork a vector store\n",
|
||||
"\n",
|
||||
"Forking lets you create a new `Chroma` vector store from an existing one instantly, using copy-on-write under the hood. This means that your new `Chroma` store is identical to the origin, but any modifications to it will not affect the origin, and vice-versa.\n",
|
||||
"\n",
|
||||
"Forks are great for any use case that benefits from data versioning. You can learn more about forking in the [Chroma docs](https://docs.trychroma.com/cloud/collection-forking).\n",
|
||||
"\n",
|
||||
"Note: Forking is only avaiable on `Chroma` instances with a Chroma Cloud connection."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e08a0c79-4d2a-49ff-be63-d8591c268764",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"forked_store = vector_store.fork(new_name=\"my_forked_collection\")\n",
|
||||
"\n",
|
||||
"updated_document_2 = Document(\n",
|
||||
" page_content=\"The weather forecast for tomorrow is extrmeley hot, with a high of 100 degrees.\",\n",
|
||||
" metadata={\"source\": \"news\"},\n",
|
||||
" id=2,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Update does not affect 'vector_store'\n",
|
||||
"forked_store.update(ids=[\"2\"], documents=[updated_document_2])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "213acf08",
|
||||
@@ -609,7 +642,7 @@
|
||||
"source": [
|
||||
"#### Other search methods\n",
|
||||
"\n",
|
||||
"There are a variety of other search methods that are not covered in this notebook, such as MMR search or searching by vector. For a full list of the search abilities available for `AstraDBVectorStore` check out the [API reference](https://python.langchain.com/api_reference/astradb/vectorstores/langchain_astradb.vectorstores.AstraDBVectorStore.html).\n",
|
||||
"There are a variety of other search methods that are not covered in this notebook. For a full list of the search abilities available for `Chroma` check out the [API reference](https://python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html).\n",
|
||||
"\n",
|
||||
"### Query by turning into retriever\n",
|
||||
"\n",
|
||||
@@ -670,7 +703,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.0"
|
||||
"version": "3.13.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
@@ -485,6 +485,23 @@ class Chroma(VectorStore):
|
||||
with open(uri, "rb") as image_file:
|
||||
return base64.b64encode(image_file.read()).decode("utf-8")
|
||||
|
||||
def fork(self, new_name: str) -> Chroma:
|
||||
"""Fork this vector store.
|
||||
|
||||
Args:
|
||||
new_name: New name for the forked store.
|
||||
|
||||
Returns:
|
||||
A new Chroma store forked from this vector store.
|
||||
|
||||
"""
|
||||
forked_collection = self._collection.fork(new_name=new_name)
|
||||
return Chroma(
|
||||
client=self._client,
|
||||
embedding_function=self._embedding_function,
|
||||
collection_name=forked_collection.name,
|
||||
)
|
||||
|
||||
def add_images(
|
||||
self,
|
||||
uris: list[str],
|
||||
|
Reference in New Issue
Block a user