-
Notifications
You must be signed in to change notification settings - Fork 60
feat: add text field weights support to TextQuery (#360) #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1b98123 to
3d45afd
Compare
3d45afd to
066579f
Compare
Adds the ability to specify weights for text fields in RedisVL queries,
enabling users to prioritize certain fields over others in search results.
- Support dictionary of field:weight mappings in TextQuery constructor
- Maintain backward compatibility with single string field names
- Add set_field_weights() method for dynamic weight updates
- Generate proper Redis query syntax with weight modifiers
- Comprehensive validation for positive numeric weights
Example usage:
```python
query = TextQuery(text="search", text_field_name={"title": 5.0})
query = TextQuery(
text="search",
text_field_name={"title": 3.0, "content": 1.5, "tags": 1.0}
)
```
- Add has_redisearch_module and has_redisearch_module_async helpers to conftest.py
- Add skip_if_no_redisearch and skip_if_no_redisearch_async functions
- Update test_no_proactive_module_checks.py to use shared helpers
- Update test_semantic_router.py to check RediSearch availability in fixtures and tests
- Update test_llmcache.py to check RediSearch availability in all cache fixtures
- Update test_message_history.py to check RediSearch availability for semantic history
- Ensure all tests that require RediSearch are properly skipped on Redis 6.2.6-v9
- BM25STD scorer is not available in Redis versions prior to 7.2.0. Add version check to skip these tests on older Redis versions.
066579f to
3395c87
Compare
Collaborator
|
Nice one. |
bsbodden
added a commit
to redis/redis-vl-java
that referenced
this pull request
Oct 22, 2025
Implements text field weights functionality allowing users to prioritize certain fields over others in full-text search queries. Python Reference: PR #384 (redis/redis-vl-python#384) Test Reference: tests/unit/test_text_query_weights.py (123 lines) Implementation: - TextQuery now accepts Map<String, Double> for textFieldWeights - Builder pattern with textField() for single field (backward compatible) - Builder method textFieldWeights() for multiple fields with custom weights - Query syntax: @field:(terms) => { $weight: 5.0 } for non-default weights - Multiple fields joined with OR operator in parentheses - Dynamic weight updates via setFieldWeights() method Validation: - Rejects negative weights (IllegalArgumentException) - Rejects zero weights (IllegalArgumentException) - Ensures all weights are positive numbers - Maintains backward compatibility with single string field API Breaking Changes: - TextQuery constructor changed to private (use Builder instead) - Updated QueryIntegrationTest to use builder pattern Tests: 7 unit tests added (TextQueryWeightsTest) - testTextQueryAcceptsWeightsDict - testTextQueryGeneratesWeightedQueryString - testTextQueryMultipleFieldsWithWeights - testTextQueryBackwardCompatibility - testTextQueryRejectsNegativeWeights - testTextQueryRejectsZeroWeights - testSetFieldWeightsMethod All tests pass: 289 tests, 14 skipped Files Modified: - core/src/main/java/com/redis/vl/query/TextQuery.java (complete rewrite) - core/src/test/java/com/redis/vl/query/QueryIntegrationTest.java (builder migration) Files Created: - core/src/test/java/com/redis/vl/query/TextQueryWeightsTest.java
bsbodden
added a commit
to redis/redis-vl-java
that referenced
this pull request
Oct 22, 2025
Implements text field weights functionality allowing users to prioritize certain fields over others in full-text search queries. Python Reference: PR #384 (redis/redis-vl-python#384) Test Reference: tests/unit/test_text_query_weights.py (123 lines) Implementation: - TextQuery now accepts Map<String, Double> for textFieldWeights - Builder pattern with textField() for single field (backward compatible) - Builder method textFieldWeights() for multiple fields with custom weights - Query syntax: @field:(terms) => { $weight: 5.0 } for non-default weights - Multiple fields joined with OR operator in parentheses - Dynamic weight updates via setFieldWeights() method Validation: - Rejects negative weights (IllegalArgumentException) - Rejects zero weights (IllegalArgumentException) - Ensures all weights are positive numbers - Maintains backward compatibility with single string field API Breaking Changes: - TextQuery constructor changed to private (use Builder instead) - Updated QueryIntegrationTest to use builder pattern Tests: 7 unit tests added (TextQueryWeightsTest) - testTextQueryAcceptsWeightsDict - testTextQueryGeneratesWeightedQueryString - testTextQueryMultipleFieldsWithWeights - testTextQueryBackwardCompatibility - testTextQueryRejectsNegativeWeights - testTextQueryRejectsZeroWeights - testSetFieldWeightsMethod All tests pass: 289 tests, 14 skipped Files Modified: - core/src/main/java/com/redis/vl/query/TextQuery.java (complete rewrite) - core/src/test/java/com/redis/vl/query/QueryIntegrationTest.java (builder migration) Files Created: - core/src/test/java/com/redis/vl/query/TextQueryWeightsTest.java
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds the ability to specify weights for text fields in RedisVL queries, enabling users to prioritize certain fields over others in search results.
Example usage: