adamjq commented on code in PR #4698:
URL: https://github.com/apache/solr/pull/4698#discussion_r4106978359
##########
solr/core/src/test/org/apache/solr/schema/ScalarQuantizedDenseVectorFieldTest.java:
##########
@@ -121,18 +129,245 @@ public void
fieldDefinition_deprecatedDynamicConfidenceInterval_shouldStillLoadS
ScalarQuantizedDenseVectorField vectorType =
(ScalarQuantizedDenseVectorField) vectorField.getType();
- assertThat(vectorType.getDimension(), is(4));
- assertThat(vectorType.getBits(),
is(ScalarQuantizedDenseVectorField.DEFAULT_BITS));
+ assertThat(vectorType.getConfidenceInterval(), is(0f));
} finally {
deleteCore();
}
}
@Test
- public void fieldDefinition_flatAlgorithm_shouldThrowException() throws
Exception {
- assertConfigs(
- "solrconfig-basic.xml",
- "bad-schema-densevector-flat-scalarQuantized.xml",
- "knnAlgorithm 'flat' is not supported for
ScalarQuantizedDenseVectorField");
+ public void fieldDefinition_flatAlgorithm_shouldLoadSchemaField() throws
Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+ IndexSchema schema = h.getCore().getLatestSchema();
+
+ SchemaField vector = schema.getField("vector_sq_flat");
+ assertNotNull(vector);
+
+ ScalarQuantizedDenseVectorField type = (ScalarQuantizedDenseVectorField)
vector.getType();
+ assertThat(type.getKnnAlgorithm(), is("flat"));
+ assertThat(type.getDimension(), is(4));
+ assertThat(type.getSimilarityFunction(),
is(VectorSimilarityFunction.COSINE));
+ assertThat(type.getBits(),
is(ScalarQuantizedDenseVectorField.DEFAULT_BITS));
+
+ assertTrue(vector.indexed());
+ assertTrue(vector.stored());
+ } finally {
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void
flatAlgorithm_buildKnnVectorsFormat_shouldReturnScalarQuantizedFormat()
+ throws Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+ IndexSchema schema = h.getCore().getLatestSchema();
+
+ SchemaField vector = schema.getField("vector_sq_flat");
+ ScalarQuantizedDenseVectorField type = (ScalarQuantizedDenseVectorField)
vector.getType();
+
+ assertThat(
+ type.buildKnnVectorsFormat() instanceof
Lucene104ScalarQuantizedVectorsFormat, is(true));
+ } finally {
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void flatAlgorithm_vectorSimilarityFunction_shouldReturnResults()
throws Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+
+ addDoc("0", 1.0f, 2.0f, 3.0f, 4.0f);
+ addDoc("1", 2.0f, 3.0f, 4.0f, 5.0f);
+ addDoc("2", 100.0f, 200.0f, 50.0f, 25.0f);
+
+ assertU(commit());
+
+ assertJQ(
+ req(
+ "q", "{!func}vectorSimilarity(vector_sq_flat,[1.0, 2.0, 3.0,
4.0])",
+ "fl", "id,score"),
+ "/response/numFound==3",
+ "/response/docs/[0]/id=='0'");
+
+ assertJQ(
+ req(
+ "q", "{!func}vectorSimilarity(vector_sq_flat,[1.0, 2.0, 3.0,
4.0])",
+ "fq", "id:(0 2)",
+ "fl", "id,score"),
+ "/response/numFound==2",
+ "/response/docs/[0]/id=='0'");
+ } finally {
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void flatAlgorithm_knnQuery_shouldReturnResults() throws Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+
+ addDoc("0", 1.0f, 2.0f, 3.0f, 4.0f);
+ addDoc("1", 2.0f, 3.0f, 4.0f, 5.0f);
+ addDoc("2", 100.0f, 200.0f, 50.0f, 25.0f);
+
+ assertU(commit());
+
+ assertJQ(
+ req(
+ "q", "{!knn f=vector_sq_flat topK=2}[1.0, 2.0, 3.0, 4.0]",
+ "fl", "id,score"),
+ "/response/numFound==2",
+ "/response/docs/[0]/id=='0'",
+ "/response/docs/[1]/id=='1'");
+ } finally {
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void flatAlgorithm_knnQuery_preFilter_shouldReturnFilteredResults()
throws Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+
+ addDoc("0", 1.0f, 2.0f, 3.0f, 4.0f);
+ addDoc("1", 2.0f, 3.0f, 4.0f, 5.0f);
+ addDoc("2", 100.0f, 200.0f, 50.0f, 25.0f);
+
+ assertU(commit());
+
+ assertJQ(
+ req(
+ "q", "{!knn f=vector_sq_flat topK=2 preFilter='id:(1 2)'}[1.0,
2.0, 3.0, 4.0]",
+ "fl", "id,score"),
+ "/response/numFound==2",
+ "/response/docs/[0]/id=='1'",
+ "/response/docs/[1]/id=='2'");
+ } finally {
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void flatAlgorithm_knnQuery_hnswParamsIgnored_shouldReturnResults()
throws Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+
+ addDoc("0", 1.0f, 2.0f, 3.0f, 4.0f);
+ addDoc("1", 2.0f, 3.0f, 4.0f, 5.0f);
+
+ assertU(commit());
+
+ assertJQ(
+ req(
+ "q",
+ "{!knn f=vector_sq_flat topK=1 efSearchScaleFactor=2.0"
+ + " earlyTermination=true saturationThreshold=0.95
patience=3"
+ + " filteredSearchThreshold=60}[1.0, 2.0, 3.0, 4.0]",
+ "fl",
+ "id,score"),
+ "/response/numFound==1",
+ "/response/docs/[0]/id=='0'");
+ } finally {
+ deleteCore();
+ }
+ }
+
+ @Test
+ public void flatAlgorithm_vectorSimilarityQParser_shouldReturnResults()
throws Exception {
+ try {
+ initCore("solrconfig_codec.xml",
"schema-densevector-flat-scalarQuantized.xml");
+
+ addDoc("0", 1.0f, 2.0f, 3.0f, 4.0f);
+ addDoc("1", 2.0f, 3.0f, 4.0f, 5.0f);
+ addDoc("2", 100.0f, 200.0f, 50.0f, 25.0f);
+
+ assertU(commit());
+
+ assertJQ(
+ req(
+ "q", "{!vectorSimilarity f=vector_sq_flat minReturn=0.0}[1.0,
2.0, 3.0, 4.0]",
+ "fl", "id,score"),
+ "/response/numFound==3",
+ "/response/docs/[0]/id=='0'");
Review Comment:
Updated - same as
https://github.com/apache/solr/pull/4698#discussion_r4106962564
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]