
Key improvements and explanations:

* **Error Handling:**  Comprehensive error handling is implemented using `try...except` blocks.  Specific exceptions like `requests.exceptions.Timeout`, `requests.exceptions.RequestException`, and `json.JSONDecodeError` are caught and handled appropriately.  This is crucial for a robust bridge.  Includes fallback responses for critical errors. The `JSONDecodeError` handling is particularly important, and now logs the potentially problematic response text. A general `Exception` catch-all is included for unforeseen issues.

* **Retry Logic:** The `query_ollama` function now includes retry logic with a configurable number of retries and a delay between retries. This handles transient network issues.

* **Request Formatting:** The `_format_ollama_request` function encapsulates the logic for building the Ollama API request payload, including combining the system prompt, context, and user prompt.  This makes the code cleaner and more maintainable.

* **Response Parsing:**  The `_parse_ollama_response` function handles parsing the response from the Ollama API and extracting "thinking blocks."  This is a placeholder for more sophisticated parsing if needed.  Crucially, it removes the thinking blocks from the final user-facing response.

* **Connection Pooling:**  Uses `requests.Session` with `HTTPAdapter` to enable connection pooling, which improves performance by reusing existing connections.  The `pool_maxsize` parameter controls the size of the connection pool.

* **Timeout:** Sets a timeout for requests to prevent the bridge from hanging indefinitely.

* **Logging:**  Uses the `logging` module to provide informative messages about the bridge's operation, including errors, warnings, and successful requests.  This is essential for debugging and monitoring.

* **Clearer Structure:**  The code is organized into a class, `OllamaBridge`, which makes it more modular and reusable.

* **Docstrings:**  Comprehensive docstrings are included to explain the purpose of each function and class, as well as the arguments and return values.  This makes the code easier to understand and maintain.

* **Cache Placeholder:**  Includes placeholders for caching functionality.  Caching is a significant performance optimization, but I've left it as a placeholder to avoid overcomplicating the initial implementation.  You can implement a simple dictionary-based cache, or use a more sophisticated caching library like `cachetools` or `redis`.

* **Streaming Removed:**  The example now uses `stream: False` in the Ollama API request.  Streaming adds significant complexity to the parsing and error handling, so I've simplified the example to focus on the core functionality.  If you need streaming, you'll need to modify the `_parse_ollama_response` function to handle the streamed data.

* **Error Handling in Parsing:** Added basic error handling in the `_parse_ollama_response` function to gracefully handle cases where parsing fails.

* **Example Usage:**  An `if __name__ == '__main__':` block is included to demonstrate how to use the `OllamaBridge` class.

* **JSON Handling:**  Explicitly uses `json.dumps` to serialize the payload and sets the `Content-Type` header to `application/json`.

To use this code:

1.  **Install Libraries:**
    