Database / ChromaDB Interview Questions
How do you inspect a ChromaDB collection's contents and configuration?
ChromaDB provides several methods to examine what is stored in a collection — useful for debugging, verifying ingestion, and monitoring collection health.
import chromadb client = chromadb.PersistentClient(path="./inspect_demo") col = client.get_or_create_collection( "articles", metadata={"hnsw:space": "cosine"}, ) col.add( documents=[f"Article {i} about topic {i%3}" for i in range(20)], metadatas=[{"topic": i%3, "idx": i} for i in range(20)], ids=[f"art-{i}" for i in range(20)], ) # 1. Count documents print(col.count()) # 20 # 2. Peek â quick look at first n items (default n=10) peek = col.peek(limit=5) print(peek["ids"]) # first 5 IDs print(peek["documents"]) # first 5 documents # 3. Get all (careful with large collections!) all_items = col.get() print(len(all_items["ids"])) # 20 # 4. Get a page of results (offset-based) page = col.get( limit=5, offset=10, # skip first 10 ) print(page["ids"]) # art-10 through art-14 # 5. Inspect collection metadata and config print(col.name) # "articles" print(col.id) # UUID print(col.metadata) # {"hnsw:space": "cosine"} # 6. List all collections for c in client.list_collections(): print(c) # prints collection name # 7. Check if a document exists by ID result = col.get(ids=["art-5"]) if result["ids"]: print("Found:", result["documents"][0]) else: print("Not found")
| Method / Property | Purpose |
|---|---|
| collection.count() | Number of documents stored |
| collection.peek(limit=10) | Quick sample of first N items |
| collection.get() | Retrieve all items (paginate large collections) |
| collection.get(limit=N, offset=M) | Paginate through collection |
| collection.name | Collection name string |
| collection.metadata | Dict of collection settings (hnsw:space etc.) |
| client.list_collections() | Names of all collections |
More Related questions...