refactor: streamline collection handling in RAGStorage (#3097)

Replaced the try-except block for collection retrieval with a single call to get_or_create_collection, simplifying the code and improving readability. Added logging to confirm whether the collection was found or created.
This commit is contained in:
Lorenze Jay
2025-07-01 10:14:39 -07:00
committed by GitHub
parent 49c0144154
commit e544ff8ba3

View File

@@ -71,14 +71,10 @@ class RAGStorage(BaseRAGStorage):
self.app = chroma_client
try:
self.collection = self.app.get_collection(
name=self.type, embedding_function=self.embedder_config
)
except Exception:
self.collection = self.app.create_collection(
name=self.type, embedding_function=self.embedder_config
)
self.collection = self.app.get_or_create_collection(
name=self.type, embedding_function=self.embedder_config
)
logging.info(f"Collection found or created: {self.collection}")
def _sanitize_role(self, role: str) -> str:
"""