| 55 | |
| 56 | |
| 57 | def generate_perturbation( |
| 58 | base_vector: dict, id: int, perturbation_degree: float |
| 59 | ) -> dict: |
| 60 | perturbation = np.random.uniform( |
| 61 | -perturbation_degree, perturbation_degree, len(base_vector["dense_values"]) |
| 62 | ) |
| 63 | perturbed_values = np.array(base_vector["dense_values"]) + perturbation |
| 64 | clamped_values = np.clip(perturbed_values, -1, 1) |
| 65 | return { |
| 66 | "id": f"vec_{id}", |
| 67 | "dense_values": clamped_values.tolist(), |
| 68 | "document_id": f"doc_{id // 10}", # Group vectors into documents |
| 69 | } |
| 70 | |
| 71 | |
| 72 | def generate_batch( |