One collection per role
We could put every document in one collection and filter by a role metadata field. It works until someone forgets the filter, and then every query sees every doc. Separate collections make that forgetfulness safe: if you pick the wrong collection you get zero results, never someone else's data.
def _init_collections(self) -> None:
for role in ROLES:
name = f"{role}_docs"
try:
self.collections[role] = self.chroma_client.get_collection(
name=name,
embedding_function=self.embedding_function,
)
except (NotFoundError, ValueError):
self.collections[role] = self.chroma_client.create_collection(
name=name,
embedding_function=self.embedding_function,
)
Three roles, three named collections, all persisted in the same ChromaDB client. The collection name is the wall. The same class also exposes a list_documents(role) helper that returns every doc name in a collection, your first stop whenever retrieval looks wrong.
Scoped retrieval in one picture
The search function picks the collection by role. There is no cross-collection query path.
Quiz: Quiz
Loading practice…