Database / ChromaDB Interview Questions
How do you run ChromaDB as a standalone HTTP server and connect to it from multiple clients?
For production or multi-process environments, run ChromaDB as a persistent HTTP server and connect all clients via chromadb.HttpClient(). This removes the single-writer SQLite limitation and allows any number of clients — including different languages — to share the same database.
# --- SERVER SIDE ---
# Install: pip install chromadb
# Start the server from the command line:
# chroma run --path ./chroma_data --port 8000 --host 0.0.0.0
# Or run programmatically (e.g. in tests):
import chromadb
from chromadb.config import Settings
# --- CLIENT SIDE ---
client = chromadb.HttpClient(
host="localhost",
port=8000,
)
# Verify server is reachable
client.heartbeat() # raises ConnectionError if server is down
# Usage is identical to PersistentClient
collection = client.get_or_create_collection(
"shared_docs",
metadata={"hnsw:space": "cosine"},
)
collection.add(
documents=["Shared document from client 1"],
ids=["s1"],
)
results = collection.query(query_texts=["shared content"], n_results=1)
print(results["documents"])
# With authentication (chromadb server configured with auth)
client_auth = chromadb.HttpClient(
host="my-server.example.com",
port=443,
ssl=True,
headers={"Authorization": "Bearer my-token"},
)# docker-compose.yml — containerised ChromaDB server
# version: "3.9"
# services:
# chromadb:
# image: chromadb/chroma:latest
# ports:
# - "8000:8000"
# volumes:
# - chroma_data:/chroma/chroma
# environment:
# - IS_PERSISTENT=TRUE
# - ANONYMIZED_TELEMETRY=FALSE
# volumes:
# chroma_data:| Mode | Concurrency | Network | Use case |
|---|---|---|---|
| EphemeralClient | Single process only | None | Tests, notebooks |
| PersistentClient | Single writer only | None | Local scripts, dev |
| HttpClient | Multiple clients | HTTP/HTTPS | Production, microservices |
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
