JonahWhaler / llm-agent-toolkit

LLM AgeToolkit provides minimal, modular interfaces for core components in LLM-based applications.
GNU General Public License v3.0
0 stars 0 forks source link

7 get collection force program to terminate when the desired collection is not found #8

Closed JonahWhaler closed 4 days ago

JonahWhaler commented 4 days ago
overwrite: bool = kwargs.get("overwrite", False)
if overwrite:
    try:
        self.vdb.delete_collection(name=self.__namespace)
        # delete_collection raises InvalidCollectionException
        # if attempt to delete non-exists collection
    except (chromadb.errors.InvalidCollectionException, ValueError):
        pass  # self.__namespace is not found in the vector database
    finally:
        self.vdb.create_collection(
            name=self.__namespace, metadata={"hnsw:space": "cosine"}
        )
else:
    # Create collection if not already present
    self.vdb.get_or_create_collection(
       name=self.__namespace, metadata={"hnsw:space": "cosine"}
    )