Converts binary back to numpy array
(text)
| 28 | |
| 29 | |
| 30 | def convert_array(text): |
| 31 | """ |
| 32 | Converts binary back to numpy array |
| 33 | """ |
| 34 | if text is None: |
| 35 | return None |
| 36 | if isinstance(text, list): |
| 37 | return np.array(text, dtype=np.float32) |
| 38 | if isinstance(text, np.ndarray): |
| 39 | return text |
| 40 | |
| 41 | # Handle both bytes and sqlite3.Binary |
| 42 | binary_data = bytes(text) if isinstance(text, sqlite3.Binary) else text |
| 43 | |
| 44 | try: |
| 45 | # First decode base64 |
| 46 | decoded_data = base64.b64decode(binary_data) |
| 47 | # Then convert to numpy array |
| 48 | return np.frombuffer(decoded_data, dtype=np.float32) |
| 49 | except Exception: |
| 50 | return None |
| 51 | |
| 52 | |
| 53 | def verify_embedding_dimension(embedding: np.ndarray, expected_dim: int = MAX_EMBEDDING_DIM) -> bool: |
no outgoing calls
no test coverage detected