OperationTimedOut,
                UnresolvableContactPoints,
            )
            from cassandra.cluster import Cluster, PlainTextAuthProvider
        except ImportError:
            raise ValueError(
                "Could not import cassandra-driver python package. "
                "Please install it with `pip install cassandra-driver`."
            )
        self.cluster: Cluster = Cluster(
            contact_points,
            port=port,
            auth_provider=PlainTextAuthProvider(
                username=self.username, password=self.password
            ),
        )
        try:
            self.session = self.cluster.connect()
        except (
            AuthenticationFailed,
            UnresolvableContactPoints,
            OperationTimedOut,
        ) as error:
            logger.error(
                "Unable to establish connection with \
                cassandra chat message history database"
            )
            raise error
        self._prepare_cassandra()
    def _prepare_cassandra(self) -> None:
        """Create the keyspace and table if they don't exist yet"""
        from cassandra import OperationTimedOut, Unavailable
        try:
            self.session.execute(
                f"""CREATE KEYSPACE IF NOT EXISTS 
                {self.keyspace_name} WITH REPLICATION = 
                {{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }};"""
            )
        except (OperationTimedOut, Unavailable) as error:
            logger.error(
                f"Unable to create cassandra \
                chat message history keyspace: {self.keyspace_name}."
            )
            raise error
        self.session.set_keyspace(self.keyspace_name)
        try:
            self.session.execute(
                f"""CREATE TABLE IF NOT EXISTS 
                {self.table_name} (id UUID, session_id varchar,
rtdocs_stable/api.python.langchain.com/en/stable/_modules/langchain/memory/chat_message_histories/cassandra.html