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 |
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...
