From 0c215c01fb2989c55eaa6450b7d7e90ca67aa434 Mon Sep 17 00:00:00 2001 From: Vlad Velicu Date: Tue, 5 Mar 2024 01:03:14 +0000 Subject: [PATCH] CBL-5433: Tests for Vector Index API 11-20 Obj-C (#3246) * update words db * add new tests * disable another tests --- .../vectorsearch/words_db.cblite2/db.sqlite3 | Bin 1560576 -> 1576960 bytes Objective-C/Tests/VectorSearchTest.m | 364 +++++++++++++++++- 2 files changed, 344 insertions(+), 20 deletions(-) diff --git a/Objective-C/Tests/Support/databases/vectorsearch/words_db.cblite2/db.sqlite3 b/Objective-C/Tests/Support/databases/vectorsearch/words_db.cblite2/db.sqlite3 index 9e6e8b918d711f056197a2499aeabf79066d3b1f..fdd0bcc0dbf30fdcd11f06f90243aa7fe9e665bb 100644 GIT binary patch delta 14322 zcmeHOdw5&Lm7md-u5|Ud*NJV}j+5AVIdNhqaUMz_5Aw1DArI$)Nq`W`vTQ4sB}bB# z7)ZpZ)bs@u)EWw9OIvD6mu?H8_O>h}l&uNS@WxPDXrQe_X@O9{rF3ccoVkzDCf@Js zAN%e8v;N~)_c!PK=FB-~?j7A3U3=HQYwv3Qazz;<;%_Q^v>TU|H!rVQ=fDf?LlAVk zn)2Q2i+bPmUg#O{9CY93jw`n*J6%6^Y0jO_N_n?D#c`{H+FR_4rD5Ck(hYQ`w3&XC zo6vkjVq42^ezJy6$-VC_%(>}JHf>7ou(W_yZl z=ITIYl{7_~x@=NTwFfejJ4>Av}HI=i`V0LwNZHZj6www~qojeeY z~||rakTRqo3jmRIEJ?I&{0&Luh3@lbB7^1a+;?%Q)8EA_dY^JRI3M=se` z4N)%76?>-SI$cl7wF-_IAvF?fi|?z0IN=9RuFmtV+`YcrbKg|IkXx^=%Gtb6<>qNi zb0@vWj&^7jG}l<59lgGw%ORIz!IbB2E-1~p{E-ahm;YxXgULw4zIunc(f5Jx&Z85WulFgtoUUT(3e+^_zVPrCWrxhK<}~Jh`|!oe4u^TQ z@{x;`U3OFRE01hZc1h;dy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xi$ASHUJXxJ%zd zPsNv4nGm;f110)WJ- z3z-`$eGg4)6s&yh3toLCO*d0+m_G)TVERs)B89@1VAh> 0); + Assert([result doubleAtIndex: 3] < 1); + } +} + +- (void) testCreateVectorIndexWithEuclideanDistance { + NSError* error; + CBLCollection* collection = [_db collectionWithName: @"words" scope: nil error: &error]; + + // Create vector index + CBLVectorIndexConfiguration* config = [[CBLVectorIndexConfiguration alloc] initWithExpression: @"vector" + dimensions: 300 + centroids: 20]; + config.metric = kCBLDistanceMetricEuclidean; + Assert([collection createIndexWithName: @"words_index" config: config error: &error]); + + NSArray* names = [collection indexes: &error]; + Assert([names containsObject:@"words_index"]); + + // Query: + NSString* sql = @"select meta().id, word, vector_distance(words_index) from _default.words where vector_match(words_index, $vector, 20)"; + CBLQuery* q = [_db createQuery: sql error: &error]; + + CBLQueryParameters* parameters = [[CBLQueryParameters alloc] init]; + [parameters setValue: kDinnerVector forName: @"vector"]; + [q setParameters: parameters]; + + NSString* explain = [q explain: &error]; + Assert([explain rangeOfString: @"SCAN kv_.words:vector:words_index"].location != NSNotFound); + CBLQueryResultSet* rs = [q execute: &error]; + NSArray* allObjects = rs.allResults; + AssertEqual(allObjects.count, 20); + + for(CBLQueryResult* result in rs){ + // doubleAtIndex: vector_distance(words_index) + Assert([result doubleAtIndex: 3] > 0); + } +} + +- (void) testCreateVectorIndexWithExistingName { + NSError* error; + CBLCollection* collection = [_db collectionWithName: @"words" scope: nil error: &error]; + + // Create and recreate vector index using the same config + CBLVectorIndexConfiguration* config = [[CBLVectorIndexConfiguration alloc] initWithExpression: @"vector" + dimensions: 300 + centroids: 20]; + Assert([collection createIndexWithName: @"words_index" config: config error: &error]); + Assert([collection createIndexWithName: @"words_index" config: config error: &error]); + + // Recreate index with same name using different config + CBLVectorIndexConfiguration* config2 = [[CBLVectorIndexConfiguration alloc] initWithExpression: @"vectors" + dimensions: 300 + centroids: 20]; + Assert([collection createIndexWithName: @"words_index" config: config2 error: &error]); + + NSArray* names = [collection indexes: &error]; + Assert([names containsObject: @"words_index"]); +} + +- (void) testDeleteVectorIndex { + NSError* error; + CBLCollection* collection = [_db collectionWithName: @"words" scope: nil error: &error]; + + // Create and recreate vector index using the same config + CBLVectorIndexConfiguration* config = [[CBLVectorIndexConfiguration alloc] initWithExpression: @"vector" + dimensions: 300 + centroids: 20]; + Assert([collection createIndexWithName: @"words_index" config: config error: &error]); + + NSArray* names = [collection indexes: &error]; + Assert([names containsObject:@"words_index"]); + + // Query: + NSString* sql = @"select meta().id, word, vector_distance(words_index) from _default.words where vector_match(words_index, $vector, 20)"; + CBLQuery* q = [_db createQuery: sql error: &error]; + + CBLQueryParameters* parameters = [[CBLQueryParameters alloc] init]; + [parameters setValue: kDinnerVector forName: @"vector"]; + [q setParameters: parameters]; + + NSString* explain = [q explain: &error]; + Assert([explain rangeOfString: @"SCAN kv_.words:vector:words_index"].location != NSNotFound); + CBLQueryResultSet* rs = [q execute: &error]; + NSArray* allObjects = rs.allResults; + AssertEqual(allObjects.count, 20); + + // Delete index + [collection deleteIndexWithName: @"words_index" error: &error]; + + names = [collection indexes: &error]; + AssertEqual(names.count, 0); +} + @end