Database / ChromaDB Interview Questions
What is the difference between ChromaDB's in-memory and persistent storage modes?
ChromaDB offers three client modes that control where data is stored. Choosing the right mode depends on whether you need data to survive restarts and whether you're running a single process or a shared service.
| Mode | Class | Data survives restart? | Best for |
|---|---|---|---|
| Ephemeral (in-memory) | chromadb.Client() | No — lost when process ends | Testing, prototyping, CI pipelines |
| Persistent (disk) | chromadb.PersistentClient(path=...) | Yes — written to SQLite + disk files | Single-process apps, local dev |
| HTTP Client | chromadb.HttpClient(host=..., port=...) | Yes — managed by server | Multi-process apps, production, shared access |
import chromadb
# 1. Ephemeral — data lives only in memory, lost on exit
client_mem = chromadb.Client()
# 2. Persistent — data saved to disk at ./my_chroma_db/
client_disk = chromadb.PersistentClient(path="./my_chroma_db")
# Creates the directory if it does not exist
# Data persists across Python restarts
# 3. HTTP Client — connects to a running ChromaDB server
client_http = chromadb.HttpClient(
host="localhost",
port=8000,
# ssl=True, headers={"Authorization": "Bearer token"} # if secured
)
# Start the server separately:
# chroma run --path ./chroma_data --port 8000
# Verify connection
client_http.heartbeat() # raises if server is unreachable
# EphemeralClient — explicit alias for chromadb.Client()
client_eph = chromadb.EphemeralClient()
# All three clients share the same collection API
collection = client_disk.get_or_create_collection("my_data")
collection.add(documents=["Persisted text"], ids=["p1"])
# Restart Python, create PersistentClient with same path → data still thereImportant: the persistent client uses SQLite under the hood. It is not designed for concurrent writes from multiple processes. For multi-process or multi-container production use, run ChromaDB as an HTTP server and use HttpClient.
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...
