Skip to content

Commit

Permalink
feat: Performance tips (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
tazarov authored Oct 26, 2024
1 parent 9f94c32 commit 3c3fbc7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ This is a collection of small guides and recipes to help you get started with Ch

If you are using Chroma `>=0.5.7` and `<=0.5.13` please upgrade to `0.5.13` as there is a critical bug that can cause data loss. Read more on the [GH Issue #2922](https://github.com/chroma-core/chroma/issues/2922).

Latest ChromaDB version: [0.5.13](https://github.com/chroma-core/chroma/releases/tag/0.5.13)
Latest ChromaDB version: [0.5.15](https://github.com/chroma-core/chroma/releases/tag/0.5.15)


## New and Noteworthy

- 🏎️ [Performance Tips](running/performance-tips.md) - Learn how to optimize the performance of yourChroma - 📅`16-Oct-2024`
- ⁉️[FAQs](faq/index.md) - Updated FAQ sections - 📅`15-Oct-2024`
- 🔥 [SSL-Terminating Proxies](security/ssl-proxies.md) - Learn how to secure Chroma server with `Envoy` or `Nginx` proxies - 📅`31-Jul-2024`
- 🗑️ [WAL Pruning](core/advanced/wal-pruning.md#chroma-cli) - Learn how to prune (cleanup) your Chroma database (WAL) with Chroma's built-in CLI `vacuum` command - 📅`30-Jul-2024`
Expand Down
70 changes: 70 additions & 0 deletions docs/running/performance-tips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Performance Tips

This section covers tips and tricks of how to improve your Chroma performance.

## Rebuild HNSW for your architecutre

Single node chroma [core package](https://pypi.org/project/chromadb/) and [server](https://hub.docker.com/r/chromadb/chroma) ship with a default HNSW build which is optimized for maximum compatibility. The default HNSW does not make use of available optimization for your CPU architecture such as SIMD/AVX.


You can rebuild the HNSW index for the core package or the server as follows.

=== "Core Package"

To rebuild the HNSW index locally you may need to install build tooling such as `gcc` depending on your operating system.

```bash
pip install --no-binary :all: chroma-hnswlib
```

=== "Server"

In the following snippet, we clone the Chroma repository (you'll need git and docker installed), and then build a new docker image with the HNSW rebuild flag set to `true`.

```bash
git clone https://github.com/chroma-core/chroma.git && cd chroma
docker build --build-arg REBUILD_HNSWLIB=true -t my-chroma-image:latest .
```

??? "Need help?"

If you need help with the above steps, please reach out to us on [Discord](https://discord.gg/MMeYNTmh3x) (look for `@taz`)

## Reducing (shortening) the dimensionality of your embeddings

Some embeddings models (or APIs) offer the ability to reduce the dimensionality of the resulting embeddings. This is a great way to reduce the storage and memory requirements of your Chroma.

Currently the following embedding functions support this feature:

- OpenAI with 3rd generation models (i.e. `text-embedding-3-small` and `text-embedding-3-large`)


### OpenAI Example

For more information on shortening embeddings see the official [OpenAI Blog post](https://openai.com/index/new-embedding-models-and-api-updates/).

=== "Python"

```python
from chromadb.utils.embedding_functions.openai_embedding_function import (
OpenAIEmbeddingFunction,
)
import os

ef = OpenAIEmbeddingFunction(api_key=os.environ["OPENAI_API_KEY"], model_name="text-embedding-3-small", dimensions=64)
embeddings = ef(["hello world"])
```

=== "Javascript"

```javascript

import {OpenAIEmbeddingFunction} from "chromadb"

const embedder = new OpenAIEmbeddingFunction({
openai_api_key: process.env.OPENAI_API_KEY,
openai_embedding_dimensions: 64,
openai_model: "text-embedding-3-small",
});
const embeddings = embedder.generate(["hello world"]);
```

0 comments on commit 3c3fbc7

Please sign in to comment.