def _resolve_session(
        self,
        session: Optional[Session] = None,
        cassio_init_kwargs: Optional[Dict[str, Any]] = None,
    ) -> Session:
        """
        Attempts to resolve and return a Session object for use in database operations.

        This function follows a specific order of precedence to determine the
        appropriate session to use:
        1. `session` parameter if given,
        2. Existing `cassio` session,
        3. A new `cassio` session derived from `cassio_init_kwargs`,
        4. `None`

        Parameters
        ----------
        - session (Optional[Session]): An optional session to use directly.
        - cassio_init_kwargs (Optional[Dict[str, Any]]): An optional dictionary of
          keyword arguments to `cassio`.

        Returns
        -------
        - Session: The resolved session object if successful, or `None` if the session
          cannot be resolved.

        Raises
        ------
        - ValueError: If `cassio_init_kwargs` is provided but is not a dictionary of
          keyword arguments.

        """
        # Prefer given session
        if session:
            return session

        # If a session is not provided, create one using cassio if available
        # dynamically import cassio to avoid circular imports
        try:
            import cassio.config
        except ImportError:
            raise ValueError(
                "cassio package not found, please install with `pip install cassio`"
            )

        # Use pre-existing session on cassio
        s = cassio.config.resolve_session()
        if s:
            return s

        # Try to init and return cassio session
        if cassio_init_kwargs:
            if isinstance(cassio_init_kwargs, dict):
                cassio.init(**cassio_init_kwargs)
                return cassio.config.check_resolve_session()
            else:
                raise ValueError("cassio_init_kwargs must be a keyword dictionary")

        # return None if we're not able to resolve
        return None

        Attempts to resolve and return a Session object for use in database operations.

        This function follows a specific order of precedence to determine the
        appropriate session to use:
        1. `session` parameter if given,
        2. Existing `cassio` session,
        3. A new `cassio` session derived from `cassio_init_kwargs`,
        4. `None`

        Parameters
        ----------
        - session (Optional[Session]): An optional session to use directly.
        - cassio_init_kwargs (Optional[Dict[str, Any]]): An optional dictionary of
          keyword arguments to `cassio`.

        Returns
        -------
        - Session: The resolved session object if successful, or `None` if the session
          cannot be resolved.

        Raises
        ------
        - ValueError: If `cassio_init_kwargs` is provided but is not a dictionary of
          keyword arguments.

        
llama-index-integrations/tools/llama-index-tools-cassandra/llama_index/tools/cassandra/cassandra_database_wrapper.py