Add dense_vector equality and inequality support in ES|QL#140005
Add dense_vector equality and inequality support in ES|QL#140005mromaios merged 14 commits intoelastic:mainfrom
Conversation
|
💚 CLA has been signed |
ℹ️ Important: Docs version tagging👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version. We use applies_to tags to mark version-specific features and changes. Expand for a quick overviewWhen to use applies_to tags:✅ At the page level to indicate which products/deployments the content applies to (mandatory) What NOT to do:❌ Don't remove or replace information that applies to an older version 🤔 Need help?
|
Signed-off-by: majiayu000 <1835304752@qq.com>
|
@carlosdelest, could you look at this one? |
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
|
@elasticmachine recheck CLA |
carlosdelest
left a comment
There was a problem hiding this comment.
Nice work!
Some comments about adding test cases - can you please address them @majiayu000 ?
| suppliers.add( | ||
| new TestCaseSupplier("<dense_vector>, <different dense_vector>", List.of(DataType.DENSE_VECTOR, DataType.DENSE_VECTOR), () -> { | ||
| List<Float> left = randomDenseVector(); | ||
| List<Float> right = randomDenseVector(); |
There was a problem hiding this comment.
Nice thinking about vectors actually being different! I think it would be better to use other testing constructs for this:
| List<Float> right = randomDenseVector(); | |
| List<Float> right = randomValueOtherThan(left, EsTestCase::randomDenseVector()); |
| List<Float> left = randomDenseVector(); | ||
| List<Float> right = randomDenseVector(); | ||
| // Make sure vectors are different | ||
| if (left.equals(right) && left.size() > 0) { |
x-pack/plugin/esql/qa/testFixtures/src/main/resources/dense_vector.csv-spec
Show resolved
Hide resolved
x-pack/plugin/esql/qa/testFixtures/src/main/resources/dense_vector.csv-spec
Show resolved
Hide resolved
x-pack/plugin/esql/qa/testFixtures/src/main/resources/dense_vector.csv-spec
Show resolved
Hide resolved
|
Hi @carlosdelest, I have updated the PR to address your review comments |
| required_capability: dense_vector_field_type_released | ||
| required_capability: dense_vector_agg_metric_double_if_version | ||
| required_capability: l2_norm_vector_similarity_function | ||
| required_capability: generic_vector_format | ||
| required_capability: dense_vector_equality |
There was a problem hiding this comment.
Please use only required_capability with the needed capabilities for the test to work - in this case:
| required_capability: dense_vector_field_type_released | |
| required_capability: dense_vector_agg_metric_double_if_version | |
| required_capability: l2_norm_vector_similarity_function | |
| required_capability: generic_vector_format | |
| required_capability: dense_vector_equality | |
| required_capability: dense_vector_equality |
We can skip checking other capabilities as they are superseded by dense_vector_equality, which is newer
x-pack/plugin/esql/qa/testFixtures/src/main/resources/dense_vector.csv-spec
Show resolved
Hide resolved
x-pack/plugin/esql/qa/testFixtures/src/main/resources/dense_vector.csv-spec
Show resolved
Hide resolved
|
Hi @carlosdelest, thanks for the additional feedback! I have updated the CSV specs to:
|
|
@elasticsearchmachine test this please |
...earch/xpack/esql/expression/predicate/operator/comparison/NotEqualsDenseVectorEvaluator.java
Outdated
Show resolved
Hide resolved
|
@elasticsearchmachine test this please |
|
@majiayu000 I've added some commits to address some issues. I see that we have some compile errors in Also, I liked these versions better when they were testing equality and inequality. Why did you change that to a fixed amount of random tests? 🤔 The original approach was better IMO |
|
@carlosdelest Thanks for the review! I've fixed the compilation errors in EqualsTests and NotEqualsTests (missing static imports). Regarding the test coverage, you were right — the fixed set of random tests wasn't ideal. I've refactored it to use the TestCaseSupplier.casesCrossProduct approach with a stable set of random vectors. This ensures we test the full cross-product (both equality and inequality scenarios) while keeping the implementation clean. Ready for another look! |
c89ab28 to
f6d34e5
Compare
|
@majiayu000 thanks for iterating on this! I'm afraid that I don't see the changes you mention on the tests. Can you please double check? Also, please don't force push - it's easier for me to review with the full commit history 👍 |
|
@carlosdelest thanks for checking. I've double checked the commit f6d34e5 and it contains the changes for EqualsTests and NotEqualsTests (imports and randomDenseVector logic). I also pushed a new commit cdfa93d with the same refactoring for InsensitiveEqualsTests. Please double check f6d34e5 for EqualsTests/NotEqualsTests and cdfa93d for InsensitiveEqualsTests. I didn't force push, so the history is preserved. |
|
Hey @majiayu000, addressed some pending test comments in 0fd20d0 and run the tests, but the From a quick look, it's two issues:
If you can have a look when you get the chance? |
|
@elasticsearchmachine test this please |
Signed-off-by: majiayu000 <1835304752@qq.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
a3ced57 to
a6944a2
Compare
|
@mromaios Both issues fixed — wrapped arrays with |
|
Thanks @majiayu000! I think this looks good now. Took care of some compilation errors after an interface move. Running CI, (hopefully for the last time 🤞) |
|
@elasticsearchmachine test this please |
|
@elasticsearchmachine test this please |
|
@elasticsearchmachine test this please |
|
@elasticmachine run elasticsearch-ci/pr-upgrade-part-3, elasticsearch-ci/rest-compatibility please |
carlosdelest
left a comment
There was a problem hiding this comment.
LGTM, thank you for your work @majiayu000 and @mromaios !
|
Thanks again for the contribution @majiayu000 and for the many rounds of reviews @carlosdelest and @kkharbas. |
|
@elasticmachine run Elasticsearch Serverless Checks, elasticsearch-ci/rest-compatibility please |
|
@elasticmachine run elasticsearch-ci/rest-compatibility please |
|
@elasticsearchmachine test this please |
Summary
Adds support for binary comparison operators (==, !=) for dense_vector type in ES|QL.
Resolves #139929
Changes
EqualsDenseVectorEvaluatorandNotEqualsDenseVectorEvaluatorclasses to handle dense_vector comparisonEquals.javaandNotEquals.javawith dense_vector support in evaluatorMap and @param annotationsDENSE_VECTOR_EQUALITYcapability in EsqlCapabilitiesTwo dense vectors are equal if they have the same dimensions and all corresponding elements are equal.
Test plan