33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
"""
|
|
Utilities module for the application.
|
|
Contains helper functions and utilities for the application.
|
|
"""
|
|
import importlib
|
|
import sys
|
|
import numpy as np
|
|
|
|
def patch_chromadb_numpy():
|
|
"""
|
|
Patch ChromaDB to use np.nan instead of np.NaN for NumPy 2.0 compatibility.
|
|
|
|
This function uses monkey patching to replace the old np.NaN reference in the
|
|
brute_force_index.py file of ChromaDB with the new np.nan (lowercase).
|
|
"""
|
|
try:
|
|
# Get the module where the error occurs
|
|
from chromadb.segment.impl.vector import brute_force_index
|
|
|
|
# Patch the module to use np.nan instead of np.NaN
|
|
if not hasattr(np, 'NaN'):
|
|
np.NaN = np.nan
|
|
|
|
print("NumPy compatibility patch applied for ChromaDB")
|
|
return True
|
|
except ImportError:
|
|
print("Could not patch ChromaDB: module not found")
|
|
return False
|
|
except Exception as e:
|
|
print(f"Error patching ChromaDB: {e}")
|
|
return False
|
|
|
|
# This module will be populated with utility functions in later steps |