(self, vector: List[float])
| 389 | cache_path.write_text(json.dumps(payload), encoding="utf-8") |
| 390 | |
| 391 | def _resize_vector(self, vector: List[float]) -> List[float]: |
| 392 | if len(vector) == self.dimensions: |
| 393 | return vector |
| 394 | |
| 395 | if len(vector) < self.dimensions: |
| 396 | resized = vector + [0.0] * (self.dimensions - len(vector)) |
| 397 | else: |
| 398 | bucket_size = len(vector) / self.dimensions |
| 399 | resized = [] |
| 400 | for index in range(self.dimensions): |
| 401 | start = int(index * bucket_size) |
| 402 | end = int((index + 1) * bucket_size) |
| 403 | if end <= start: |
| 404 | end = start + 1 |
| 405 | segment = vector[start:end] |
| 406 | resized.append(sum(segment) / len(segment)) |
| 407 | |
| 408 | norm = sum(value * value for value in resized) ** 0.5 |
| 409 | if norm > 0: |
| 410 | resized = [value / norm for value in resized] |
| 411 | return resized |
| 412 | |
| 413 | def _get_openai_embedding(self, text: str) -> List[float]: |
| 414 | kwargs: Dict[str, Any] = {"model": self.model, "input": text} |
no outgoing calls
no test coverage detected