validateVectorDimension checks that the vector has the expected dimension for the predicate. If this is the first vector for the predicate, it sets the expected dimension. Returns true if the vector is valid, false otherwise.
(pred string, vector []float32, uid uint64)
| 327 | // If this is the first vector for the predicate, it sets the expected dimension. |
| 328 | // Returns true if the vector is valid, false otherwise. |
| 329 | func (vi *vectorIndexer) validateVectorDimension(pred string, vector []float32, uid uint64) bool { |
| 330 | vi.mu.Lock() |
| 331 | defer vi.mu.Unlock() |
| 332 | |
| 333 | // Empty vectors are invalid |
| 334 | if len(vector) == 0 { |
| 335 | vi.handleError( |
| 336 | fmt.Errorf("empty vector for predicate %s uid %d", pred, uid), |
| 337 | fmt.Sprintf("predicate=%s uid=%d", pred, uid), |
| 338 | "<vector_validation>", |
| 339 | ) |
| 340 | return false |
| 341 | } |
| 342 | |
| 343 | // Check dimension consistency |
| 344 | expectedDim, exists := vi.dimensions[pred] |
| 345 | if !exists { |
| 346 | // First vector for this predicate - set the expected dimension |
| 347 | vi.dimensions[pred] = len(vector) |
| 348 | return true |
| 349 | } |
| 350 | |
| 351 | if len(vector) != expectedDim { |
| 352 | vi.handleError( |
| 353 | fmt.Errorf("dimension mismatch: expected %d, got %d", expectedDim, len(vector)), |
| 354 | fmt.Sprintf("predicate=%s uid=%d expected_dim=%d actual_dim=%d", pred, uid, expectedDim, len(vector)), |
| 355 | "<vector_validation>", |
| 356 | ) |
| 357 | return false |
| 358 | } |
| 359 | |
| 360 | return true |
| 361 | } |
| 362 | |
| 363 | // addVectorEntry processes a single vector entry by inserting it into the HNSW index. |
| 364 | // This is the entry point called from reduce phase. |
no test coverage detected