(base_vector, idd, perturbation_degree, dimensions)
| 219 | |
| 220 | |
| 221 | def generate_perturbation(base_vector, idd, perturbation_degree, dimensions): |
| 222 | # Generate the perturbation |
| 223 | perturbation = np.random.uniform( |
| 224 | -perturbation_degree, perturbation_degree, dimensions |
| 225 | ) |
| 226 | |
| 227 | # Apply the perturbation and clamp the values within the range of -1 to 1 |
| 228 | # perturbed_values = base_vector["values"] + perturbation |
| 229 | perturbed_values = np.array(base_vector["values"]) + perturbation |
| 230 | clamped_values = np.clip(perturbed_values, -1, 1) |
| 231 | |
| 232 | perturbed_vector = {"id": idd, "values": clamped_values.tolist()} |
| 233 | # print(base_vector["values"][:10]) |
| 234 | # print( perturbed_vector["values"][:10] ) |
| 235 | # cs = cosine_similarity(base_vector["values"], perturbed_vector["values"] ) |
| 236 | # print ("cosine similarity of perturbed vec: ", row_ct, cs) |
| 237 | return perturbed_vector |
| 238 | # if np.random.rand() < 0.01: # 1 in 100 probability |
| 239 | # shortlisted_vectors.append(perturbed_vector) |
| 240 | |
| 241 | |
| 242 | def bruteforce_search(vectors, query, k=5): |
nothing calls this directly
no outgoing calls
no test coverage detected