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 there
Important: 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.
More Related questions...