← Journal
Use a Vector Database Instead of a Search Engine: Running Chroma

Use a Vector Database Instead of a Search Engine: Running Chroma

A record of running Chroma, a database for storing and searching embedding vectors, with the network disconnected. It retrieved notes with similar meanings even when the queries used different wording.

Repository covered in this article

chroma-core/chroma

Search infrastructure for AI

28.8k Rust Apache License 2.0

Making internal notes or tickets searchable can lead you to build a search engine for each use case. Chroma is a lightweight database built for storing and searching embedding vectors, and you can embed it in an application. I installed it and tested semantic search with the network disconnected.

Chroma converts documents into embedding vectors, stores them, and returns results ordered by distance from the query. The Chroma project uses the Apache 2.0 License (*1).

1. Install it

Fetch the default ONNX embedding model during the build, while the network is available.

FROM docker.io/library/python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'chromadb==1.5.9'
COPY warmup_model.py /tmp/warmup_model.py
RUN python /tmp/warmup_model.py
WORKDIR /work
# warmup_model.py
import chromadb

client = chromadb.Client()
collection = client.create_collection("warmup")
collection.add(documents=["warm up"], ids=["1"])
print("warmup ok")
podman build -t chromadb-sandbox .

2. Search with differently worded queries

I registered four short notes and searched with a query that shared almost no words with any of them. Run the command with the network disconnected.

import chromadb

client = chromadb.PersistentClient(path="/work/chroma_db")
collection = client.get_or_create_collection("notes")

collection.add(
    documents=[
        "The invoice was rejected because the tax ID field was empty.",
        "Restart the router if the wifi light stays orange for more than a minute.",
        "The payment failed validation due to a missing tax identifier.",
        "Water the tomato plants every morning before the sun gets strong.",
    ],
    ids=["doc1", "doc2", "doc3", "doc4"],
)

query = "billing rejected, tax number missing"
results = collection.query(query_texts=[query], n_results=2)
for doc, dist in zip(results["documents"][0], results["distances"][0]):
    print(f"distance={dist:.4f}  {doc}")
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work chromadb-sandbox \
  python search_demo.py

The -v option makes the specified directory readable and writable from the container. Use an empty directory for this experiment. PersistentClient keeps data as files on disk, so do not place existing database files containing real data in the mount point.

The command produced the following output.

QUERY: billing rejected, tax number missing

distance=0.6248  The payment failed validation due to a missing tax identifier.
distance=0.6592  The invoice was rejected because the tax ID field was empty.

The query's words (billing, rejected, tax, number, missing) do not form an exact match for any sentence in the four notes. The two tax and billing notes ranked highest, and Chroma excluded the notes about Wi-Fi and watering tomatoes. Chroma ranked documents by vector distance alone, and the two notes with related meanings took the top positions.

Put search inside the application

You can store and search embedding vectors inside an application without building or operating an external search service. Chroma persists data as files on disk, so this setup is enough for small-scale note and FAQ search.

Sources

*1 Chroma (GitHub), https://github.com/chroma-core/chroma, Apache 2.0 License