"In this basic example, we take the a Paul Graham essay, split it into chunks, embed it using an open-source embedding model, load it into Chroma, and then query it."
"In this basic example, we take the Paul Graham essay, split it into chunks, embed it using an open-source embedding model, load it into Chroma, and then query it."
]
},
{
...
...
%% Cell type:markdown id:0af3ec93 tags:
<ahref="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/vector_stores/ChromaIndexDemo.ipynb"target="_parent"><imgsrc="https://colab.research.google.com/assets/colab-badge.svg"alt="Open In Colab"/></a>
>[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.
Chroma is fully-typed, fully-tested and fully-documented.
Install Chroma with:
```sh
pip install chromadb
```
Chroma runs in various modes. See below for examples of each integrated with LangChain.
-`in-memory` - in a python script or jupyter notebook
-`in-memory with persistance` - in a script or notebook and save/load to disk
-`in a docker container` - as a server running your local machine or in the cloud
Like any other database, you can:
-`.add`
-`.get`
-`.update`
-`.upsert`
-`.delete`
-`.peek`
- and `.query` runs the similarity search.
View full docs at [docs](https://docs.trychroma.com/reference/Collection).
%% Cell type:markdown id:b5331b6b tags:
## Basic Example
In this basic example, we take the a Paul Graham essay, split it into chunks, embed it using an open-source embedding model, load it into Chroma, and then query it.
In this basic example, we take the Paul Graham essay, split it into chunks, embed it using an open-source embedding model, load it into Chroma, and then query it.
%% Cell type:markdown id:54361467 tags:
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
response=query_engine.query("What did the author do growing up?")
display(Markdown(f"<b>{response}</b>"))
```
%% Output
/Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
/Users/loganmarkewich/llama_index/llama-index/lib/python3.9/site-packages/bitsandbytes/cextension.py:34: UserWarning: The installed version of bitsandbytes was compiled without GPU support. 8-bit optimizers, 8-bit multiplication, and GPU quantization are unavailable.
warn("The installed version of bitsandbytes was compiled without GPU support. "
'NoneType' object has no attribute 'cadam32bit_grad_fp32'
<b>The author worked on writing and programming growing up. They wrote short stories and tried writing programs on an IBM 1401 computer. Later, they got a microcomputer and started programming more extensively.</b>
%% Cell type:markdown id:349de571 tags:
## Basic Example (including saving to disk)
Extending the previous example, if you want to save to disk, simply initialize the Chroma client and pass the directory where you want the data to be saved to.
`Caution`: Chroma makes a best-effort to automatically save data to disk, however multiple in-memory clients can stomp each other's work. As a best practice, only have one client per path running at any given time.
response=query_engine.query("What did the author do growing up?")
display(Markdown(f"<b>{response}</b>"))
```
%% Output
<b>The author worked on writing and programming growing up. They wrote short stories and tried writing programs on an IBM 1401 computer. Later, they got a microcomputer and started programming games and a word processor.</b>
%% Cell type:markdown id:d596e475 tags:
## Basic Example (using the Docker Container)
You can also run the Chroma Server in a Docker container separately, create a Client to connect to it, and then pass that to LlamaIndex.
Here is how to clone, build, and run the Docker Image:
response=query_engine.query("What did the author do growing up?")
display(Markdown(f"<b>{response}</b>"))
```
%% Output
<b>
Growing up, the author wrote short stories, programmed on an IBM 1401, and wrote programs on a TRS-80 microcomputer. He also took painting classes at Harvard and worked as a de facto studio assistant for a painter. He also tried to start a company to put art galleries online, and wrote software to build online stores.</b>
%% Cell type:markdown id:0a0e79f7 tags:
## Update and Delete
While building toward a real application, you want to go beyond adding data, and also update and delete data.
Chroma has users provide `ids` to simplify the bookkeeping here. `ids` can be the name of the file, or a combined has like `filename_paragraphNumber`, etc.
Here is a basic example showing how to do various operations: