@@ -125,7 +125,8 @@ public void testSupportsRemoteIndexBuild() {
125
125
}
126
126
127
127
public void testCreateRemoteIndexingParameters_Success () {
128
- RemoteIndexParameters result = FaissHNSWMethod .createRemoteIndexingParameters (createMockMethodContext ());
128
+ FaissHNSWMethod method = new FaissHNSWMethod ();
129
+ RemoteIndexParameters result = method .createRemoteIndexingParameters (createMockMethodContext ());
129
130
130
131
assertNotNull (result );
131
132
assertTrue (result instanceof RemoteFaissHNSWIndexParameters );
@@ -139,6 +140,21 @@ public void testCreateRemoteIndexingParameters_Success() {
139
140
assertEquals (14 , hnswParams .getM ());
140
141
}
141
142
143
+ public void testCreateRemoteIndexingParameters_CosineSpaceType () {
144
+ FaissHNSWMethod method = new FaissHNSWMethod ();
145
+ KNNMethodContext context = createMockMethodContextWithCosineSimil ();
146
+
147
+ RemoteIndexParameters result = method .createRemoteIndexingParameters (context );
148
+
149
+ assertNotNull (result );
150
+ assertTrue (result instanceof RemoteFaissHNSWIndexParameters );
151
+
152
+ RemoteFaissHNSWIndexParameters hnswParams = (RemoteFaissHNSWIndexParameters ) result ;
153
+
154
+ // Test that cosine space type is converted to inner product space type for Faiss
155
+ assertEquals (SpaceType .INNER_PRODUCT .getValue (), hnswParams .getSpaceType ());
156
+ }
157
+
142
158
public static KNNMethodContext createFaissIVFMethodContext () {
143
159
MethodComponentContext encoder = new MethodComponentContext (ENCODER_SQ , Map .of ());
144
160
Map <String , Object > encoderMap = Map .of (METHOD_ENCODER_PARAMETER , encoder );
@@ -178,4 +194,20 @@ public static KNNMethodContext createMockMethodContext() {
178
194
return new KNNMethodContext (KNNEngine .FAISS , SpaceType .L2 , methodComponentContext );
179
195
}
180
196
197
+ public static KNNMethodContext createMockMethodContextWithCosineSimil () {
198
+ MethodComponentContext encoder = new MethodComponentContext (KNNConstants .ENCODER_FLAT , Map .of ());
199
+ Map <String , Object > parameters = Map .of (
200
+ KNNRemoteConstants .METHOD_PARAMETER_EF_SEARCH ,
201
+ 89 ,
202
+ KNNRemoteConstants .METHOD_PARAMETER_EF_CONSTRUCTION ,
203
+ 94 ,
204
+ KNNRemoteConstants .METHOD_PARAMETER_M ,
205
+ 14 ,
206
+ METHOD_PARAMETER_ENCODER ,
207
+ encoder
208
+ );
209
+ MethodComponentContext methodComponentContext = new MethodComponentContext (KNNConstants .METHOD_HNSW , parameters );
210
+ return new KNNMethodContext (KNNEngine .FAISS , SpaceType .COSINESIMIL , methodComponentContext );
211
+ }
212
+
181
213
}
0 commit comments