This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 3c9fcc1ebf3 SOLR-18329: DenseVectorField support existence queries
(#4700)
3c9fcc1ebf3 is described below
commit 3c9fcc1ebf33ed337fcd100e125532bb8eff6a54
Author: linslee75 <[email protected]>
AuthorDate: Fri Aug 7 14:11:15 2026 +0800
SOLR-18329: DenseVectorField support existence queries (#4700)
---
.../SOLR-18329-densevector-existence-queries.yml | 8 +++++
.../org/apache/solr/schema/DenseVectorField.java | 14 ++++++++-
.../apache/solr/schema/DenseVectorFieldTest.java | 34 +++++++++++++++++-----
.../query-guide/pages/dense-vector-search.adoc | 2 ++
4 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/changelog/unreleased/SOLR-18329-densevector-existence-queries.yml
b/changelog/unreleased/SOLR-18329-densevector-existence-queries.yml
new file mode 100644
index 00000000000..e4ad24480d1
--- /dev/null
+++ b/changelog/unreleased/SOLR-18329-densevector-existence-queries.yml
@@ -0,0 +1,8 @@
+title: DenseVectorField now supports existence queries (field:* / [* TO *])
+type: added
+authors:
+ - name: Li Enlai
+ nick: linslee75
+links:
+ - name: SOLR-18329
+ url: https://issues.apache.org/jira/browse/SOLR-18329
diff --git a/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
b/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
index 797b6bfc9a7..f010c741b07 100644
--- a/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
+++ b/solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
@@ -37,6 +37,7 @@ import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.ByteKnnVectorFieldSource;
import
org.apache.lucene.queries.function.valuesource.FloatKnnVectorFieldSource;
+import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.PatienceKnnVectorQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SeededKnnVectorQuery;
@@ -572,6 +573,11 @@ public class DenseVectorField extends FloatPointField {
return baseQuery;
}
+ @Override
+ public Query getExistenceQuery(QParser parser, SchemaField field) {
+ return new FieldExistsQuery(field.getName());
+ }
+
/**
* Not Supported. Please use the {!knn} query parser to run K nearest
neighbors search queries.
*/
@@ -582,7 +588,10 @@ public class DenseVectorField extends FloatPointField {
"Field Queries are not supported for Dense Vector fields. Please use
the {!knn} query parser to run K nearest neighbors search queries.");
}
- /** Not Supported */
+ /**
+ * Unbounded ranges ({@code [* TO *]}) are treated as existence queries.
Bounded range queries are
+ * not supported.
+ */
@Override
public Query getRangeQuery(
QParser parser,
@@ -591,6 +600,9 @@ public class DenseVectorField extends FloatPointField {
String part2,
boolean minInclusive,
boolean maxInclusive) {
+ if (part1 == null && part2 == null) {
+ return getExistenceQuery(parser, field);
+ }
throw new SolrException(
SolrException.ErrorCode.BAD_REQUEST,
"Range Queries are not supported for Dense Vector fields. Please use
the {!knn} query parser to run K nearest neighbors search queries.");
diff --git
a/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
b/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
index a11e184e2e1..442a0cd4eef 100644
--- a/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/DenseVectorFieldTest.java
@@ -556,18 +556,36 @@ public class DenseVectorFieldTest extends
AbstractBadConfigTestBase {
}
}
- /** Not Supported */
@Test
- public void query_existenceSearch_shouldThrowException() throws Exception {
+ public void query_existenceSearch_shouldMatchDocumentsWithVector() throws
Exception {
try {
initCore("solrconfig-basic.xml", "schema-densevector.xml");
- assertQEx(
- "Running Existence queries on a dense vector field should raise an
Exception",
- "Range Queries are not supported for Dense Vector fields."
- + " Please use the {!knn} query parser to run K nearest
neighbors search queries.",
- req("q", "vector:[* TO *]", "fl", "vector"),
- SolrException.ErrorCode.BAD_REQUEST);
+ SolrInputDocument doc1 = new SolrInputDocument();
+ doc1.addField("id", "1");
+ doc1.addField("vector", List.of(1.0f, 2.0f, 3.0f, 4.0f));
+ assertU(adoc(doc1));
+
+ SolrInputDocument doc2 = new SolrInputDocument();
+ doc2.addField("id", "2");
+ assertU(adoc(doc2));
+
+ assertU(commit());
+
+ assertJQ(
+ req("q", "vector:[* TO *]", "fl", "id", "sort", "id asc"),
+ "/response/numFound==1",
+ "/response/docs/[0]/id=='1'");
+
+ assertJQ(
+ req("q", "vector:*", "fl", "id", "sort", "id asc"),
+ "/response/numFound==1",
+ "/response/docs/[0]/id=='1'");
+
+ assertJQ(
+ req("q", "-vector:*", "fl", "id", "sort", "id asc"),
+ "/response/numFound==1",
+ "/response/docs/[0]/id=='2'");
} finally {
deleteCore();
}
diff --git
a/solr/solr-ref-guide/modules/query-guide/pages/dense-vector-search.adoc
b/solr/solr-ref-guide/modules/query-guide/pages/dense-vector-search.adoc
index c91a362f740..879ec439124 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/dense-vector-search.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/dense-vector-search.adoc
@@ -355,6 +355,8 @@ Apache Solr provides three query parsers that work with the
`DenseVectorField` f
All parsers return scores for retrieved documents that are the approximate
distance to the target vector (defined by the similarityFunction configured at
indexing time) and both support "Pre-Filtering" the document graph to reduce
the number of candidate vectors evaluated (without needing to compute their
vector similarity distances).
+While field queries and bounded range queries are not supported on
`DenseVectorField`, existence queries such as `vector:*` (or the equivalent
`vector:[* TO *]`) can be used to match documents that have a value for the
vector field.
+
Common parameters for all query parsers are:
`f`::