|
| 1 | +# Performance Tips |
| 2 | + |
| 3 | +This section covers tips and tricks of how to improve your Chroma performance. |
| 4 | + |
| 5 | +## Rebuild HNSW for your architecutre |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | + |
| 10 | +You can rebuild the HNSW index for the core package or the server as follows. |
| 11 | + |
| 12 | +=== "Core Package" |
| 13 | + |
| 14 | + To rebuild the HNSW index locally you may need to install build tooling such as `gcc` depending on your operating system. |
| 15 | + |
| 16 | + ```bash |
| 17 | + pip install --no-binary :all: chroma-hnswlib |
| 18 | + ``` |
| 19 | + |
| 20 | +=== "Server" |
| 21 | + |
| 22 | + 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`. |
| 23 | + |
| 24 | + ```bash |
| 25 | + git clone https://github.com/chroma-core/chroma.git && cd chroma |
| 26 | + docker build --build-arg REBUILD_HNSWLIB=true -t my-chroma-image:latest . |
| 27 | + ``` |
| 28 | + |
| 29 | +??? "Need help?" |
| 30 | + |
| 31 | + If you need help with the above steps, please reach out to us on [Discord](https://discord.gg/MMeYNTmh3x) (look for `@taz`) |
| 32 | + |
| 33 | +## Reducing (shortening) the dimensionality of your embeddings |
| 34 | + |
| 35 | +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. |
| 36 | + |
| 37 | +Currently the following embedding functions support this feature: |
| 38 | + |
| 39 | +- OpenAI with 3rd generation models (i.e. `text-embedding-3-small` and `text-embedding-3-large`) |
| 40 | + |
| 41 | + |
| 42 | +### OpenAI Example |
| 43 | + |
| 44 | +For more information on shortening embeddings see the official [OpenAI Blog post](https://openai.com/index/new-embedding-models-and-api-updates/). |
| 45 | + |
| 46 | +=== "Python" |
| 47 | + |
| 48 | + ```python |
| 49 | + from chromadb.utils.embedding_functions.openai_embedding_function import ( |
| 50 | + OpenAIEmbeddingFunction, |
| 51 | + ) |
| 52 | + import os |
| 53 | + |
| 54 | + ef = OpenAIEmbeddingFunction(api_key=os.environ["OPENAI_API_KEY"], model_name="text-embedding-3-small", dimensions=64) |
| 55 | + embeddings = ef(["hello world"]) |
| 56 | + ``` |
| 57 | + |
| 58 | +=== "Javascript" |
| 59 | + |
| 60 | + ```javascript |
| 61 | + |
| 62 | + import {OpenAIEmbeddingFunction} from "chromadb" |
| 63 | + |
| 64 | + const embedder = new OpenAIEmbeddingFunction({ |
| 65 | + openai_api_key: process.env.OPENAI_API_KEY, |
| 66 | + openai_embedding_dimensions: 64, |
| 67 | + openai_model: "text-embedding-3-small", |
| 68 | + }); |
| 69 | + const embeddings = embedder.generate(["hello world"]); |
| 70 | + ``` |
0 commit comments