Repository navigation
implement missing validation for sparse and milti-vectors in grpc - #6274
Conversation
📝 WalkthroughWalkthroughThe changes update and extend validation across several modules. In the gRPC module, the vector validation logic is enhanced by incorporating new validations for an optional field and adding implementations of the ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
tests/basic_grpc_test.sh (1)
95-117: Valid sparse vector insertion test is effective.It’s good to confirm that proper data passes validation. As a potential improvement, consider adding assertions on the server’s response status or the stored data to further validate correctness.
lib/api/src/grpc/validate.rs (3)
238-249: Ensure comprehensive validation when bothvectoranddata/indicesfields are present.The optional
vectorfield is validated if provided, and you correctly handleindices/vectors_countexclusivity. However, consider clarifying whetherdatais expected whenvectoris set, to avoid partial/ambiguous definitions.
269-280: Variant-level validations appear concise but consider specific checks.For variants like
DocumentorImage, you might enforce format rules or size limits. Even if they pass by default, consider adding more checks if they have known constraints.
282-295: Handle potential invalid inputs more explicitly inSparseVectorandMultiDenseVector.While
validate_sparse_vector_implandvalidate_multi_vector_by_lengthare robust, consider checks for negative or out-of-order indices, and issuance of user-friendly error messages if encountered.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
lib/api/src/grpc/validate.rs(2 hunks)lib/common/common/src/validation.rs(5 hunks)lib/segment/src/vector_storage/sparse/mmap_sparse_vector_storage.rs(1 hunks)tests/basic_grpc_test.sh(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
- GitHub Check: Basic TLS/HTTPS tests
- GitHub Check: test-snapshot-operations-s3-minio
- GitHub Check: test-shard-snapshot-api-s3-minio
- GitHub Check: test-low-resources
- GitHub Check: test-consistency
- GitHub Check: test (macos-latest)
- GitHub Check: test-consensus-compose
- GitHub Check: test-consensus
- GitHub Check: test (windows-latest)
- GitHub Check: test
- GitHub Check: test
- GitHub Check: test (ubuntu-latest)
- GitHub Check: test
🔇 Additional comments (6)
tests/basic_grpc_test.sh (2)
30-38: Configuration for on-disk sparse vector indexing looks good.Including
"sparse_vectors_config"allows indexing sparse vectors on disk, which is helpful for large datasets. Ensure you’ve confirmed the performance and storage trade-offs of on-disk indexing for your use case.
68-93: Great job testing the invalid sparse vector scenario.This negative test verifying a validation error helps ensure the API rejects malformed data. The
grep -q "Validation error in body"check is a reliable pattern for CI validation.lib/api/src/grpc/validate.rs (1)
258-262:Details
❓ Verification inconclusive
Request verification of sparse-vector length mismatch scenarios.
When using
indicesalongsidedata, ensure no length mismatch can slip through. You might want to confirm that all relevant checks exist upstream or invalidate_sparse_vector_impl.
🏁 Script executed:
#!/bin/bash # This script checks for references to validate_sparse_vector_impl usage to ensure length mismatch is thoroughly validated. rg "validate_sparse_vector_impl" -A 5Length of output: 4494
Sparse Vector Length Validation Consistency
I verified that all invocations of
validate_sparse_vector_impl—including the one in this GRPC validation case—are consistent with its usage elsewhere in the codebase. Please confirm that its implementation inlib/sparse/src/common/sparse_vector.rsexplicitly checks for length mismatches between the provided indices and data so that no inconsistent sparse vector scenarios can slip through.lib/common/common/src/validation.rs (3)
157-157: Function has been refactored to work with vector lengths directlyThe function has been renamed from
validate_multi_vectortovalidate_multi_vector_by_length, and its signature has changed to accept a slice of vector lengths rather than a slice of vectors. This is a good separation of concerns that allows validation to operate on lengths directly.
159-159: Implementation correctly updated to work with vector lengthsThe validation logic has been properly adjusted to operate on lengths instead of the actual vectors:
- Checking for empty input by verifying if
multivec_lengthis empty- Validating that no individual length is zero
- Computing the total size by summing the lengths
- Ensuring consistent dimensions by comparing all lengths with the first one
- Error message formatting updated to reflect these changes
This refactoring preserves the original validation logic while making it more flexible.
Also applies to: 168-168, 177-177, 187-188, 194-194
204-207: Good addition of a backward-compatible wrapper functionA new wrapper function
validate_multi_vectorhas been added that maintains the original function signature. This function simply collects the lengths from the input vectors and delegates tovalidate_multi_vector_by_length, ensuring backward compatibility while benefiting from the refactored implementation.
No description provided.