diff --git a/CouchbaseLite.xcodeproj/project.pbxproj b/CouchbaseLite.xcodeproj/project.pbxproj index a3ad64f60..ef62e5511 100644 --- a/CouchbaseLite.xcodeproj/project.pbxproj +++ b/CouchbaseLite.xcodeproj/project.pbxproj @@ -382,12 +382,12 @@ 406F8DEB2C26901A000223FC /* QueryIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DEA2C26901A000223FC /* QueryIndex.swift */; }; 406F8DEC2C26901A000223FC /* QueryIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DEA2C26901A000223FC /* QueryIndex.swift */; }; 406F8DFB2C27C303000223FC /* IndexUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DF92C27C302000223FC /* IndexUpdater.swift */; }; - 406F8DFF2C27F0A9000223FC /* LazyVectorIndexTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DFC2C27F097000223FC /* LazyVectorIndexTest.swift */; }; - 406F8E002C27F0AB000223FC /* LazyVectorIndexTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DFC2C27F097000223FC /* LazyVectorIndexTest.swift */; }; + 406F8DFF2C27F0A9000223FC /* VectorLazyIndexTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DFC2C27F097000223FC /* VectorLazyIndexTest.swift */; }; + 406F8E002C27F0AB000223FC /* VectorLazyIndexTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 406F8DFC2C27F097000223FC /* VectorLazyIndexTest.swift */; }; 40AA72952C28938D007FB1E0 /* VectorSearchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = AE006DE62B7BB98B00884E2B /* VectorSearchTest.m */; }; 40AA72962C28938E007FB1E0 /* VectorSearchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = AE006DE62B7BB98B00884E2B /* VectorSearchTest.m */; }; - 40AA729D2C28B1A3007FB1E0 /* LazyVectorIndexTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 40AA72972C28B1A3007FB1E0 /* LazyVectorIndexTest.m */; }; - 40AA729E2C28B1A3007FB1E0 /* LazyVectorIndexTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 40AA72972C28B1A3007FB1E0 /* LazyVectorIndexTest.m */; }; + 40AA729D2C28B1A3007FB1E0 /* VectorLazyIndexTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 40AA72972C28B1A3007FB1E0 /* VectorLazyIndexTest.m */; }; + 40AA729E2C28B1A3007FB1E0 /* VectorLazyIndexTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 40AA72972C28B1A3007FB1E0 /* VectorLazyIndexTest.m */; }; 40C5FD5B2B9947B3004BFD3B /* CBLVectorIndexTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 40C5FD5A2B9946E6004BFD3B /* CBLVectorIndexTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; 40C5FD5C2B9947B9004BFD3B /* CBLVectorIndexTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 40C5FD5A2B9946E6004BFD3B /* CBLVectorIndexTypes.h */; settings = {ATTRIBUTES = (Private, ); }; }; 40EF690C2B7757CF00F0CB50 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 40EF690A2B77564000F0CB50 /* PrivacyInfo.xcprivacy */; }; @@ -2287,13 +2287,13 @@ 4017E4642BED6E5400A438EE /* CBLContextManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBLContextManager.m; sourceTree = ""; }; 406F8DEA2C26901A000223FC /* QueryIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryIndex.swift; sourceTree = ""; }; 406F8DF92C27C302000223FC /* IndexUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexUpdater.swift; sourceTree = ""; }; - 406F8DFC2C27F097000223FC /* LazyVectorIndexTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyVectorIndexTest.swift; sourceTree = ""; }; + 406F8DFC2C27F097000223FC /* VectorLazyIndexTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VectorLazyIndexTest.swift; sourceTree = ""; }; 40A789282BE2C7D100CA43A1 /* CBL_EE.exp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.exports; path = CBL_EE.exp; sourceTree = ""; }; 40A789292BE2C7D100CA43A1 /* CBL.exp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.exports; path = CBL.exp; sourceTree = ""; }; 40A7892B2BE2C7D100CA43A1 /* CBL_EE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CBL_EE.txt; sourceTree = ""; }; 40A7892C2BE2C7D100CA43A1 /* CBL.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CBL.txt; sourceTree = ""; }; 40A7892D2BE2C7D100CA43A1 /* generate_exports.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = generate_exports.sh; sourceTree = ""; }; - 40AA72972C28B1A3007FB1E0 /* LazyVectorIndexTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LazyVectorIndexTest.m; sourceTree = ""; }; + 40AA72972C28B1A3007FB1E0 /* VectorLazyIndexTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VectorLazyIndexTest.m; sourceTree = ""; }; 40AA72A12C28B1F2007FB1E0 /* VectorSearchTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VectorSearchTest.h; sourceTree = ""; }; 40C5FD5A2B9946E6004BFD3B /* CBLVectorIndexTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBLVectorIndexTypes.h; sourceTree = ""; }; 40E905462B5B6D9D00EDF483 /* CouchbaseLiteSwift.private.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = CouchbaseLiteSwift.private.modulemap; sourceTree = ""; }; @@ -3079,7 +3079,7 @@ 934608EE247F35CC00CF2F27 /* URLEndpointListenerTest.swift */, 1A13DD3328B8809300BC1084 /* URLEndpointListenerTest+Collection.swift */, AE5803A32B99C67D001A1BE3 /* VectorSearchTest.swift */, - 406F8DFC2C27F097000223FC /* LazyVectorIndexTest.swift */, + 406F8DFC2C27F097000223FC /* VectorLazyIndexTest.swift */, 1AA91DC522B0356000BF0BDE /* CustomLogger.swift */, 93249D81246B99FD000A8A6E /* iOS */, 939B79241E679017009A70EF /* Info.plist */, @@ -4147,7 +4147,7 @@ 1AA3D77222AB06E10098E16B /* CustomLogger.m */, 40AA72A12C28B1F2007FB1E0 /* VectorSearchTest.h */, AE006DE62B7BB98B00884E2B /* VectorSearchTest.m */, - 40AA72972C28B1A3007FB1E0 /* LazyVectorIndexTest.m */, + 40AA72972C28B1A3007FB1E0 /* VectorLazyIndexTest.m */, 93DECF3E200DBE5800F44953 /* Support */, 936483AA1E4431C6008D08B3 /* iOS */, 275FF5FA1E3FBD3B005F90DD /* Performance */, @@ -6267,7 +6267,7 @@ 93BB1C9E246BB2BF004FFA00 /* DatabaseTest.swift in Sources */, 93BB1C9C246BB2BB004FFA00 /* CBLTestCase.swift in Sources */, 93BB1CB8246BB2F4004FFA00 /* ReplicatorTest+CustomConflict.swift in Sources */, - 406F8E002C27F0AB000223FC /* LazyVectorIndexTest.swift in Sources */, + 406F8E002C27F0AB000223FC /* VectorLazyIndexTest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -6694,7 +6694,7 @@ 1A621D7A2887DCFD0017F905 /* QueryTest+Collection.m in Sources */, 93EB25CC21CDD12A0006FB88 /* PredictiveQueryTest.m in Sources */, 1AF555D422948BD90077DF6D /* QueryTest+Main.m in Sources */, - 40AA729D2C28B1A3007FB1E0 /* LazyVectorIndexTest.m in Sources */, + 40AA729D2C28B1A3007FB1E0 /* VectorLazyIndexTest.m in Sources */, 9343F13D207D61EC00F19A89 /* MigrationTest.m in Sources */, 9343F13E207D61EC00F19A89 /* DocumentTest.m in Sources */, 9343F140207D61EC00F19A89 /* DictionaryTest.m in Sources */, @@ -6748,7 +6748,7 @@ 1AA6744C227924130018CC6D /* QueryTest+Meta.m in Sources */, 934EF8322460D07B0053A47C /* TLSIdentityTest.m in Sources */, 9369A6AF207DD105009B5B83 /* DatabaseEncryptionTest.m in Sources */, - 40AA729E2C28B1A3007FB1E0 /* LazyVectorIndexTest.m in Sources */, + 40AA729E2C28B1A3007FB1E0 /* VectorLazyIndexTest.m in Sources */, 9343F176207D633300F19A89 /* DocumentTest.m in Sources */, 1A13DD4228B882A800BC1084 /* URLEndpointListenerTest+Main.m in Sources */, 9388CBAE21BD9187005CA66D /* DocumentExpirationTest.m in Sources */, @@ -6810,7 +6810,7 @@ 9343F198207D636300F19A89 /* CBLTestCase.swift in Sources */, 93C50EB021BDFC7B00C7E980 /* DocumentExpirationTest.swift in Sources */, 9369A6B7207DEB60009B5B83 /* DatabaseEncryptionTest.swift in Sources */, - 406F8DFF2C27F0A9000223FC /* LazyVectorIndexTest.swift in Sources */, + 406F8DFF2C27F0A9000223FC /* VectorLazyIndexTest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Objective-C/Tests/LazyVectorIndexTest.m b/Objective-C/Tests/VectorLazyIndexTest.m similarity index 98% rename from Objective-C/Tests/LazyVectorIndexTest.m rename to Objective-C/Tests/VectorLazyIndexTest.m index 2b0576c02..115b43787 100644 --- a/Objective-C/Tests/LazyVectorIndexTest.m +++ b/Objective-C/Tests/VectorLazyIndexTest.m @@ -28,11 +28,11 @@ #define LAZY_VECTOR_INDEX_CONFIG(E, D, C) [self lazyVectorIndexConfigWithExpression: (E) dimensions: (D) centroids: (C)] -@interface LazyVectorIndexTest : VectorSearchTest +@interface VectorLazyIndexTest : VectorSearchTest @end -@implementation LazyVectorIndexTest +@implementation VectorLazyIndexTest - (CBLQueryIndex*) wordsIndex { CBLQueryIndex* index = [self.wordsCollection indexWithName: kWordsIndexName error: nil]; @@ -208,7 +208,7 @@ - (void) testGetExistingVectorIndex { * 3. Create an SQL++ query: * - SELECT word * FROM _default.words - * WHERE vector_match(words_index, < dinner vector >) + * WHERE vector_match(words_index, ) * 4. Execute the query and check that 0 results are returned. * 5. Update the documents: * - Create _default.words.word301 with the content from _default.extwords.word1 @@ -261,7 +261,7 @@ - (void) testLazyVectorIndexNotAutoUpdatedChangedDocs { * 6. Create an SQL++ query: * - SELECT word * FROM _default.words - * WHERE vector_match(words_index, < dinner vector >, 300) + * WHERE vector_match(words_index, ) LIMIT 300 * 7. Execute the query and check that 1 results are returned. * 8. Check that the word gotten from the query result is the same as the word in Step 5. * 9. Delete _default.words.word1 doc. @@ -318,7 +318,7 @@ - (void) testLazyVectorIndexAutoUpdateDeletedDocs { * 7. Create an SQL++ query: * - SELECT word * FROM _default.words - * WHERE vector_match(words_index, < dinner vector >, 300) + * WHERE vector_match(words_index, ) LIMIT 300 * 8. Execute the query and check that 1 results are returned. * 9. Check that the word gotten from the query result is the same as the word in Step 5. * 10. Purge _default.words.word1 doc. @@ -827,7 +827,7 @@ - (void) testIndexUpdaterGettingValues { * 7. Execute a vector search query. * - SELECT word * FROM _default.words - * WHERE vector_match(words_index, < dinner vector >, 300) + * WHERE vector_match(words_index, ) LIMIT 300 * 8. Check that there are 10 words returned. * 9. Check that the word is in the word set from the step 5. */ @@ -884,8 +884,7 @@ - (void) testIndexUpdaterSetFloatArrayVectors { * 5. With the IndexUpdater object, call setVector() with a float array as [1.0] * 6. Check that the setVector throws CouchbaseLiteException with the InvalidParameter error. */ -// CBL-5814 -- (void) _testIndexUpdaterSetInvalidVectorDimensions { +- (void) testIndexUpdaterSetInvalidVectorDimensions { [self createWordsIndexWithConfig: LAZY_VECTOR_INDEX_CONFIG(@"word", 300, 8)]; NSError* error; @@ -1091,7 +1090,7 @@ - (void) testIndexUpdaterCaughtUp { * 7. Execute a vector search query. * - SELECT word * FROM _default.words - * WHERE vector_match(words_index, < dinner vector >, 300) + * WHERE vector_match(words_index, ) LIMIT 300 * 8. Check that there are 0 words returned. */ @@ -1247,10 +1246,9 @@ - (void) testIndexUpdaterIndexOutOfBounds { * - Convert the vector result which is an array object to a platform's float array. * - Call setVector() with the platform's float array at the index.. * 8. Call finish() and check that the finish() is successfully called. - * 9. Call finish() again and check that a CouchbaseLiteException with the code Unsupported is thrown. + * 9. Call finish() again and check that a CouchbaseLiteException with the code NotOpen is thrown. */ -// CBL-5843 -- (void) _testIndexUpdaterCallFinishTwice { +- (void) testIndexUpdaterCallFinishTwice { [self createWordsIndexWithConfig: LAZY_VECTOR_INDEX_CONFIG(@"word", 300, 8)]; NSError* error; @@ -1264,7 +1262,7 @@ - (void) _testIndexUpdaterCallFinishTwice { Assert([updater setVector: vector atIndex: 0 error: &error]); Assert([updater finishWithError: &error]); - [self expectError: CBLErrorDomain code: CBLErrorUnsupported in: ^BOOL(NSError** err) { + [self expectError: CBLErrorDomain code: CBLErrorNotOpen in: ^BOOL(NSError** err) { return [updater finishWithError: err]; }]; } diff --git a/Objective-C/Tests/VectorSearchTest.m b/Objective-C/Tests/VectorSearchTest.m index 653f0d292..bd577efcb 100644 --- a/Objective-C/Tests/VectorSearchTest.m +++ b/Objective-C/Tests/VectorSearchTest.m @@ -217,8 +217,8 @@ - (CBLQueryResultSet*) executeWordsQueryNoTrainingCheckWithLimit: (NSNumber*)lim * 2. Get and check the following property values: * - encoding: 8-Bit Scalar Quantizer Encoding * - metric: Euclidean Distance - * - minTrainingSize: 25 * centroids - * - maxTrainingSize: 256 * centroids + * - minTrainingSize: 0 + * - maxTrainingSize: 0 * 3. To check the encoding type, platform code will have to expose some internal * property to the tests for verification. */ @@ -226,8 +226,9 @@ - (void) testVectorIndexConfigurationDefaultValue { CBLVectorIndexConfiguration* config = VECTOR_INDEX_CONFIG(@"vector", 300, 8); AssertEqualObjects(config.encoding, [CBLVectorEncoding scalarQuantizerWithType: kCBLSQ8]); AssertEqual(config.metric, kCBLDistanceMetricEuclidean); - AssertEqual(config.minTrainingSize, 25 * config.centroids); - AssertEqual(config.maxTrainingSize, 256 * config.centroids); + AssertEqual(config.minTrainingSize, 0); + AssertEqual(config.maxTrainingSize, 0); + AssertEqual(config.numProbes, 0); } /** @@ -354,7 +355,7 @@ - (void) testCentroidsValidation { * 6. Create an SQL++ query: * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 7. Check the explain() result of the query to ensure that the "words_index" is used. * 8. Execute the query and check that 20 results are returned. * 9. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -385,7 +386,7 @@ - (void) testCreateVectorIndex { * 5. Create an SQL++ query: * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 350) + * WHERE vector_match(words_index, ) LIMIT 350 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 300 results are returned. * 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -454,7 +455,7 @@ - (void) testUpdateVectorIndex { * 6. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 350) + * WHERE vector_match(words_index, ) LIMIT 350 * 7. Execute the query and check that 296 results are returned, and the results * do not include document word1, word2, word3, and word4. * 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -528,7 +529,7 @@ - (void) testCreateVectorIndexWithInvalidVectors { * 6. Create an SQL++ query: * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_pred_index, , 350) + * WHERE vector_match(words_pred_index, ) LIMIT 350 * 7. Check the explain() result of the query to ensure that the "words_pred_index" is used. * 8. Execute the query and check that 300 results are returned. * 9. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -605,7 +606,7 @@ - (void) testCreateVectorIndexUsingPredictionModel { * 7. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_pred_index, , 350) + * WHERE vector_match(words_pred_index, ) LIMIT 350 * 8. Check the explain() result of the query to ensure that the "words_predi_index" is used. * 9. Execute the query and check that 296 results are returned and the results * do not include word1, word2, word3, and word4. @@ -679,7 +680,7 @@ - (void) testCreateVectorIndexUsingPredictionModelWithInvalidVectors { * 5. Create an SQL++ query * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned. * 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -734,7 +735,7 @@ - (void) testCreateVectorIndexWithSQ { * 5. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned. * 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -751,8 +752,6 @@ - (void) testCreateVectorIndexWithNoneEncoding { } /** - * FAILED : https://issues.couchbase.com/browse/CBL-5538 - * * 12. TestCreateVectorIndexWithPQ * Description * Using the PQ Encoding, test that the vector index can be created and used. The @@ -769,7 +768,7 @@ - (void) testCreateVectorIndexWithNoneEncoding { * 5. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned. * 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -852,7 +851,7 @@ - (void) testSubquantizersValidation { * 5. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 5. Check the explain() result of the query to ensure that the "words_index" is used. * 6. Execute the query and check that 20 results are returned. * 7. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -884,11 +883,9 @@ - (void) testeCreateVectorIndexWithFixedTrainingSize { * - minTrainingSize: 1 and maxTrainingSize: 100 * 3. Check that the index is created without an error returned. * 4. Delete the "words_index" - * 5. Repeat Step 2 with the following cases: - * - minTrainingSize = 0 and maxTrainingSize 0 - * - minTrainingSize = 0 and maxTrainingSize 100 - * - minTrainingSize = 10 and maxTrainingSize 9 - * 6. Check that an invalid argument exception was thrown for all cases in step 4. + * 5. Repeat Step 2 with the following case: + * - minTrainingSize = 10 and maxTrainingSize = 9 + * 6. Check that an invalid argument exception was thrown. */ - (void) testValidateMinMaxTrainingSize { CBLVectorIndexConfiguration* config = VECTOR_INDEX_CONFIG(@"vector", 300, 8); @@ -896,24 +893,13 @@ - (void) testValidateMinMaxTrainingSize { config.maxTrainingSize = 100; [self createWordsIndexWithConfig: config]; - NSArray *> *trainingSizes = @[ - @[@0, @0], - @[@0, @100], - @[@10, @9] - ]; - + [self deleteWordsIndex]; + config.minTrainingSize = 10; + config.maxTrainingSize = 9; CBLCollection* collection = self.wordsCollection; - for (size_t i = 0; i < trainingSizes.count; i++) { - config.minTrainingSize = trainingSizes[i][0].unsignedIntValue; - config.maxTrainingSize = trainingSizes[i][1].unsignedIntValue; - - // Check if exception thrown for wrong values - [self expectException: NSInvalidArgumentException in:^{ - [collection createIndexWithName: kWordsIndexName config: config error: nil]; - }]; - - [self deleteWordsIndex]; - } + [self expectException: NSInvalidArgumentException in:^{ + [collection createIndexWithName: kWordsIndexName config: config error: nil]; + }]; } /** @@ -933,7 +919,7 @@ - (void) testValidateMinMaxTrainingSize { * 5. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned. * 8. Verify that the index was not trained by checking that the “Untrained index; @@ -967,7 +953,7 @@ - (void) testQueryUntrainedVectorIndex { * 5. Create an SQL++ query. * - SELECT meta().id, word,vector_distance(words_index) * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned and the vector * distance value is in between 0 – 1.0 inclusively. @@ -1005,7 +991,7 @@ - (void) testCreateVectorIndexWithCosineDistance { * 5. Create an SQL++ query. * - SELECT meta().id, word, vector_distance(words_index) * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned and the * distance value is more than zero. @@ -1070,7 +1056,7 @@ - (void) testCreateVectorIndexWithExistingName { * 5. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 6. Check the explain() result of the query to ensure that the "words_index" is used. * 7. Execute the query and check that 20 results are returned. * 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -1106,7 +1092,7 @@ - (void) testDeleteVectorIndex { * 2. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 3. Check that a CouchbaseLiteException is returned as the index doesn’t exist. */ - (void) testVectorMatchOnNonExistingIndex { @@ -1163,7 +1149,7 @@ - (void) testVectorMatchDefaultLimit { * 4. Create an SQL++ query. * - SELECT meta().id, word * FROM _default.words - * WHERE vector_match(words_index, , ) + * WHERE vector_match(words_index, ) LIMIT * - limit: 1 and 10000 * 5. Check that the query can be created without an error. * 6. Repeat step 4 with the limit: -1, 0, and 10001 @@ -1205,7 +1191,7 @@ - (void) testVectorMatchLimitBoundary { * 5. Create an SQL++ query. * - SELECT word, catid * FROM _default.words - * WHERE vector_match(words_index, , 300) AND catid = 'cat1' + * WHERE vector_match(words_index, ) AND catid = 'cat1' LIMIT 300 * 6. Check that the query can be created without an error. * 7. Check the explain() result of the query to ensure that the "words_index" is used. * 8. Execute the query and check that the number of results returned is 50 @@ -1245,7 +1231,7 @@ - (void) testVectorMatchWithAndExpression { * 5. Create an SQL++ query. * - SELECT word, catid * FROM _default.words - * WHERE (vector_match(words_index, , 300) AND word is valued) AND catid = 'cat1' + * WHERE (vector_match(words_index, ) AND word is valued) AND catid = 'cat1' LIMIT 300 * 6. Check that the query can be created without an error. * 7. Check the explain() result of the query to ensure that the "words_index" is used. * 8. Execute the query and check that the number of results returned is 50 @@ -1284,7 +1270,7 @@ - (void) testVectorMatchWithMultipleAndExpression { * 4. Create an SQL++ query. * - SELECT word, catid * FROM _default.words - * WHERE vector_match(words_index, , 20) OR catid = 1 + * WHERE vector_match(words_index, ) OR catid = 1 LIMIT 20 * 5. Check that a CouchbaseLiteException is returned when creating the query. */ - (void) testInvalidVectorMatchWithOrExpression { @@ -1319,7 +1305,7 @@ - (void) testInvalidVectorMatchWithOrExpression { * 7. Create an SQL++ query: * - SELECT meta().id, word, vector_distance(words_index) * FROM _default.words - * WHERE vector_match(words_index, < dinner vector >, 20) + * WHERE vector_match(words_index, ) LIMIT 20 * 8. Execute the query and check that 20 results are returned. * 9. Check that the result also contains doc id = word49. */ @@ -1338,6 +1324,45 @@ - (void) testIndexVectorInBase64 { AssertNotNil(wordMap[@"word49"]); } +/** + * 28. TestNumProbes + * + * Description + * Test that the numProces specified is effective. + * Steps + * 1. Copy database words_db. + * 2. Create a vector index named "words_index" in _default.words collection. + * - expression: "vector" + * - dimensions: 300 + * - centroids : 8 + * - numProbes: 5 + * 3. Check that the index is created without an error returned. + * 4. Create an SQL++ query: + * - SELECT meta().id, word + * FROM _default.words + * WHERE vector_match(words_index, ) LIMIT 300 + * 5. Execute the query and check that 20 results are returned. + * 6. Repeat step 2 - 6 but change the numProbes to 1. + * 7. Verify the number of results returned in Step 5 is larger than Step 6. +*/ +- (void) testNumProbes { + CBLVectorIndexConfiguration* config = VECTOR_INDEX_CONFIG(@"vector", 300, 8); + config.numProbes = 5; + [self createWordsIndexWithConfig: config]; + + CBLQueryResultSet* rs = [self executeWordsQueryWithLimit: @300]; + NSUInteger numResultsFor5Probes = [[rs allObjects] count]; + Assert(numResultsFor5Probes > 0); + + config.numProbes = 1; + [self createWordsIndexWithConfig: config]; + rs = [self executeWordsQueryWithLimit: @300]; + NSUInteger numResultsFor1Probes = [[rs allObjects] count]; + Assert(numResultsFor1Probes > 0); + + Assert(numResultsFor5Probes > numResultsFor1Probes); +} + /* Private methods tests */ diff --git a/Swift/Tests/LazyVectorIndexTest.swift b/Swift/Tests/VectorLazyIndexTest.swift similarity index 99% rename from Swift/Tests/LazyVectorIndexTest.swift rename to Swift/Tests/VectorLazyIndexTest.swift index 812b5abcb..7559ae209 100644 --- a/Swift/Tests/LazyVectorIndexTest.swift +++ b/Swift/Tests/VectorLazyIndexTest.swift @@ -39,7 +39,7 @@ import XCTest * - Test 6 TestGetIndexOnClosedDatabase is done in CollectionTest.testUseCollectionAPIWhenDatabaseIsClosed() * - Test 7 testInvalidCollection) is done in CollectionTest.testUseCollectionAPIOnDeletedCollection() */ -class LazyVectorIndexTest: VectorSearchTest { +class VectorLazyIndexTest: VectorSearchTest { func wordsIndex() throws -> QueryIndex { let index = try wordsCollection.index(withName: wordsIndexName) XCTAssertNotNil(index) @@ -622,7 +622,7 @@ class LazyVectorIndexTest: VectorSearchTest { /// 7. Execute a vector search query. /// - SELECT word /// FROM _default.words - /// WHERE vector_match(words_index, < dinner vector >, 300) + /// WHERE vector_match(words_index, ) LIMIT 300 /// 8. Check that there are 10 words returned. /// 9. Check that the word is in the word set from the step 5. func testIndexUpdaterSetFloatArrayVectors() throws { diff --git a/Swift/Tests/VectorSearchTest.swift b/Swift/Tests/VectorSearchTest.swift index 057684446..167031438 100644 --- a/Swift/Tests/VectorSearchTest.swift +++ b/Swift/Tests/VectorSearchTest.swift @@ -180,16 +180,17 @@ class VectorSearchTest: CBLTestCase { /// 2. Get and check the following property values: /// - encoding: 8-Bit Scalar Quantizer Encoding /// - metric: Euclidean Distance - /// - minTrainingSize: 25 * centroids - /// - maxTrainingSize: 256 * centroids + /// - minTrainingSize: 0 + /// - maxTrainingSize: 0 /// 3. To check the encoding type, platform code will have to expose some internal /// property to the tests for verification. func testVectorIndexConfigurationDefaultValue() throws { let config = VectorIndexConfiguration(expression: "vector", dimensions: 300, centroids: 20) XCTAssertEqual(config.encoding, .scalarQuantizer(type: VectorIndexConfiguration.defaultEncoding)); XCTAssertEqual(config.metric, VectorIndexConfiguration.defaultDistanceMetric) - XCTAssertEqual(config.minTrainingSize, 25 * config.centroids) - XCTAssertEqual(config.maxTrainingSize, 256 * config.centroids) + XCTAssertEqual(config.minTrainingSize, 0) + XCTAssertEqual(config.maxTrainingSize, 0) + XCTAssertEqual(config.numProbes, 0) } /// 2. TestVectorIndexConfigurationSettersAndGetters @@ -309,7 +310,7 @@ class VectorSearchTest: CBLTestCase { /// 6. Create an SQL++ query: /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 7. Check the explain() result of the query to ensure that the "words_index" is used. /// 8. Execute the query and check that 20 results are returned. /// 9. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -339,7 +340,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query: /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 350) + /// WHERE vector_match(words_index, ) LIMIT 350 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 300 results are returned. /// 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -410,7 +411,7 @@ class VectorSearchTest: CBLTestCase { /// 6. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 350) + /// WHERE vector_match(words_index, ) LIMIT 350 /// 7. Execute the query and check that 296 results are returned, and the results /// do not include document word1, word2, word3, and word4. /// 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -479,7 +480,7 @@ class VectorSearchTest: CBLTestCase { /// 6. Create an SQL++ query: /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_pred_index, , 350) + /// WHERE vector_match(words_pred_index, ) LIMIT 350 /// 7. Check the explain() result of the query to ensure that the "words_pred_index" is used. /// 8. Execute the query and check that 300 results are returned. /// 9. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -560,7 +561,7 @@ class VectorSearchTest: CBLTestCase { /// 7. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_pred_index, , 350) + /// WHERE vector_match(words_pred_index, ) LIMIT 350 /// 8. Check the explain() result of the query to ensure that the "words_predi_index" is used. /// 9. Execute the query and check that 296 results are returned and the results /// do not include word1, word2, word3, and word4. @@ -630,7 +631,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned. /// 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -683,7 +684,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned. /// 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -717,7 +718,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned. /// 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -803,7 +804,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 5. Check the explain() result of the query to ensure that the "words_index" is used. /// 6. Execute the query and check that 20 results are returned. /// 7. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -833,25 +834,20 @@ class VectorSearchTest: CBLTestCase { /// - minTrainingSize: 1 and maxTrainingSize: 100 /// 3. Check that the index is created without an error returned. /// 4. Delete the "words_index" - /// 5. Repeat Step 2 with the following cases: - /// - minTrainingSize = 0 and maxTrainingSize 0 - /// - minTrainingSize = 0 and maxTrainingSize 100 - /// - minTrainingSize = 10 and maxTrainingSize 9 - /// 6. Check that an invalid argument exception was thrown for all cases in step 4. + /// 5. Repeat Step 2 with the following case: + /// - minTrainingSize = 10 and maxTrainingSize = 9 + /// 6. Check that an invalid argument exception was thrown. func testValidateMinMaxTrainingSize() throws { var config = VectorIndexConfiguration(expression: "vector", dimensions: 300, centroids: 20) config.minTrainingSize = 1 config.maxTrainingSize = 100 try createWordsIndex(config: config) - let trainingSizes: [[UInt32]] = [[0, 0], [0, 100], [10, 9]] - for size in trainingSizes { - try deleteWordsIndex() - config.minTrainingSize = size[0] - config.maxTrainingSize = size[1] - expectExcepion(exception: .invalidArgumentException) { - try? self.createWordsIndex(config: config) - } + try deleteWordsIndex() + config.minTrainingSize = 10 + config.maxTrainingSize = 9 + expectExcepion(exception: .invalidArgumentException) { + try? self.createWordsIndex(config: config) } } @@ -871,7 +867,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned. /// 8. Verify that the index was not trained by checking that the “Untrained index; @@ -904,7 +900,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word,vector_distance(words_index) /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned and the vector /// distance value is in between 0 – 1.0 inclusively. @@ -940,7 +936,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word, vector_distance(words_index) /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned and the /// distance value is more than zero. @@ -1002,7 +998,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 6. Check the explain() result of the query to ensure that the "words_index" is used. /// 7. Execute the query and check that 20 results are returned. /// 8. Verify that the index was trained by checking that the “Untrained index; queries may be slow” @@ -1037,7 +1033,7 @@ class VectorSearchTest: CBLTestCase { /// 2. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 3. Check that a CouchbaseLiteException is returned as the index doesn’t exist. func testVectorMatchOnNonExistingIndex() throws { self.expectError(domain: CBLError.domain, code: CBLError.missingIndex) { @@ -1089,7 +1085,7 @@ class VectorSearchTest: CBLTestCase { /// 4. Create an SQL++ query. /// - SELECT meta().id, word /// FROM _default.words - /// WHERE vector_match(words_index, , ) + /// WHERE vector_match(words_index, ) LIMIT /// - limit: 1 and 10000 /// 5. Check that the query can be created without an error. /// 6. Repeat step 4 with the limit: -1, 0, and 10001 @@ -1125,7 +1121,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT word, catid /// FROM _default.words - /// WHERE vector_match(words_index, , 300) AND catid = 'cat1' + /// WHERE vector_match(words_index, ) AND catid = 'cat1' LIMIT 300 /// 6. Check that the query can be created without an error. /// 7. Check the explain() result of the query to ensure that the "words_index" is used. /// 8. Execute the query and check that the number of results returned is 50 @@ -1159,7 +1155,7 @@ class VectorSearchTest: CBLTestCase { /// 5. Create an SQL++ query. /// - SELECT word, catid /// FROM _default.words - /// WHERE (vector_match(words_index, , 300) AND word is valued) AND catid = 'cat1' + /// WHERE (vector_match(words_index, ) AND word is valued) AND catid = 'cat1' LIMIT 300 /// 6. Check that the query can be created without an error. /// 7. Check the explain() result of the query to ensure that the "words_index" is used. /// 8. Execute the query and check that the number of results returned is 50 @@ -1192,7 +1188,7 @@ class VectorSearchTest: CBLTestCase { /// 4. Create an SQL++ query. /// - SELECT word, catid /// FROM _default.words - /// WHERE vector_match(words_index, , 20) OR catid = 1 + /// WHERE vector_match(words_index, ) OR catid = 1 LIMIT 20 /// 5. Check that a CouchbaseLiteException is returned when creating the query. func testInvalidVectorMatchWithOrExpression() throws { let config = VectorIndexConfiguration(expression: "vector", dimensions: 300, centroids: 8) @@ -1220,7 +1216,7 @@ class VectorSearchTest: CBLTestCase { /// 7. Create an SQL++ query: /// - SELECT meta().id, word, vector_distance(words_index) /// FROM _default.words - /// WHERE vector_match(words_index, < dinner vector >, 20) + /// WHERE vector_match(words_index, ) LIMIT 20 /// 8. Execute the query and check that 20 results are returned. /// 9. Check that the result also contains doc id = word49. func testIndexVectorInBase64() throws { @@ -1236,4 +1232,39 @@ class VectorSearchTest: CBLTestCase { XCTAssertEqual(wordMap.count, 20) XCTAssertNotNil(wordMap["word49"]) } + + /// 28. TestNumProbes + /// Description + /// Test that the numProces specified is effective. + /// Steps + /// 1. Copy database words_db. + /// 2. Create a vector index named "words_index" in _default.words collection. + /// - expression: "vector" + /// - dimensions: 300 + /// - centroids : 8 + /// - numProbes: 5 + /// 3. Check that the index is created without an error returned. + /// 4. Create an SQL++ query: + /// - SELECT meta().id, word + /// FROM _default.words + /// WHERE vector_match(words_index, ) LIMIT 300 + /// 5. Execute the query and check that 20 results are returned. + /// 6. Repeat step 2 - 6 but change the numProbes to 1. + /// 7. Verify the number of results returned in Step 5 is larger than Step 6. + func testNumProbes() throws { + var config = VectorIndexConfiguration(expression: "vector", dimensions: 300, centroids: 8) + config.numProbes = 5 + try createWordsIndex(config: config) + var rs = try executeWordsQuery(limit: 300) + let numResultsFor5Probes = rs.allResults().count + XCTAssert(numResultsFor5Probes > 0) + + config.numProbes = 1; + try createWordsIndex(config: config) + rs = try executeWordsQuery(limit: 300) + let numResultsFor1Probes = rs.allResults().count + XCTAssert(numResultsFor1Probes > 0) + + XCTAssert(numResultsFor5Probes > numResultsFor1Probes) + } } diff --git a/Tests/Extensions/version.txt b/Tests/Extensions/version.txt index 5d46c9b2a..645ad1271 100644 --- a/Tests/Extensions/version.txt +++ b/Tests/Extensions/version.txt @@ -1 +1 @@ -1.0.0-43 +1.0.0-52 diff --git a/vendor/couchbase-lite-core b/vendor/couchbase-lite-core index 61cfa302d..1b03b5456 160000 --- a/vendor/couchbase-lite-core +++ b/vendor/couchbase-lite-core @@ -1 +1 @@ -Subproject commit 61cfa302d61b8baef2c2cfeeb79c24653e1603a0 +Subproject commit 1b03b5456c508d431aa4ddfff82bda18f2fd392a